Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/13/21 10:55:09 (3 years ago)
Author:
gkronber
Message:

#3087: merged r17784:18004 from trunk to branch to prepare for trunk reintegration (fixed a conflict in CrossValidation.cs)

Location:
branches/3087_Ceres_Integration
Files:
17 edited
7 copied

Legend:

Unmodified
Added
Removed
  • branches/3087_Ceres_Integration

  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis

  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4

  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs

    r17180 r18006  
    9696    }
    9797
     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);
     115      }
     116
     117      return variableRanges;
     118    }
     119
    98120    public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> GetFactorVariableValues(
    99121      this IDataset ds, IEnumerable<string> factorVariables, IEnumerable<int> rows) {
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r17579 r18006  
    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>
     
    145146    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
    146147    <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" />
     151    <Compile Include="Implementation\Regression\ShapeConstraints.cs" />
    147152    <Compile Include="Implementation\Regression\RegressionEnsembleProblemData.cs" />
    148153    <Compile Include="Implementation\Regression\RegressionEnsembleModel.cs">
     
    152157    <Compile Include="Implementation\Regression\RegressionModel.cs" />
    153158    <Compile Include="Implementation\Regression\RegressionSolutionVariableImpactsCalculator.cs" />
     159    <Compile Include="Implementation\Regression\ShapeConstraintsParser.cs" />
    154160    <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" />
    155161    <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisAutoRegressiveModel.cs" />
     
    187193    <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" />
    188194    <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" />
     195    <Compile Include="Interfaces\Regression\IShapeConstrainedRegressionProblem.cs" />
     196    <Compile Include="Interfaces\Regression\IShapeConstrainedRegressionProblemData.cs" />
    189197    <Compile Include="Interfaces\TimeSeriesPrognosis\IOnlineTimeSeriesCalculator.cs" />
    190198    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisModel.cs" />
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs

    r17180 r18006  
    7373
    7474    public ClassificationEnsembleProblemData() : base() { }
     75
    7576    public ClassificationEnsembleProblemData(IClassificationProblemData classificationProblemData)
    76       : base(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) {
    77       this.TrainingPartition.Start = classificationProblemData.TrainingPartition.Start;
    78       this.TrainingPartition.End = classificationProblemData.TrainingPartition.End;
    79       this.TestPartition.Start = classificationProblemData.TestPartition.Start;
    80       this.TestPartition.End = classificationProblemData.TestPartition.End;
    81       this.PositiveClass = classificationProblemData.PositiveClass;
     77      : base(classificationProblemData) {
    8278    }
    8379
     
    8581      : base(dataset, allowedInputVariables, targetVariable) {
    8682    }
     83
     84    public ClassificationEnsembleProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<string> classNames, string positiveClass = null)
     85      : base(dataset, allowedInputVariables, targetVariable, classNames, positiveClass) {
     86    }
    8787  }
    8888}
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r17180 r18006  
    260260      evaluationCache.Clear();
    261261
    262       IClassificationProblemData problemData = new ClassificationProblemData(ProblemData.Dataset,
    263                                                                      ProblemData.AllowedInputVariables,
    264                                                                      ProblemData.TargetVariable);
    265       problemData.TrainingPartition.Start = ProblemData.TrainingPartition.Start;
    266       problemData.TrainingPartition.End = ProblemData.TrainingPartition.End;
    267       problemData.TestPartition.Start = ProblemData.TestPartition.Start;
    268       problemData.TestPartition.End = ProblemData.TestPartition.End;
     262      IClassificationProblemData problemData = new ClassificationProblemData(ProblemData);
    269263
    270264      foreach (var solution in ClassificationSolutions) {
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r17180 r18006  
    306306        classNamesCache.Add(ClassNamesParameter.Value[i, 0]);
    307307    }
     308
    308309    public override IDeepCloneable Clone(Cloner cloner) {
    309310      if (this == emptyProblemData) return emptyProblemData;
     
    311312    }
    312313
    313     public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { }
     314    public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable, Enumerable.Empty<string>()) { }
    314315
    315316    public ClassificationProblemData(IClassificationProblemData classificationProblemData)
    316       : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) {
     317      : this(classificationProblemData, classificationProblemData.Dataset) {
     318    }
     319
     320    /// <summary>
     321    /// This method satisfies a common use case: making a copy of the problem but providing a different dataset.
     322    /// One must be careful here that the dataset passed is not modified, as that would invalidate the problem data internals.
     323    /// Passing a ModifiableDataset to this constructor is therefore discouraged.
     324    /// </summary>
     325    /// <param name="classificationProblemData">The original instance of classification problem data.</param>
     326    /// <param name="dataset">The new dataset.</param>
     327    public ClassificationProblemData(IClassificationProblemData classificationProblemData, IDataset dataset)
     328    : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable, classificationProblemData.ClassNames, classificationProblemData.PositiveClass) {
     329
    317330      TrainingPartition.Start = classificationProblemData.TrainingPartition.Start;
    318331      TrainingPartition.End = classificationProblemData.TrainingPartition.End;
     
    320333      TestPartition.End = classificationProblemData.TestPartition.End;
    321334
    322       for (int i = 0; i < classificationProblemData.ClassNames.Count(); i++)
    323         ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i);
    324 
    325       //mkommend: The positive class depends on the class names and as a result must only be set after the classe names parameter.
    326       PositiveClass = classificationProblemData.PositiveClass;
    327 
    328335      for (int i = 0; i < Classes; i++) {
    329336        for (int j = 0; j < Classes; j++) {
     
    333340    }
    334341
    335     public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)
     342    public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
     343      IEnumerable<string> classNames = null,
     344      string positiveClass = null, // can be null in which case it's set as the first class name
     345      IEnumerable<ITransformation> transformations = null)
    336346      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    337347      var validTargetVariableValues = CheckVariablesForPossibleTargetVariables(dataset).Select(x => new StringValue(x).AsReadOnly()).ToList();
     
    339349
    340350      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(validTargetVariableValues), target));
    341       Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, ""));
     351      Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "", new StringMatrix()));
    342352      Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassParameterName, "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)"));
    343353      Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, ""));
    344354
    345355      RegisterParameterEvents();
    346       ResetTargetVariableDependentMembers();
     356      ResetTargetVariableDependentMembers(); // correctly set the values of the parameters added above
     357
     358      // set the class names
     359      if (classNames != null && classNames.Any()) {
     360        // better to allocate lists because we use these multiple times below
     361        var names = classNames.ToList();
     362        var values = ClassValuesCache;
     363
     364        if (names.Count != values.Count) {
     365          throw new ArgumentException();
     366        }
     367
     368        ((IStringConvertibleMatrix)ClassNamesParameter.Value).Columns = 1;
     369        ((IStringConvertibleMatrix)ClassNamesParameter.Value).Rows = names.Count;
     370
     371        for (int i = 0; i < names.Count; ++i) {
     372          SetClassName(values[i], names[i]);
     373        }
     374      }
     375
     376      // set the positive class value
     377      if (positiveClass != null) {
     378        PositiveClass = positiveClass;
     379      }
    347380    }
    348381
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs

    r17180 r18006  
    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/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs

    r17180 r18006  
    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/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

    r17583 r18006  
    3333    [Storable]
    3434    public double UpperBound { get; private set; }
     35
     36    public double Width => UpperBound - LowerBound;
    3537
    3638    [StorableConstructor]
     
    6769    }
    6870
     71    private Interval(double v) : this(v, v) { }
     72
    6973    public bool Contains(double value) {
    7074      return LowerBound <= value && value <= UpperBound;
     
    7478      if (double.IsNegativeInfinity(LowerBound) && double.IsPositiveInfinity(UpperBound)) return true;
    7579      if (other.LowerBound >= LowerBound && other.UpperBound <= UpperBound) return true;
    76  
     80
    7781      return false;
    7882    }
     
    9397    /// </summary>
    9498    public bool IsPositive {
    95       get => LowerBound > 0.0; 
     99      get => LowerBound > 0.0;
    96100    }
    97101
     
    126130        return false;
    127131
    128       return (UpperBound.IsAlmost(other.UpperBound) || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound)))
    129         && (LowerBound.IsAlmost(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)));
    130134    }
    131135
     
    234238    public static Interval Cube(Interval a) {
    235239      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      }
    236256    }
    237257
     
    267287    }
    268288
    269     public static Interval AnalyticalQuotient(Interval a, Interval b) {
     289    public static Interval AnalyticQuotient(Interval a, Interval b) {
    270290      var dividend = a;
    271291      var divisor = Add(Square(b), new Interval(1.0, 1.0));
     
    276296    }
    277297    #endregion
     298
     299    #region arithmetic overloads
     300    public static Interval operator +(Interval a, Interval b) => Add(a, b);
     301    public static Interval operator +(Interval a, double b) => Add(a, new Interval(b));
     302    public static Interval operator +(double a, Interval b) => Add(new Interval(a), b);
     303    public static Interval operator -(Interval a, Interval b) => Subtract(a, b);
     304    public static Interval operator -(Interval a, double b) => Subtract(a, new Interval(b));
     305    public static Interval operator -(double a, Interval b) => Subtract(new Interval(a), b);
     306    public static Interval operator -(Interval a) => Subtract(new Interval(0), a);
     307    public static Interval operator *(Interval a, Interval b) => Multiply(a, b);
     308    public static Interval operator *(Interval a, double b) => Multiply(a, new Interval(b));
     309    public static Interval operator *(double a, Interval b) => Multiply(new Interval(a), b);
     310    public static Interval operator /(Interval a, Interval b) => Divide(a, b);
     311    public static Interval operator /(Interval a, double b) => Divide(a, new Interval(b));
     312    public static Interval operator /(double a, Interval b) => Divide(new Interval(a), b);
     313    public static Interval Exponential(double a) { return Exponential(new Interval(a)); }
     314    public static Interval Logarithm(double a) { return Logarithm(new Interval(a)); }
     315    public static Interval Sine(double a) { return Sine(new Interval(a)); }
     316    public static Interval Cosine(double a) { return Cosine(new Interval(a)); }
     317    public static Interval Tangens(double a) { return Tangens(new Interval(a)); }
     318    public static Interval HyperbolicTangent(double a) { return HyperbolicTangent(new Interval(a)); }
     319    public static Interval Square(double a) { return Square(new Interval(a)); }
     320    public static Interval Cube(double a) { return Cube(new Interval(a)); }
     321    public static Interval SquareRoot(double a) { return SquareRoot(new Interval(a)); }
     322    public static Interval CubicRoot(double a) { return CubicRoot(new Interval(a)); }
     323    public static Interval Absolute(double a) { return Absolute(new Interval(a)); }
     324    public static Interval AnalyticQuotient(Interval a, double b) { return AnalyticQuotient(a, new Interval(b)); }
     325    public static Interval AnalyticQuotient(double a, Interval b) { return AnalyticQuotient(new Interval(a), b); }
     326    public static Interval AnalyticQuotient(double a, double b) { return AnalyticQuotient(new Interval(a), new Interval(b)); }
     327    #endregion
    278328  }
    279329}
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs

    r17564 r18006  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3434      get => HeuristicLab.Common.Resources.VSImageLibrary.Object;
    3535    }
    36     private IDictionary<string, Interval> intervals { get; } = new Dictionary<string, Interval>();
    3736
    38     [Storable(Name = "StorableIntervalInformation")]
     37    private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>();
     38
     39    [Storable(OldName = "StorableIntervalInformation")]
    3940    private KeyValuePair<string, double[]>[] StorableIntervalInformation {
     41      set {
     42        foreach (var varInt in value)
     43          intervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1]));
     44      }
     45    }
     46
     47    [Storable]
     48    private object[] StorableIntervals {
    4049      get {
    41         var l = new List<KeyValuePair<string, double[]>>();
    42         foreach (var varInt in intervals)
     50        var names = intervals.Keys.ToArray();
     51        var lowerBounds = intervals.Values.Select(i => i.LowerBound).ToArray();
     52        var upperBounds = intervals.Values.Select(i => i.UpperBound).ToArray();
    4353
    44           l.Add(new KeyValuePair<string, double[]>(varInt.Key,
    45             new double[] { varInt.Value.LowerBound, varInt.Value.UpperBound }));
    46         return l.ToArray();
     54        return new object[] { names, lowerBounds, upperBounds };
    4755      }
    4856
    4957      set {
    50         foreach (var varInt in value)
    51           intervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1]));
     58        var names = (string[])value[0];
     59        var lowerBounds = (double[])value[1];
     60        var upperBounds = (double[])value[2];
     61
     62        for (int i = 0; i < names.Length; i++) {
     63          intervals.Add(names[i], new Interval(lowerBounds[i], upperBounds[i]));
     64        }
    5265      }
    5366    }
     
    8093    public void SetInterval(string identifier, Interval interval) {
    8194      intervals[identifier] = interval;
     95      RaiseChanged();
    8296    }
    8397
    8498    public void AddInterval(string identifier, Interval interval) {
    8599      intervals.Add(identifier, interval);
     100      RaiseChanged();
    86101    }
    87102
    88103    public void DeleteInterval(string identifier) {
    89104      intervals.Remove(identifier);
     105      RaiseChanged();
    90106    }
    91107
    92108    public IReadOnlyDictionary<string, Interval> GetReadonlyDictionary() {
     109      return intervals.ToDictionary(pair => pair.Key, pair => pair.Value);
     110    }
     111
     112    public IDictionary<string, Interval> GetDictionary() {
    93113      return intervals.ToDictionary(pair => pair.Key, pair => pair.Value);
    94114    }
     
    98118        yield return Tuple.Create(variableInterval.Key, variableInterval.Value);
    99119    }
     120
     121    public event EventHandler Changed;
     122    private void RaiseChanged() {
     123      var handler = Changed;
     124      if (handler != null)
     125        handler(this, EventArgs.Empty);
     126    }
     127
    100128  }
    101129}
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17579 r18006  
    3535    protected const string TargetVariableParameterName = "TargetVariable";
    3636    protected const string VariableRangesParameterName = "VariableRanges";
    37     protected const string IntervalConstraintsParameterName = "IntervalConstraints";
    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";
     
    9897    #endregion
    9998
    100     public IConstrainedValueParameter<StringValue> TargetVariableParameter {
    101       get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; }
    102     }
     99    #region parameter properties
     100    public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName];
     101    public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName];
     102    #endregion
    103103
    104     public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName];
    105 
     104    #region properties
    106105    public IntervalCollection VariableRanges {
    107106      get => VariableRangesParameter.Value;
    108107    }
    109 
    110108
    111109    public string TargetVariable {
     
    120118      }
    121119    }
     120    public IEnumerable<double> TargetVariableValues => Dataset.GetDoubleValues(TargetVariable);
     121    public IEnumerable<double> TargetVariableTrainingValues => Dataset.GetDoubleValues(TargetVariable, TrainingIndices);
     122    public IEnumerable<double> TargetVariableTestValues => Dataset.GetDoubleValues(TargetVariable, TestIndices);
     123    #endregion
    122124
    123     public IEnumerable<double> TargetVariableValues {
    124       get { return Dataset.GetDoubleValues(TargetVariable); }
    125     }
    126     public IEnumerable<double> TargetVariableTrainingValues {
    127       get { return Dataset.GetDoubleValues(TargetVariable, TrainingIndices); }
    128     }
    129     public IEnumerable<double> TargetVariableTestValues {
    130       get { return Dataset.GetDoubleValues(TargetVariable, TestIndices); }
    131     }
    132125
    133126
     
    137130    private void AfterDeserialization() {
    138131      if (!Parameters.ContainsKey(VariableRangesParameterName)) {
    139         var intervalCollection = CalculateDatasetIntervals(this.Dataset);
    140         Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
     132        var variableRanges = Dataset.GetVariableRanges();
     133        Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges));
    141134      }
     135
    142136      RegisterParameterEvents();
    143137    }
     
    163157    }
    164158
    165     public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)
     159    public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
     160      IEnumerable<ITransformation> transformations = null,
     161      IntervalCollection variableRanges = null)
    166162      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    167163      var variables = InputVariables.Select(x => x.AsReadOnly()).ToList();
    168164      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First()));
    169       var intervalCollection = CalculateDatasetIntervals(this.Dataset);
    170       Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    171       RegisterParameterEvents();
     165      if (variableRanges == null) {
     166        variableRanges = Dataset.GetVariableRanges();
     167      }
     168      Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges));
    172169    }
    173 
    174     private static IntervalCollection CalculateDatasetIntervals(IDataset dataset) {
    175       IntervalCollection intervalCollection = new IntervalCollection();
    176       foreach (var variable in dataset.DoubleVariables) {// intervals are only possible for double variables
    177         var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
    178         intervalCollection.AddInterval(variable, variableInterval);
    179       }
    180 
    181       return intervalCollection;
     170    private void RegisterParameterEvents() {
     171      TargetVariableParameter.ValueChanged += new EventHandler(Parameter_ValueChanged);
     172      // VariableRanges are fixed parameters
    182173    }
    183 
    184     private void RegisterParameterEvents() {
    185       TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged);
    186     }
    187     private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {
     174    private void Parameter_ValueChanged(object sender, EventArgs e) {
    188175      OnChanged();
    189176    }
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs

    r17579 r18006  
    11#region License Information
     2
    23/* HeuristicLab
    34 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    1819 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1920 */
     21
    2022#endregion
    2123
     
    2729  public interface IRegressionProblemData : IDataAnalysisProblemData {
    2830    string TargetVariable { get; set; }
    29 
    30     IntervalCollection VariableRanges { get;}
    31 
     31    IntervalCollection VariableRanges { get; }
    3232    IEnumerable<double> TargetVariableValues { get; }
    3333    IEnumerable<double> TargetVariableTrainingValues { get; }
  • branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/AutoCorrelationCalculator.cs

    r17180 r18006  
    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/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/SpearmansRankCorrelationCoefficientCalculator.cs

    r17180 r18006  
    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/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Plugin.cs.frame

    r17184 r18006  
    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.