Changeset 12694 for branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
- Timestamp:
- 07/09/15 13:07:30 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.Orienteering
- Files:
-
- 46 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.Orienteering
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
-
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 67 67 } 68 68 69 public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors( Dataset dataset, IEnumerable<int> rows) {69 public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows) { 70 70 var estimatedValuesEnumerators = (from model in models 71 71 select model.GetEstimatedClassValues(dataset, rows).GetEnumerator()) … … 82 82 #region IClassificationModel Members 83 83 84 public IEnumerable<double> GetEstimatedClassValues( Dataset dataset, IEnumerable<int> rows) {84 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 85 85 foreach (var estimatedValuesVector in GetEstimatedClassValueVectors(dataset, rows)) { 86 86 // return the class which is most often occuring -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 79 79 this.TestPartition.Start = classificationProblemData.TestPartition.Start; 80 80 this.TestPartition.End = classificationProblemData.TestPartition.End; 81 this.PositiveClass = classificationProblemData.PositiveClass; 81 82 } 82 83 -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 [StorableClass] 36 36 [Item("Classification Ensemble Solution", "A classification solution that contains an ensemble of multiple classification models")] 37 [Creatable( "Data Analysis - Ensembles")]37 [Creatable(CreatableAttribute.Categories.DataAnalysisEnsembles, Priority = 110)] 38 38 public sealed class ClassificationEnsembleSolution : ClassificationSolutionBase, IClassificationEnsembleSolution { 39 39 private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>(); … … 231 231 } 232 232 233 public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors( Dataset dataset, IEnumerable<int> rows) {233 public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(IDataset dataset, IEnumerable<int> rows) { 234 234 if (!Model.Models.Any()) yield break; 235 235 var estimatedValuesEnumerators = (from model in Model.Models -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblem.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 [StorableClass] 28 28 [Item("Classification Problem", "A general classification problem.")] 29 [Creatable("Problems")]30 29 public class ClassificationProblem : DataAnalysisProblem<IClassificationProblemData>, IClassificationProblem, IStorableContent { 31 30 public string Filename { get; set; } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 36 36 protected const string ClassNamesParameterName = "ClassNames"; 37 37 protected const string ClassificationPenaltiesParameterName = "ClassificationPenalties"; 38 protected const string PositiveClassParameterName = "PositiveClass"; 38 39 protected const int MaximumNumberOfClasses = 100; 39 40 protected const int InspectedRowsToDetermineTargets = 2000; … … 213 214 get { return (IFixedValueParameter<StringMatrix>)Parameters[ClassNamesParameterName]; } 214 215 } 216 public IConstrainedValueParameter<StringValue> PositiveClassParameter { 217 get { return (IConstrainedValueParameter<StringValue>)Parameters[PositiveClassParameterName]; } 218 } 215 219 public IFixedValueParameter<DoubleMatrix> ClassificationPenaltiesParameter { 216 220 get { return (IFixedValueParameter<DoubleMatrix>)Parameters[ClassificationPenaltiesParameterName]; } … … 262 266 get { return ClassNamesCache; } 263 267 } 268 269 public string PositiveClass { 270 get { return PositiveClassParameter.Value.Value; } 271 set { 272 var matchingValue = PositiveClassParameter.ValidValues.SingleOrDefault(x => x.Value == value); 273 if (matchingValue == null) throw new ArgumentException(string.Format("{0} cannot be set as positive class.", value)); 274 PositiveClassParameter.Value = matchingValue; 275 } 276 } 264 277 #endregion 265 278 … … 270 283 private void AfterDeserialization() { 271 284 RegisterParameterEvents(); 285 // BackwardsCompatibility3.4 286 #region Backwards compatible code, remove with 3.5 287 if (!Parameters.ContainsKey(PositiveClassParameterName)) { 288 var validValues = new ItemSet<StringValue>(ClassNames.Select(s => new StringValue(s).AsReadOnly())); 289 Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassParameterName, 290 "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)", validValues, validValues.First())); 291 } 292 #endregion 293 272 294 } 273 295 … … 290 312 TestPartition.End = classificationProblemData.TestPartition.End; 291 313 314 PositiveClass = classificationProblemData.PositiveClass; 315 292 316 for (int i = 0; i < classificationProblemData.ClassNames.Count(); i++) 293 317 ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i); … … 300 324 } 301 325 302 public ClassificationProblemData( Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)326 public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 303 327 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 304 328 var validTargetVariableValues = CheckVariablesForPossibleTargetVariables(dataset).Select(x => new StringValue(x).AsReadOnly()).ToList(); … … 307 331 Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(validTargetVariableValues), target)); 308 332 Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "")); 333 Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassParameterName, "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)")); 309 334 Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "")); 310 335 … … 313 338 } 314 339 315 public static IEnumerable<string> CheckVariablesForPossibleTargetVariables( Dataset dataset) {340 public static IEnumerable<string> CheckVariablesForPossibleTargetVariables(IDataset dataset) { 316 341 int maxSamples = Math.Min(InspectedRowsToDetermineTargets, dataset.Rows); 317 342 var validTargetVariables = (from v in dataset.DoubleVariables … … 339 364 ClassNamesParameter.Value.ColumnNames = new List<string>() { "ClassNames" }; 340 365 ClassNamesParameter.Value.RowNames = ClassValues.Select(s => "ClassValue: " + s); 366 367 PositiveClassParameter.ValidValues.Clear(); 368 foreach (var className in ClassNames) { 369 PositiveClassParameter.ValidValues.Add(new StringValue(className).AsReadOnly()); 370 } 341 371 342 372 ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Rows = Classes; … … 411 441 } 412 442 private void Parameter_ValueChanged(object sender, EventArgs e) { 443 var oldPositiveClass = PositiveClass; 444 var oldClassNames = classNamesCache; 445 var index = oldClassNames.IndexOf(oldPositiveClass); 446 413 447 classNamesCache = null; 414 448 ClassificationPenaltiesParameter.Value.RowNames = ClassNames.Select(name => "Actual " + name); 415 449 ClassificationPenaltiesParameter.Value.ColumnNames = ClassNames.Select(name => "Estimated " + name); 450 451 PositiveClassParameter.ValidValues.Clear(); 452 foreach (var className in ClassNames) { 453 PositiveClassParameter.ValidValues.Add(new StringValue(className).AsReadOnly()); 454 } 455 PositiveClassParameter.Value = PositiveClassParameter.ValidValues.ElementAt(index); 456 416 457 OnChanged(); 417 458 } … … 435 476 if (!newClassValues.SequenceEqual(ClassValues)) { 436 477 errorMessage = errorMessage + string.Format("The class values differ in the provided classification problem data."); 437 return false; 478 returnValue = false; 479 } 480 481 var newPositivieClassName = classificationProblemData.PositiveClass; 482 if (newPositivieClassName != PositiveClass) { 483 errorMessage = errorMessage + string.Format("The positive class differs in the provided classification problem data."); 484 returnValue = false; 438 485 } 439 486 … … 452 499 ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i); 453 500 501 PositiveClass = classificationProblemData.PositiveClass; 502 454 503 for (int i = 0; i < Classes; i++) { 455 504 for (int j = 0; j < Classes; j++) { -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 30 30 /// </summary> 31 31 [StorableClass] 32 public abstractclass ClassificationSolution : ClassificationSolutionBase {32 public class ClassificationSolution : ClassificationSolutionBase { 33 33 protected readonly Dictionary<int, double> evaluationCache; 34 34 … … 46 46 evaluationCache = new Dictionary<int, double>(problemData.Dataset.Rows); 47 47 CalculateClassificationResults(); 48 } 49 50 public override IDeepCloneable Clone(Cloner cloner) { 51 return new ClassificationSolution(this, cloner); 48 52 } 49 53 -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 34 34 private const string TrainingNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (training)"; 35 35 private const string TestNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (test)"; 36 private const string ClassificationPerformanceMeasuresResultName = "Classification Performance Measures"; 36 37 37 38 public new IClassificationModel Model { … … 62 63 protected set { ((DoubleValue)this[TestNormalizedGiniCoefficientResultName].Value).Value = value; } 63 64 } 65 public ClassificationPerformanceMeasuresResultCollection ClassificationPerformanceMeasures { 66 get { return ((ClassificationPerformanceMeasuresResultCollection)this[ClassificationPerformanceMeasuresResultName].Value); } 67 protected set { (this[ClassificationPerformanceMeasuresResultName].Value) = value; } 68 } 64 69 #endregion 65 70 … … 75 80 Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the training partition.", new DoubleValue())); 76 81 Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue())); 82 Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n 83 In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.", 84 new ClassificationPerformanceMeasuresResultCollection())); 77 85 } 78 86 … … 83 91 if (!this.ContainsKey(TestNormalizedGiniCoefficientResultName)) 84 92 Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue())); 93 if (!this.ContainsKey(ClassificationPerformanceMeasuresResultName)) { 94 Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n 95 In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.", 96 new ClassificationPerformanceMeasuresResultCollection())); 97 CalculateClassificationResults(); 98 } 85 99 } 86 100 … … 88 102 double[] estimatedTrainingClassValues = EstimatedTrainingClassValues.ToArray(); // cache values 89 103 double[] originalTrainingClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToArray(); 104 90 105 double[] estimatedTestClassValues = EstimatedTestClassValues.ToArray(); // cache values 91 106 double[] originalTestClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices).ToArray(); 107 108 var positiveClassName = ProblemData.PositiveClass; 109 double positiveClassValue = ProblemData.GetClassValue(positiveClassName); 110 ClassificationPerformanceMeasuresCalculator trainingPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, positiveClassValue); 111 ClassificationPerformanceMeasuresCalculator testPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, positiveClassValue); 92 112 93 113 OnlineCalculatorError errorState; … … 107 127 TrainingNormalizedGiniCoefficient = trainingNormalizedGini; 108 128 TestNormalizedGiniCoefficient = testNormalizedGini; 129 130 trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues); 131 if (trainingPerformanceCalculator.ErrorState == OnlineCalculatorError.None) 132 ClassificationPerformanceMeasures.SetTrainingResults(trainingPerformanceCalculator); 133 134 testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues); 135 if (testPerformanceCalculator.ErrorState == OnlineCalculatorError.None) 136 ClassificationPerformanceMeasures.SetTestResults(testPerformanceCalculator); 109 137 } 110 138 -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 111 111 112 112 113 public IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows) {113 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 114 114 return model.GetEstimatedValues(dataset, rows); 115 115 } 116 116 117 public IEnumerable<double> GetEstimatedClassValues( Dataset dataset, IEnumerable<int> rows) {117 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 118 118 if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model."); 119 119 foreach (var x in GetEstimatedValues(dataset, rows)) { -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 105 105 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN; 106 106 107 double trainingR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);108 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR 2: double.NaN;109 double testR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);110 TestRSquared = errorState == OnlineCalculatorError.None ? testR 2: double.NaN;107 double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 108 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN; 109 double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 110 TestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN; 111 111 112 112 double trainingNormalizedGini = NormalizedGiniCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/AccuracyMaximizationThresholdCalculator.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/NormalDistributionCutPointsThresholdCalculator.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/ThresholdCalculator.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Clustering/ClusteringProblem.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 [StorableClass] 28 28 [Item("Clustering Problem", "A general clustering problem.")] 29 [Creatable("Problems")]30 29 public class ClusteringProblem : DataAnalysisProblem<IClusteringProblemData>, IClusteringProblem { 31 30 [StorableConstructor] -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Clustering/ClusteringProblemData.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Clustering/ClusteringSolution.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblem.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 63 63 get { return isEmpty; } 64 64 } 65 public Dataset Dataset {65 public IDataset Dataset { 66 66 get { return DatasetParameter.Value; } 67 67 } … … 126 126 } 127 127 128 protected DataAnalysisProblemData( Dataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<ITransformation> transformations = null) {128 protected DataAnalysisProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<ITransformation> transformations = null) { 129 129 if (dataset == null) throw new ArgumentNullException("The dataset must not be null."); 130 130 if (allowedInputVariables == null) throw new ArgumentNullException("The allowedInputVariables must not be null."); … … 144 144 var transformationsList = new ItemList<ITransformation>(transformations ?? Enumerable.Empty<ITransformation>()); 145 145 146 Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", dataset));146 Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", (Dataset)dataset)); 147 147 Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, "", inputVariables.AsReadOnly())); 148 148 Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", new IntRange(trainingPartitionStart, trainingPartitionEnd))); -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Drawing; 24 25 using HeuristicLab.Common; … … 106 107 } 107 108 109 //mkommend avoid unnecessary event registration for result name changes 110 protected override void RegisterItemEvents(IEnumerable<IResult> items) { } 111 protected override void DeregisterItemEvents(IEnumerable<IResult> items) { } 112 108 113 #region INamedItem Members 109 114 [Storable] -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 51 51 } 52 52 53 public IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows) {53 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 54 54 return rows.Select(row => Constant); 55 55 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionSolution.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 80 80 } 81 81 82 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors( Dataset dataset, IEnumerable<int> rows) {82 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows) { 83 83 var estimatedValuesEnumerators = (from model in models 84 84 select model.GetEstimatedValues(dataset, rows).GetEnumerator()) … … 95 95 #region IRegressionModel Members 96 96 97 public IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows) {97 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 98 98 foreach (var estimatedValuesVector in GetEstimatedValueVectors(dataset, rows)) { 99 99 yield return estimatedValuesVector.Average(); -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleProblemData.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 35 35 [StorableClass] 36 36 [Item("Regression Ensemble Solution", "A regression solution that contains an ensemble of multiple regression models")] 37 [Creatable( "Data Analysis - Ensembles")]37 [Creatable(CreatableAttribute.Categories.DataAnalysisEnsembles, Priority = 100)] 38 38 public sealed class RegressionEnsembleSolution : RegressionSolutionBase, IRegressionEnsembleSolution { 39 39 private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>(); … … 232 232 } 233 233 234 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors( Dataset dataset, IEnumerable<int> rows) {234 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(IDataset dataset, IEnumerable<int> rows) { 235 235 if (!Model.Models.Any()) yield break; 236 236 var estimatedValuesEnumerators = (from model in Model.Models -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 [StorableClass] 28 28 [Item("Regression Problem", "A general regression problem.")] 29 [Creatable("Problems")]30 29 public class RegressionProblem : DataAnalysisProblem<IRegressionProblemData>, IRegressionProblem, IStorableContent { 31 30 public string Filename { get; set; } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 137 137 } 138 138 139 public RegressionProblemData( Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)139 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 140 140 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 141 141 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 30 30 /// </summary> 31 31 [StorableClass] 32 public abstractclass RegressionSolution : RegressionSolutionBase {32 public class RegressionSolution : RegressionSolutionBase { 33 33 protected readonly Dictionary<int, double> evaluationCache; 34 34 … … 42 42 evaluationCache = new Dictionary<int, double>(original.evaluationCache); 43 43 } 44 p rotectedRegressionSolution(IRegressionModel model, IRegressionProblemData problemData)44 public RegressionSolution(IRegressionModel model, IRegressionProblemData problemData) 45 45 : base(model, problemData) { 46 46 evaluationCache = new Dictionary<int, double>(problemData.Dataset.Rows); … … 48 48 } 49 49 50 public override IDeepCloneable Clone(Cloner cloner) { 51 return new RegressionSolution(this, cloner); 52 } 50 53 51 54 public override IEnumerable<double> EstimatedValues { … … 60 63 61 64 public override IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) { 62 var rowsToEvaluate = rows. Except(evaluationCache.Keys);65 var rowsToEvaluate = rows.Where(row => !evaluationCache.ContainsKey(row)); 63 66 var rowsEnumerator = rowsToEvaluate.GetEnumerator(); 64 67 var valuesEnumerator = Model.GetEstimatedValues(ProblemData.Dataset, rowsToEvaluate).GetEnumerator(); -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; … … 39 40 protected const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)"; 40 41 protected const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)"; 41 protected const string TrainingMeanErrorResultName = "Mean error (training)"; 42 protected const string TestMeanErrorResultName = "Mean error (test)"; 42 protected const string TrainingRootMeanSquaredErrorResultName = "Root mean squared error (training)"; 43 protected const string TestRootMeanSquaredErrorResultName = "Root mean squared error (test)"; 44 45 // BackwardsCompatibility3.3 46 #region Backwards compatible code, remove with 3.5 47 private const string TrainingMeanErrorResultName = "Mean error (training)"; 48 private const string TestMeanErrorResultName = "Mean error (test)"; 49 #endregion 50 43 51 44 52 protected const string TrainingMeanSquaredErrorResultDescription = "Mean of squared errors of the model on the training partition"; … … 52 60 protected const string TrainingNormalizedMeanSquaredErrorResultDescription = "Normalized mean of squared errors of the model on the training partition"; 53 61 protected const string TestNormalizedMeanSquaredErrorResultDescription = "Normalized mean of squared errors of the model on the test partition"; 54 protected const string Training MeanErrorResultDescription = "Mean oferrors of the model on the training partition";55 protected const string Test MeanErrorResultDescription = "Mean oferrors of the model on the test partition";62 protected const string TrainingRootMeanSquaredErrorResultDescription = "Root mean of squared errors of the model on the training partition"; 63 protected const string TestRootMeanSquaredErrorResultDescription = "Root mean of squared errors of the model on the test partition"; 56 64 57 65 public new IRegressionModel Model { … … 111 119 private set { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; } 112 120 } 113 public double TrainingMeanError { 114 get { return ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value; } 115 private set { ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value = value; } 116 } 117 public double TestMeanError { 118 get { return ((DoubleValue)this[TestMeanErrorResultName].Value).Value; } 119 private set { ((DoubleValue)this[TestMeanErrorResultName].Value).Value = value; } 120 } 121 public double TrainingRootMeanSquaredError { 122 get { return ((DoubleValue)this[TrainingRootMeanSquaredErrorResultName].Value).Value; } 123 private set { ((DoubleValue)this[TrainingRootMeanSquaredErrorResultName].Value).Value = value; } 124 } 125 public double TestRootMeanSquaredError { 126 get { return ((DoubleValue)this[TestRootMeanSquaredErrorResultName].Value).Value; } 127 private set { ((DoubleValue)this[TestRootMeanSquaredErrorResultName].Value).Value = value; } 128 } 129 130 // BackwardsCompatibility3.3 131 #region Backwards compatible code, remove with 3.5 132 private double TrainingMeanError { 133 get { 134 if (!ContainsKey(TrainingMeanErrorResultName)) return double.NaN; 135 return ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value; 136 } 137 set { 138 if (ContainsKey(TrainingMeanErrorResultName)) 139 ((DoubleValue)this[TrainingMeanErrorResultName].Value).Value = value; 140 } 141 } 142 private double TestMeanError { 143 get { 144 if (!ContainsKey(TestMeanErrorResultName)) return double.NaN; 145 return ((DoubleValue)this[TestMeanErrorResultName].Value).Value; 146 } 147 set { 148 if (ContainsKey(TestMeanErrorResultName)) 149 ((DoubleValue)this[TestMeanErrorResultName].Value).Value = value; 150 } 151 } 152 #endregion 121 153 #endregion 122 154 … … 138 170 Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, TrainingNormalizedMeanSquaredErrorResultDescription, new DoubleValue())); 139 171 Add(new Result(TestNormalizedMeanSquaredErrorResultName, TestNormalizedMeanSquaredErrorResultDescription, new DoubleValue())); 140 Add(new Result(Training MeanErrorResultName, TrainingMeanErrorResultDescription, new DoubleValue()));141 Add(new Result(Test MeanErrorResultName, TestMeanErrorResultDescription, new DoubleValue()));172 Add(new Result(TrainingRootMeanSquaredErrorResultName, TrainingRootMeanSquaredErrorResultDescription, new DoubleValue())); 173 Add(new Result(TestRootMeanSquaredErrorResultName, TestRootMeanSquaredErrorResultDescription, new DoubleValue())); 142 174 } 143 175 … … 145 177 private void AfterDeserialization() { 146 178 // BackwardsCompatibility3.4 147 148 179 #region Backwards compatible code, remove with 3.5 149 150 180 if (!ContainsKey(TrainingMeanAbsoluteErrorResultName)) { 151 181 OnlineCalculatorError errorState; … … 162 192 } 163 193 164 if (!ContainsKey(TrainingMeanErrorResultName)) { 165 OnlineCalculatorError errorState; 166 Add(new Result(TrainingMeanErrorResultName, "Mean of errors of the model on the training partition", new DoubleValue())); 167 double trainingME = OnlineMeanErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState); 168 TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN; 169 } 170 if (!ContainsKey(TestMeanErrorResultName)) { 171 OnlineCalculatorError errorState; 172 Add(new Result(TestMeanErrorResultName, "Mean of errors of the model on the test partition", new DoubleValue())); 173 double testME = OnlineMeanErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState); 174 TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN; 194 if (!ContainsKey(TrainingRootMeanSquaredErrorResultName)) { 195 OnlineCalculatorError errorState; 196 Add(new Result(TrainingRootMeanSquaredErrorResultName, TrainingRootMeanSquaredErrorResultDescription, new DoubleValue())); 197 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(EstimatedTrainingValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices), out errorState); 198 TrainingRootMeanSquaredError = errorState == OnlineCalculatorError.None ? Math.Sqrt(trainingMSE) : double.NaN; 199 } 200 201 if (!ContainsKey(TestRootMeanSquaredErrorResultName)) { 202 OnlineCalculatorError errorState; 203 Add(new Result(TestRootMeanSquaredErrorResultName, TestRootMeanSquaredErrorResultDescription, new DoubleValue())); 204 double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(EstimatedTestValues, ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices), out errorState); 205 TestRootMeanSquaredError = errorState == OnlineCalculatorError.None ? Math.Sqrt(testMSE) : double.NaN; 175 206 } 176 207 #endregion … … 198 229 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN; 199 230 200 double trainingR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);201 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR 2: double.NaN;202 double testR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);203 TestRSquared = errorState == OnlineCalculatorError.None ? testR 2: double.NaN;231 double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 232 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN; 233 double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 234 TestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN; 204 235 205 236 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); … … 213 244 TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN; 214 245 215 double trainingME = OnlineMeanErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 216 TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN; 217 double testME = OnlineMeanErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 218 TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN; 246 TrainingRootMeanSquaredError = Math.Sqrt(TrainingMeanSquaredError); 247 TestRootMeanSquaredError = Math.Sqrt(TestMeanSquaredError); 248 249 // BackwardsCompatibility3.3 250 #region Backwards compatible code, remove with 3.5 251 if (ContainsKey(TrainingMeanErrorResultName)) { 252 double trainingME = OnlineMeanErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 253 TrainingMeanError = errorState == OnlineCalculatorError.None ? trainingME : double.NaN; 254 } 255 if (ContainsKey(TestMeanErrorResultName)) { 256 double testME = OnlineMeanErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 257 TestMeanError = errorState == OnlineCalculatorError.None ? testME : double.NaN; 258 } 259 #endregion 219 260 } 220 261 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/ConstantTimeSeriesPrognosisModel.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 39 39 public ConstantTimeSeriesPrognosisModel(double constant) : base(constant) { } 40 40 41 public IEnumerable<IEnumerable<double>> GetPrognosedValues( Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) {41 public IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) { 42 42 return horizons.Select(horizon => Enumerable.Repeat(Constant, horizon)); 43 43 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 58 58 } 59 59 60 public IEnumerable<IEnumerable<double>> GetPrognosedValues( Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) {60 public IEnumerable<IEnumerable<double>> GetPrognosedValues(IDataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) { 61 61 var rowsEnumerator = rows.GetEnumerator(); 62 62 var horizonsEnumerator = horizons.GetEnumerator(); … … 91 91 } 92 92 93 public IEnumerable<double> GetEstimatedValues( Dataset dataset, IEnumerable<int> rows) {93 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 94 94 var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable); 95 95 foreach (int row in rows) { -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblem.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 [StorableClass] 28 28 [Item("Time-series Prognosis Problem", "A general time-series prognosis problem.")] 29 [Creatable("Problems")]30 29 public class TimeSeriesPrognosisProblem : DataAnalysisProblem<ITimeSeriesPrognosisProblemData>, ITimeSeriesPrognosisProblem { 31 30 [StorableConstructor] -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisProblemData.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 1582 1582 TrainingPartition.Start = 50; 1583 1583 } 1584 public TimeSeriesPrognosisProblemData( Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)1584 public TimeSeriesPrognosisProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 1585 1585 : base(dataset, allowedInputVariables, targetVariable, transformations ?? Enumerable.Empty<ITransformation>()) { 1586 1586 Parameters.Add(new FixedValueParameter<IntValue>(TrainingHorizonParameterName, "Specifies the horizon (how far the prognosis reaches in the future) for each training sample.", new IntValue(1))); -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisResults.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 394 394 double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 395 395 PrognosisTrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN; 396 double trainingR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);397 PrognosisTrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR 2: double.NaN;396 double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 397 PrognosisTrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN; 398 398 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 399 399 PrognosisTrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN; … … 430 430 double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 431 431 PrognosisTestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN; 432 double testR 2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);433 PrognosisTestRSquared = errorState == OnlineCalculatorError.None ? testR 2: double.NaN;432 double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 433 PrognosisTestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN; 434 434 double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState); 435 435 PrognosisTestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN; -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolution.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/CopyColumnTransformation.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis { 31 [StorableClass] 31 32 [Item("CopyColumnTransformation", "Represents a transformation which represents a copied Column.")] 32 33 public class CopyColumnTransformation : Transformation { -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ExponentialTransformation.cs
r11114 r12694 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq; 3 4 using HeuristicLab.Common; 4 5 using HeuristicLab.Core; … … 8 9 9 10 namespace HeuristicLab.Problems.DataAnalysis { 11 [StorableClass] 10 12 [Item("Exponential Transformation", "f(x) = b ^ x | Represents a exponential transformation.")] 11 13 public class ExponentialTransformation : Transformation<double> { … … 44 46 45 47 public override IEnumerable<double> Apply(IEnumerable<double> data) { 46 foreach (double d in data) { 47 yield return Math.Pow(Base, d); 48 } 48 return data.Select(d => Math.Pow(Base, d)); 49 49 } 50 50 -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 32 32 namespace HeuristicLab.Problems.DataAnalysis { 33 [StorableClass] 33 34 [Item("Linear Transformation", "f(x) = k * x + d | Represents a linear transformation with multiplication and addition.")] 34 35 public class LinearTransformation : Transformation<double> { … … 80 81 81 82 public override IEnumerable<double> Apply(IEnumerable<double> data) { 82 return data.Select(e => e * Multiplier + Addend); 83 var m = Multiplier; 84 var a = Addend; 85 return data.Select(e => e * m + a); 83 86 } 84 87 85 88 public override bool Check(IEnumerable<double> data, out string errorMsg) { 86 89 errorMsg = null; 87 if (Multiplier == 0.0) {90 if (Multiplier.IsAlmost(0.0)) { 88 91 errorMsg = String.Format("Multiplicand is 0, all {0} entries will be set to {1}. Inverse apply will not be possible (division by 0).", data.Count(), Addend); 89 92 return false; -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LogarithmicTransformation.cs
r11114 r12694 9 9 10 10 namespace HeuristicLab.Problems.DataAnalysis { 11 [StorableClass] 11 12 [Item("Logarithmic Transformation", "f(x) = log(x, b) | Represents a logarithmic transformation.")] 12 13 public class LogarithmicTransformation : Transformation<double> { … … 43 44 44 45 public override IEnumerable<double> Apply(IEnumerable<double> data) { 45 foreach (double i in data) { 46 if (i > 0.0) 47 yield return Math.Log(i, Base); 48 else 49 yield return i; 50 } 46 var b = Base; 47 return data.Select(d => d > 0.0 ? Math.Log(d, b) : d); 51 48 } 52 49 -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/PowerTransformation.cs
r11114 r12694 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq; 3 4 using HeuristicLab.Common; 4 5 using HeuristicLab.Core; … … 8 9 9 10 namespace HeuristicLab.Problems.DataAnalysis { 11 [StorableClass] 10 12 [Item("Power Transformation", "f(x) = x ^ exp | Represents a power transformation.")] 11 13 public class PowerTransformation : Transformation<double> { … … 42 44 43 45 public override IEnumerable<double> Apply(IEnumerable<double> data) { 44 foreach (double i in data) { 45 yield return Math.Pow(i, Exponent); 46 } 46 return data.Select(i => Math.Pow(i, Exponent)); 47 47 } 48 48 -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ReciprocalTransformation.cs
r11114 r12694 7 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 8 namespace HeuristicLab.Problems.DataAnalysis { 9 [StorableClass] 9 10 [Item("Reciprocal Transformation", "f(x) = 1 / x | Represents a reciprocal transformation.")] 10 11 public class ReciprocalTransformation : Transformation<double> { … … 16 17 #endregion 17 18 18 //TODO: is a special case of Linear19 19 [StorableConstructor] 20 20 protected ReciprocalTransformation(bool deserializing) : base(deserializing) { } … … 31 31 32 32 public override IEnumerable<double> Apply(IEnumerable<double> data) { 33 foreach (double i in data) { 34 if (i > 0.0) 35 yield return 1.0 / i; 36 else 37 yield return i; 38 } 33 return data.Select(d => d > 0 ? 1.0 / d : d); 39 34 } 40 35 -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftStandardDistributionTransformation.cs
r11114 r12694 8 8 9 9 namespace HeuristicLab.Problems.DataAnalysis { 10 [StorableClass] 10 11 [Item("Shift Standard Distribution Transformation", "f(x) = ((x - m_org) / s_org ) * s_tar + m_tar | Represents Transformation to unit standard deviation and additional linear transformation to a target Mean and Standard deviation")] 11 12 public class ShiftStandardDistributionTransformation : Transformation<double> { … … 69 70 } 70 71 71 // http://en.wikipedia.org/wiki/Standard_deviation72 // http://www.statistics4u.info/fundstat_germ/ee_ztransform.html73 // https://www.uni-due.de/~bm0061/vorl12.pdf p574 72 public override IEnumerable<double> Apply(IEnumerable<double> data) { 75 73 ConfigureParameters(data); 76 if (OriginalStandardDeviation == 0.0) { 77 foreach (var e in data) { 78 yield return e; 79 } 80 yield break; 74 if (OriginalStandardDeviation.IsAlmost(0.0)) { 75 return data; 81 76 } 82 83 foreach (var e in data) { 84 double unitNormalDistributedValue = (e - OriginalMean) / OriginalStandardDeviation; 85 yield return unitNormalDistributedValue * StandardDeviation + Mean; 86 } 77 var old_m = OriginalMean; 78 var old_s = OriginalStandardDeviation; 79 var m = Mean; 80 var s = StandardDeviation; 81 return data 82 .Select(d => (d - old_m) / old_s) // standardized 83 .Select(d => d * s + m); 87 84 } 88 85 … … 90 87 ConfigureParameters(data); 91 88 errorMsg = ""; 92 if (OriginalStandardDeviation == 0.0) {89 if (OriginalStandardDeviation.IsAlmost(0.0)) { 93 90 errorMsg = "Standard deviaton for the original data is 0.0, Transformation cannot be applied onto these values."; 94 91 return false; -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftToRangeTransformation.cs
r11114 r12694 8 8 9 9 namespace HeuristicLab.Problems.DataAnalysis { 10 [StorableClass] 10 11 [Item("Shift to Range Transformation", "f(x) = k * x + d, start <= f(x) <= end | Represents a linear Transformation using Parameters defining a target range")] 11 12 public class ShiftToRangeTransformation : LinearTransformation { -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 32 32 [Item("Transformation", "Represents the base class for a transformation.")] 33 [StorableClass]34 33 public abstract class Transformation : ParameterizedNamedItem, ITransformation { 35 34 protected const string ColumnParameterName = "Column";
Note: See TracChangeset
for help on using the changeset viewer.