Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/20/21 18:13:55 (3 years ago)
Author:
dpiringe
Message:

#3026

  • merged trunk into branch
Location:
branches/3026_IntegrationIntoSymSpace
Files:
2 deleted
14 edited
6 copied

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4

  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs

    r17928 r18027  
    9696    }
    9797
    98     public static IntervalCollection GetIntervals(this IDataset dataset) {
    99       IntervalCollection intervalCollection = new IntervalCollection();
    100       foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables
    101         var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
    102         intervalCollection.AddInterval(variable, variableInterval);
     98    public static IntervalCollection GetVariableRanges(this IDataset dataset, bool ignoreNaNs = true) {
     99      IntervalCollection variableRanges = new IntervalCollection();
     100      foreach (var variable in dataset.DoubleVariables) { // ranges can only be calculated for double variables
     101        var values = dataset.GetDoubleValues(variable);
     102
     103        if (ignoreNaNs) {
     104          values = values.Where(v => !double.IsNaN(v));
     105
     106          if (!values.Any()) { //handle values with only NaNs explicitly
     107            var emptyInterval = new Interval(double.NaN, double.NaN);
     108            variableRanges.AddInterval(variable, emptyInterval);
     109            continue;
     110          }
     111        }
     112
     113        var interval = Interval.GetInterval(values);
     114        variableRanges.AddInterval(variable, interval);
    103115      }
    104116
    105       return intervalCollection;
     117      return variableRanges;
    106118    }
    107119
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r17928 r18027  
    9999  </PropertyGroup>
    100100  <ItemGroup>
    101     <Reference Include="ALGLIB-3.7.0, Version=3.7.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    102       <HintPath>..\..\bin\ALGLIB-3.7.0.dll</HintPath>
     101    <Reference Include="ALGLIB-3.17.0, Version=3.17.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     102      <SpecificVersion>False</SpecificVersion>
     103      <HintPath>..\..\bin\ALGLIB-3.17.0.dll</HintPath>
    103104      <Private>False</Private>
    104105    </Reference>
     
    142143    <Compile Include="Implementation\Interval\Interval.cs" />
    143144    <Compile Include="Implementation\Interval\IntervalCollection.cs" />
    144     <Compile Include="Implementation\Interval\ShapeConstraint.cs" />
    145     <Compile Include="Implementation\Interval\ShapeConstraintsParser.cs" />
    146145    <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" />
    147146    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
    148147    <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" />
     148    <Compile Include="Implementation\Regression\ShapeConstrainedRegressionProblem.cs" />
     149    <Compile Include="Implementation\Regression\ShapeConstrainedRegressionProblemData.cs" />
     150    <Compile Include="Implementation\Regression\ShapeConstraint.cs" />
    149151    <Compile Include="Implementation\Regression\ShapeConstraints.cs" />
    150152    <Compile Include="Implementation\Regression\RegressionEnsembleProblemData.cs" />
     
    155157    <Compile Include="Implementation\Regression\RegressionModel.cs" />
    156158    <Compile Include="Implementation\Regression\RegressionSolutionVariableImpactsCalculator.cs" />
     159    <Compile Include="Implementation\Regression\ShapeConstraintsParser.cs" />
    157160    <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" />
    158161    <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisAutoRegressiveModel.cs" />
     
    190193    <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" />
    191194    <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" />
     195    <Compile Include="Interfaces\Regression\IShapeConstrainedRegressionProblem.cs" />
     196    <Compile Include="Interfaces\Regression\IShapeConstrainedRegressionProblemData.cs" />
    192197    <Compile Include="Interfaces\TimeSeriesPrognosis\IOnlineTimeSeriesCalculator.cs" />
    193198    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisModel.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs

    r17180 r18027  
    3434    private const string TrainingAccuracyResultName = "Accuracy (training)";
    3535    private const string TestAccuracyResultName = "Accuracy (test)";
    36     private const string TrainingNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (training)";
    37     private const string TestNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (test)";
     36    private const string TrainingNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (training)";
     37    private const string TestNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (test)";
    3838    private const string ClassificationPerformanceMeasuresResultName = "Classification Performance Measures";
    3939
     
    9797      if (string.IsNullOrEmpty(Model.TargetVariable))
    9898        Model.TargetVariable = this.ProblemData.TargetVariable;
    99 
    100       if (!this.ContainsKey(TrainingNormalizedGiniCoefficientResultName))
     99      var newResult = false;
     100      if (!this.ContainsKey(TrainingNormalizedGiniCoefficientResultName)) {
    101101        Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the training partition.", new DoubleValue()));
    102       if (!this.ContainsKey(TestNormalizedGiniCoefficientResultName))
     102        newResult = true;
     103      }
     104      if (!this.ContainsKey(TestNormalizedGiniCoefficientResultName)) {
    103105        Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue()));
     106        newResult = true;
     107      }
    104108      if (!this.ContainsKey(ClassificationPerformanceMeasuresResultName)) {
    105109        Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n
    106110                              In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.",
    107111                              new ClassificationPerformanceMeasuresResultCollection()));
    108         CalculateClassificationResults();
     112        newResult = true;
    109113      }
     114      if (newResult) CalculateClassificationResults();
    110115    }
    111116
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs

    r17180 r18027  
    4040    private const string TrainingRSquaredResultName = "Pearson's R² (training)";
    4141    private const string TestRSquaredResultName = "Pearson's R² (test)";
     42    private const string TrainingNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (training, discriminant values)";
     43    private const string TestNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (test, discriminant values)";
     44
    4245
    4346    public new IDiscriminantFunctionClassificationModel Model {
     
    7174      private set { ((DoubleValue)this[TestRSquaredResultName].Value).Value = value; }
    7275    }
     76    public double TrainingNormalizedGiniCoefficientForDiscriminantValues {
     77      get { return ((DoubleValue)this[TrainingNormalizedGiniCoefficientResultName].Value).Value; }
     78      protected set { ((DoubleValue)this[TrainingNormalizedGiniCoefficientResultName].Value).Value = value; }
     79    }
     80    public double TestNormalizedGiniCoefficientForDiscriminantValues {
     81      get { return ((DoubleValue)this[TestNormalizedGiniCoefficientResultName].Value).Value; }
     82      protected set { ((DoubleValue)this[TestNormalizedGiniCoefficientResultName].Value).Value = value; }
     83    }
    7384    #endregion
    7485
     
    8596      Add(new Result(TrainingRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
    8697      Add(new Result(TestRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
     98      Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the discriminant values produced by the model on the training partition.", new DoubleValue()));
     99      Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the discriminant values produced by the model on the test partition.", new DoubleValue()));
    87100      RegisterEventHandler();
    88101    }
     
    90103    [StorableHook(HookType.AfterDeserialization)]
    91104    private void AfterDeserialization() {
     105      #region backwards compatibility
     106      if (!ContainsKey(TrainingNormalizedGiniCoefficientResultName)) {
     107        Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the discriminant values produced by the model on the training partition.", new DoubleValue()));
     108        Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the discriminant values produced by the model on the test partition.", new DoubleValue()));
     109        double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values
     110        double[] originalTrainingValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToArray();
     111        double[] estimatedTestValues = EstimatedTestValues.ToArray(); // cache values
     112        double[] originalTestValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices).ToArray();
     113        double trainingNormalizedGini = NormalizedGiniCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out var errorState);
     114        if (errorState != OnlineCalculatorError.None) trainingNormalizedGini = double.NaN;
     115        double testNormalizedGini = NormalizedGiniCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
     116        if (errorState != OnlineCalculatorError.None) testNormalizedGini = double.NaN;
     117
     118        TrainingNormalizedGiniCoefficientForDiscriminantValues = trainingNormalizedGini;
     119        TestNormalizedGiniCoefficientForDiscriminantValues = testNormalizedGini;
     120      }
     121      #endregion
    92122      RegisterEventHandler();
    93123    }
     
    106136
    107137      double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    108       TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN;
     138      TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR * trainingR : double.NaN;
    109139      double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    110       TestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN;
     140      TestRSquared = errorState == OnlineCalculatorError.None ? testR * testR : double.NaN;
    111141
    112142      double trainingNormalizedGini = NormalizedGiniCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
     
    115145      if (errorState != OnlineCalculatorError.None) testNormalizedGini = double.NaN;
    116146
    117       TrainingNormalizedGiniCoefficient = trainingNormalizedGini;
    118       TestNormalizedGiniCoefficient = testNormalizedGini;
     147      TrainingNormalizedGiniCoefficientForDiscriminantValues = trainingNormalizedGini;
     148      TestNormalizedGiniCoefficientForDiscriminantValues = testNormalizedGini;
    119149    }
    120150
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

    r17928 r18027  
    7878      if (double.IsNegativeInfinity(LowerBound) && double.IsPositiveInfinity(UpperBound)) return true;
    7979      if (other.LowerBound >= LowerBound && other.UpperBound <= UpperBound) return true;
    80  
     80
    8181      return false;
    8282    }
     
    9797    /// </summary>
    9898    public bool IsPositive {
    99       get => LowerBound > 0.0; 
     99      get => LowerBound > 0.0;
    100100    }
    101101
     
    130130        return false;
    131131
    132       return (UpperBound==other.UpperBound || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound)))
    133         && (LowerBound==other.LowerBound || (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound)));
     132      return (UpperBound == other.UpperBound || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound)))
     133        && (LowerBound == other.LowerBound || (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound)));
    134134    }
    135135
     
    238238    public static Interval Cube(Interval a) {
    239239      return new Interval(Math.Pow(a.LowerBound, 3), Math.Pow(a.UpperBound, 3));
     240    }
     241
     242    public static Interval Power(Interval a, int b) {
     243      if (b < 0) return Power(1.0 / a, -b); // a^(-b) = 1/(a^b)
     244      if (b == 0 && (a.Contains(0.0) || a.IsInfiniteOrUndefined)) return new Interval(double.NaN, double.NaN);  // 0^0, +/-inf^0 are undefined
     245      if (b == 0) return new Interval(1.0, 1.0); // x^0 = 1
     246      if (b == 1) return a;
     247      if (b % 2 == 0) {
     248        // even powers (see x²)
     249        if (a.UpperBound <= 0) return new Interval(Math.Pow(a.UpperBound, b), Math.Pow(a.LowerBound, b));     // interval is negative
     250        if (a.LowerBound >= 0) return new Interval(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b)); // interval is positive
     251        return new Interval(0, Math.Max(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b))); // interval goes over zero
     252      } else {
     253        // odd powers (see x³)
     254        return new Interval(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b));
     255      }
    240256    }
    241257
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17928 r18027  
    3535    protected const string TargetVariableParameterName = "TargetVariable";
    3636    protected const string VariableRangesParameterName = "VariableRanges";
    37     protected const string ShapeConstraintsParameterName = "ShapeConstraints";
    3837    public string Filename { get; set; }
    3938
     
    7877      defaultDataset = new Dataset(new string[] { "y", "x" }, kozaF1);
    7978      defaultDataset.Name = "Fourth-order Polynomial Function Benchmark Dataset";
    80       defaultDataset.Description = "f(x) = x^4 + x^3 + x^2 + x^1";
     79      defaultDataset.Description = "f(x) = x^4 + x^3 + x^2 + x";
    8180      defaultAllowedInputVariables = new List<string>() { "x" };
    8281      defaultTargetVariable = "y";
     
    9493      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
    9594      problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection()));
    96       problemData.Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, "", new ShapeConstraints()));
    9795      emptyProblemData = problemData;
    9896    }
     
    10199    #region parameter properties
    102100    public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName];
    103     public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter => (IFixedValueParameter<ShapeConstraints>)Parameters[ShapeConstraintsParameterName];
    104101    public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName];
    105102    #endregion
     
    109106      get => VariableRangesParameter.Value;
    110107    }
    111 
    112 
    113     public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value;
    114 
    115108
    116109    public string TargetVariable {
     
    137130    private void AfterDeserialization() {
    138131      if (!Parameters.ContainsKey(VariableRangesParameterName)) {
    139         var intervalCollection = Dataset.GetIntervals();
    140         Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    141       }
    142       if (Parameters.ContainsKey("IntervalConstraints")) {
    143         var param = (IFixedValueParameter<ShapeConstraints>)Parameters["IntervalConstraints"];
    144         Parameters.Remove(param);
    145         Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, param.Value));
    146       }
    147       if (!Parameters.ContainsKey(ShapeConstraintsParameterName)) {
    148         Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, new ShapeConstraints()));
     132        var variableRanges = Dataset.GetVariableRanges();
     133        Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges));
    149134      }
    150135
     
    174159    public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
    175160      IEnumerable<ITransformation> transformations = null,
    176       IntervalCollection variableRanges = null,
    177       ShapeConstraints shapeConstraints = null)
     161      IntervalCollection variableRanges = null)
    178162      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    179163      var variables = InputVariables.Select(x => x.AsReadOnly()).ToList();
    180164      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First()));
    181165      if (variableRanges == null) {
    182         variableRanges = Dataset.GetIntervals();
     166        variableRanges = Dataset.GetVariableRanges();
    183167      }
    184168      Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges));
    185 
    186       if (shapeConstraints == null) {
    187         shapeConstraints = new ShapeConstraints();
    188       }
    189       Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, shapeConstraints));
    190       RegisterParameterEvents();
    191169    }
    192170    private void RegisterParameterEvents() {
    193171      TargetVariableParameter.ValueChanged += new EventHandler(Parameter_ValueChanged);
    194       // VariableRanges and ShapeConstraints are fixed parameters
     172      // VariableRanges are fixed parameters
    195173    }
    196174    private void Parameter_ValueChanged(object sender, EventArgs e) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ShapeConstraints.cs

    r17928 r18027  
    7777    public event EventHandler Changed;
    7878
     79
    7980    private void RaiseChanged() {
    8081      var handlers = Changed;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs

    r17928 r18027  
    2929  public interface IRegressionProblemData : IDataAnalysisProblemData {
    3030    string TargetVariable { get; set; }
    31 
    3231    IntervalCollection VariableRanges { get; }
    33     ShapeConstraints ShapeConstraints { get; }
    34 
    3532    IEnumerable<double> TargetVariableValues { get; }
    3633    IEnumerable<double> TargetVariableTrainingValues { get; }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/AutoCorrelationCalculator.cs

    r17180 r18027  
    3131      }
    3232
    33       double[] correlations = new double[values.Length];
    34       alglib.corr.corrr1dcircular(values, values.Length, values, values.Length, ref correlations);
     33      alglib.corrr1dcircular(values, values.Length, values, values.Length, out var correlations);
    3534      return correlations;
    3635    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/SpearmansRankCorrelationCoefficientCalculator.cs

    r17180 r18027  
    4545        var original = originalValues.ToArray();
    4646        var estimated = estimatedValues.ToArray();
    47         rs = alglib.basestat.spearmancorr2(original, estimated, original.Length);
     47        rs = alglib.spearmancorr2(original, estimated, original.Length);
    4848        errorState = OnlineCalculatorError.None;
    4949      }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Plugin.cs.frame

    r17184 r18027  
    2828  [Plugin("HeuristicLab.Problems.DataAnalysis","Provides base classes for data analysis tasks.", "3.4.12.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis-3.4.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.ALGLIB","3.7.0")]
     30  [PluginDependency("HeuristicLab.ALGLIB","3.17.0")]
    3131  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3232  [PluginDependency("HeuristicLab.Common", "3.3")]
Note: See TracChangeset for help on using the changeset viewer.