- Timestamp:
- 07/13/21 10:55:09 (3 years ago)
- Location:
- branches/3087_Ceres_Integration
- Files:
-
- 17 edited
- 7 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3087_Ceres_Integration
- Property svn:mergeinfo changed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs
r17180 r18006 96 96 } 97 97 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 98 120 public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> GetFactorVariableValues( 99 121 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 99 99 </PropertyGroup> 100 100 <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> 103 104 <Private>False</Private> 104 105 </Reference> … … 145 146 <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" /> 146 147 <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" /> 147 152 <Compile Include="Implementation\Regression\RegressionEnsembleProblemData.cs" /> 148 153 <Compile Include="Implementation\Regression\RegressionEnsembleModel.cs"> … … 152 157 <Compile Include="Implementation\Regression\RegressionModel.cs" /> 153 158 <Compile Include="Implementation\Regression\RegressionSolutionVariableImpactsCalculator.cs" /> 159 <Compile Include="Implementation\Regression\ShapeConstraintsParser.cs" /> 154 160 <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" /> 155 161 <Compile Include="Implementation\TimeSeriesPrognosis\Models\TimeSeriesPrognosisAutoRegressiveModel.cs" /> … … 187 193 <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" /> 188 194 <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" /> 195 <Compile Include="Interfaces\Regression\IShapeConstrainedRegressionProblem.cs" /> 196 <Compile Include="Interfaces\Regression\IShapeConstrainedRegressionProblemData.cs" /> 189 197 <Compile Include="Interfaces\TimeSeriesPrognosis\IOnlineTimeSeriesCalculator.cs" /> 190 198 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisModel.cs" /> -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs
r17180 r18006 73 73 74 74 public ClassificationEnsembleProblemData() : base() { } 75 75 76 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) { 82 78 } 83 79 … … 85 81 : base(dataset, allowedInputVariables, targetVariable) { 86 82 } 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 } 87 87 } 88 88 } -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r17180 r18006 260 260 evaluationCache.Clear(); 261 261 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); 269 263 270 264 foreach (var solution in ClassificationSolutions) { -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r17180 r18006 306 306 classNamesCache.Add(ClassNamesParameter.Value[i, 0]); 307 307 } 308 308 309 public override IDeepCloneable Clone(Cloner cloner) { 309 310 if (this == emptyProblemData) return emptyProblemData; … … 311 312 } 312 313 313 public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable ) { }314 public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable, Enumerable.Empty<string>()) { } 314 315 315 316 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 317 330 TrainingPartition.Start = classificationProblemData.TrainingPartition.Start; 318 331 TrainingPartition.End = classificationProblemData.TrainingPartition.End; … … 320 333 TestPartition.End = classificationProblemData.TestPartition.End; 321 334 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 328 335 for (int i = 0; i < Classes; i++) { 329 336 for (int j = 0; j < Classes; j++) { … … 333 340 } 334 341 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) 336 346 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 337 347 var validTargetVariableValues = CheckVariablesForPossibleTargetVariables(dataset).Select(x => new StringValue(x).AsReadOnly()).ToList(); … … 339 349 340 350 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())); 342 352 Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassParameterName, "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)")); 343 353 Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "")); 344 354 345 355 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 } 347 380 } 348 381 -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs
r17180 r18006 34 34 private const string TrainingAccuracyResultName = "Accuracy (training)"; 35 35 private const string TestAccuracyResultName = "Accuracy (test)"; 36 private const string TrainingNormalizedGiniCoefficientResultName = "Norm alized Gini Coefficient(training)";37 private const string TestNormalizedGiniCoefficientResultName = "Norm alized Gini Coefficient(test)";36 private const string TrainingNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (training)"; 37 private const string TestNormalizedGiniCoefficientResultName = "Norm. Gini coeff. (test)"; 38 38 private const string ClassificationPerformanceMeasuresResultName = "Classification Performance Measures"; 39 39 … … 97 97 if (string.IsNullOrEmpty(Model.TargetVariable)) 98 98 Model.TargetVariable = this.ProblemData.TargetVariable; 99 100 if (!this.ContainsKey(TrainingNormalizedGiniCoefficientResultName)) 99 var newResult = false; 100 if (!this.ContainsKey(TrainingNormalizedGiniCoefficientResultName)) { 101 101 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)) { 103 105 Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue())); 106 newResult = true; 107 } 104 108 if (!this.ContainsKey(ClassificationPerformanceMeasuresResultName)) { 105 109 Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n 106 110 In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.", 107 111 new ClassificationPerformanceMeasuresResultCollection())); 108 CalculateClassificationResults();112 newResult = true; 109 113 } 114 if (newResult) CalculateClassificationResults(); 110 115 } 111 116 -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs
r17180 r18006 40 40 private const string TrainingRSquaredResultName = "Pearson's R² (training)"; 41 41 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 42 45 43 46 public new IDiscriminantFunctionClassificationModel Model { … … 71 74 private set { ((DoubleValue)this[TestRSquaredResultName].Value).Value = value; } 72 75 } 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 } 73 84 #endregion 74 85 … … 85 96 Add(new Result(TrainingRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue())); 86 97 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())); 87 100 RegisterEventHandler(); 88 101 } … … 90 103 [StorableHook(HookType.AfterDeserialization)] 91 104 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 92 122 RegisterEventHandler(); 93 123 } … … 106 136 107 137 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; 109 139 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; 111 141 112 142 double trainingNormalizedGini = NormalizedGiniCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); … … 115 145 if (errorState != OnlineCalculatorError.None) testNormalizedGini = double.NaN; 116 146 117 TrainingNormalizedGiniCoefficient = trainingNormalizedGini;118 TestNormalizedGiniCoefficient = testNormalizedGini;147 TrainingNormalizedGiniCoefficientForDiscriminantValues = trainingNormalizedGini; 148 TestNormalizedGiniCoefficientForDiscriminantValues = testNormalizedGini; 119 149 } 120 150 -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
- Property svn:mergeinfo changed
r17583 r18006 33 33 [Storable] 34 34 public double UpperBound { get; private set; } 35 36 public double Width => UpperBound - LowerBound; 35 37 36 38 [StorableConstructor] … … 67 69 } 68 70 71 private Interval(double v) : this(v, v) { } 72 69 73 public bool Contains(double value) { 70 74 return LowerBound <= value && value <= UpperBound; … … 74 78 if (double.IsNegativeInfinity(LowerBound) && double.IsPositiveInfinity(UpperBound)) return true; 75 79 if (other.LowerBound >= LowerBound && other.UpperBound <= UpperBound) return true; 76 80 77 81 return false; 78 82 } … … 93 97 /// </summary> 94 98 public bool IsPositive { 95 get => LowerBound > 0.0; 99 get => LowerBound > 0.0; 96 100 } 97 101 … … 126 130 return false; 127 131 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))); 130 134 } 131 135 … … 234 238 public static Interval Cube(Interval a) { 235 239 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 } 236 256 } 237 257 … … 267 287 } 268 288 269 public static Interval Analytic alQuotient(Interval a, Interval b) {289 public static Interval AnalyticQuotient(Interval a, Interval b) { 270 290 var dividend = a; 271 291 var divisor = Add(Square(b), new Interval(1.0, 1.0)); … … 276 296 } 277 297 #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 278 328 } 279 329 } -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs
r17564 r18006 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2019Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 34 34 get => HeuristicLab.Common.Resources.VSImageLibrary.Object; 35 35 } 36 private IDictionary<string, Interval> intervals { get; } = new Dictionary<string, Interval>();37 36 38 [Storable(Name = "StorableIntervalInformation")] 37 private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>(); 38 39 [Storable(OldName = "StorableIntervalInformation")] 39 40 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 { 40 49 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(); 43 53 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 }; 47 55 } 48 56 49 57 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 } 52 65 } 53 66 } … … 80 93 public void SetInterval(string identifier, Interval interval) { 81 94 intervals[identifier] = interval; 95 RaiseChanged(); 82 96 } 83 97 84 98 public void AddInterval(string identifier, Interval interval) { 85 99 intervals.Add(identifier, interval); 100 RaiseChanged(); 86 101 } 87 102 88 103 public void DeleteInterval(string identifier) { 89 104 intervals.Remove(identifier); 105 RaiseChanged(); 90 106 } 91 107 92 108 public IReadOnlyDictionary<string, Interval> GetReadonlyDictionary() { 109 return intervals.ToDictionary(pair => pair.Key, pair => pair.Value); 110 } 111 112 public IDictionary<string, Interval> GetDictionary() { 93 113 return intervals.ToDictionary(pair => pair.Key, pair => pair.Value); 94 114 } … … 98 118 yield return Tuple.Create(variableInterval.Key, variableInterval.Value); 99 119 } 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 100 128 } 101 129 } -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r17579 r18006 35 35 protected const string TargetVariableParameterName = "TargetVariable"; 36 36 protected const string VariableRangesParameterName = "VariableRanges"; 37 protected const string IntervalConstraintsParameterName = "IntervalConstraints";38 37 public string Filename { get; set; } 39 38 … … 78 77 defaultDataset = new Dataset(new string[] { "y", "x" }, kozaF1); 79 78 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"; 81 80 defaultAllowedInputVariables = new List<string>() { "x" }; 82 81 defaultTargetVariable = "y"; … … 98 97 #endregion 99 98 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 103 103 104 public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName]; 105 104 #region properties 106 105 public IntervalCollection VariableRanges { 107 106 get => VariableRangesParameter.Value; 108 107 } 109 110 108 111 109 public string TargetVariable { … … 120 118 } 121 119 } 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 122 124 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 }132 125 133 126 … … 137 130 private void AfterDeserialization() { 138 131 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)); 141 134 } 135 142 136 RegisterParameterEvents(); 143 137 } … … 163 157 } 164 158 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) 166 162 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 167 163 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); 168 164 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)); 172 169 } 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 182 173 } 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) { 188 175 OnChanged(); 189 176 } -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs
r17579 r18006 1 1 #region License Information 2 2 3 /* HeuristicLab 3 4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 18 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 20 */ 21 20 22 #endregion 21 23 … … 27 29 public interface IRegressionProblemData : IDataAnalysisProblemData { 28 30 string TargetVariable { get; set; } 29 30 IntervalCollection VariableRanges { get;} 31 31 IntervalCollection VariableRanges { get; } 32 32 IEnumerable<double> TargetVariableValues { get; } 33 33 IEnumerable<double> TargetVariableTrainingValues { get; } -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/AutoCorrelationCalculator.cs
r17180 r18006 31 31 } 32 32 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); 35 34 return correlations; 36 35 } -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/SpearmansRankCorrelationCoefficientCalculator.cs
r17180 r18006 45 45 var original = originalValues.ToArray(); 46 46 var estimated = estimatedValues.ToArray(); 47 rs = alglib. basestat.spearmancorr2(original, estimated, original.Length);47 rs = alglib.spearmancorr2(original, estimated, original.Length); 48 48 errorState = OnlineCalculatorError.None; 49 49 } -
branches/3087_Ceres_Integration/HeuristicLab.Problems.DataAnalysis/3.4/Plugin.cs.frame
r17184 r18006 28 28 [Plugin("HeuristicLab.Problems.DataAnalysis","Provides base classes for data analysis tasks.", "3.4.12.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.DataAnalysis-3.4.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.ALGLIB","3. 7.0")]30 [PluginDependency("HeuristicLab.ALGLIB","3.17.0")] 31 31 [PluginDependency("HeuristicLab.Collections", "3.3")] 32 32 [PluginDependency("HeuristicLab.Common", "3.3")]
Note: See TracChangeset
for help on using the changeset viewer.