Changeset 16788
- Timestamp:
- 04/16/19 11:43:52 (6 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis (added) merged: 12212-12213,12416,12448-12449,13401
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj
r16658 r16788 126 126 <Compile Include="ModelCreators\NormalDistributedThresholdsModelCreator.cs" /> 127 127 <Compile Include="MultiObjective\SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 128 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.cs" /> 129 <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator.cs" /> 128 130 <Compile Include="SymbolicClassificationPhenotypicDiversityAnalyzer.cs" /> 129 131 <Compile Include="SymbolicClassificationPruningAnalyzer.cs" /> -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.cs
r16784 r16788 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 28 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 30 using HeuristicLab.Parameters; 30 using HeuristicLab.P ersistence.Default.CompositeSerializers.Storable;31 using HeuristicLab.PluginInfrastructure; 31 32 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.SingleObjective { 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 34 [NonDiscoverableType] 33 35 [Item("Weighted Performance Measures Evaluator", "Calculates the quality of a symbolic classification solution based on three weighted measures(normalized mean squared error, false negative rate(1-sensitivity) and false positve rate(1-specificity)).")] 34 [Storable Class]36 [StorableType("0772F316-5E12-4153-857E-8625069B4677")] 35 37 public class SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator : SymbolicClassificationSingleObjectiveEvaluator { 36 38 private const string NormalizedMeanSquaredErrorWeightingFactorParameterName = "NormalizedMeanSquaredErrorWeightingFactor"; … … 57 59 58 60 public double NormalizedMeanSquaredErrorWeightingFactor { 59 get { 60 return NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value; 61 } 61 get { return NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value; } 62 62 } 63 63 public double FalseNegativeRateWeightingFactor { 64 get { 65 return FalseNegativeRateWeightingFactorParameter.Value.Value; 66 } 64 get { return FalseNegativeRateWeightingFactorParameter.Value.Value; } 67 65 } 68 66 public double FalsePositiveRateWeightingFactor { 69 get { 70 return FalsePositiveRateWeightingFactorParameter.Value.Value; 71 } 67 get { return FalsePositiveRateWeightingFactorParameter.Value.Value; } 72 68 } 73 69 74 70 [StorableConstructor] 75 protected SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator( bool deserializing) : base(deserializing) { }71 protected SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(StorableConstructorFlag _) : base(_) { } 76 72 protected SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator original, Cloner cloner) 77 73 : base(original, cloner) { … … 79 75 public override IDeepCloneable Clone(Cloner cloner) { 80 76 return new SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(this, cloner); 81 }82 83 [StorableHook(HookType.AfterDeserialization)]84 private void AfterDeserialization() {85 // BackwardsCompatibility86 #region Backwards compatible code87 if (Parameters.ContainsKey(ModelCreatorParameterName)) {88 Parameters.Remove(ModelCreatorParameterName);89 Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "The model creator which is used during the evaluations."));90 }91 #endregion92 77 } 93 78 … … 102 87 public override IOperation InstrumentedApply() { 103 88 IEnumerable<int> rows = GenerateRowsToEvaluate(); 104 var solution= SymbolicExpressionTreeParameter.ActualValue;89 var tree = SymbolicExpressionTreeParameter.ActualValue; 105 90 var creator = ModelCreatorParameter.ActualValue; 106 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 107 ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, creator, NormalizedMeanSquaredErrorWeightingFactor, FalseNegativeRateWeightingFactor, FalsePositiveRateWeightingFactor); 91 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 92 var estimationLimits = EstimationLimitsParameter.ActualValue; 93 var applyLinearScaling = ApplyLinearScalingParameter.ActualValue.Value; 94 95 96 double quality = Calculate(interpreter, tree, estimationLimits.Lower, estimationLimits.Upper, 97 ProblemDataParameter.ActualValue, rows, applyLinearScaling, creator, NormalizedMeanSquaredErrorWeightingFactor, FalseNegativeRateWeightingFactor, FalsePositiveRateWeightingFactor); 108 98 QualityParameter.ActualValue = new DoubleValue(quality); 109 99 return base.InstrumentedApply(); 110 100 } 111 101 112 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData,102 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, 113 103 IEnumerable<int> rows, bool applyLinearScaling, ISymbolicClassificationModelCreator modelCreator, double normalizedMeanSquaredErrorWeightingFactor, double falseNegativeRateWeightingFactor, double falsePositiveRateWeightingFactor) { 114 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);104 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 115 105 var targetClassValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 116 106 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit).ToArray(); … … 124 114 ISymbolicDiscriminantFunctionClassificationModel m; 125 115 126 var model = modelCreator.CreateSymbolicClassificationModel( solution, interpreter, lowerEstimationLimit, upperEstimationLimit);116 var model = modelCreator.CreateSymbolicClassificationModel(problemData.TargetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit); 127 117 if ((m = model as ISymbolicDiscriminantFunctionClassificationModel) != null) { 128 118 m.ThresholdCalculator.Calculate(problemData, boundedEstimatedValues, targetClassValues, out classValues, out thresholds); … … 133 123 estimatedClassValues = model.GetEstimatedClassValues(problemData.Dataset, rows); 134 124 } 125 135 126 var performanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, problemData.GetClassValue(positiveClassName)); 136 127 performanceCalculator.Calculate(targetClassValues, estimatedClassValues); -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator.cs
r16784 r16788 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 28 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 30 using HeuristicLab.Parameters; 30 using HeuristicLab.P ersistence.Default.CompositeSerializers.Storable;31 using HeuristicLab.PluginInfrastructure; 31 32 32 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 34 [NonDiscoverableType] 33 35 [Item("Weighted Residuals Mean Squared Error Evaluator", @"A modified mean squared error evaluator that enables the possibility to weight residuals differently. 34 36 The first residual category belongs to estimated values which definitely belong to a specific class because the estimated value is located above the maximum or below the minimum of all the class values (DefiniteResidualsWeight). … … 36 38 All other cases are represented by the third category (NegativeClassesResidualsWeight). 37 39 The weight gets multiplied to the squared error. Note that the Evaluator acts like a normal MSE-Evaluator if all the weights are set to 1.")] 38 [Storable Class]39 public class SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator : SymbolicClassificationSingleObjectiveEvaluator {40 [StorableType("A3193296-1A0F-46E2-8F43-22E2ED9CFFC5")] 41 public sealed class SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator : SymbolicClassificationSingleObjectiveEvaluator { 40 42 private const string DefiniteResidualsWeightParameterName = "DefiniteResidualsWeight"; 41 43 private const string PositiveClassResidualsWeightParameterName = "PositiveClassResidualsWeight"; 42 44 private const string NegativeClassesResidualsWeightParameterName = "NegativeClassesResidualsWeight"; 43 45 [StorableConstructor] 44 pr otected SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { }45 pr otectedSymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator(SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator original, Cloner cloner)46 private SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator(StorableConstructorFlag _) : base(_) { } 47 private SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator(SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator original, Cloner cloner) 46 48 : base(original, cloner) { 47 49 } … … 73 75 74 76 public double DefiniteResidualsWeight { 75 get { 76 return DefiniteResidualsWeightParameter.Value.Value; 77 } 77 get { return DefiniteResidualsWeightParameter.Value.Value; } 78 78 } 79 79 public double PositiveClassResidualsWeight { 80 get { 81 return PositiveClassResidualsWeightParameter.Value.Value; 82 } 80 get { return PositiveClassResidualsWeightParameter.Value.Value; } 83 81 } 84 82 public double NegativeClassesResidualsWeight { 85 get { 86 return NegativeClassesResidualsWeightParameter.Value.Value; 87 } 83 get { return NegativeClassesResidualsWeightParameter.Value.Value; } 88 84 } 89 85 #endregion … … 98 94 } 99 95 100 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling,96 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree tree, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling, 101 97 double definiteResidualsWeight, double positiveClassResidualsWeight, double negativeClassesResidualsWeight) { 102 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues( solution, problemData.Dataset, rows);98 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(tree, problemData.Dataset, rows); 103 99 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 104 100 OnlineCalculatorError errorState; … … 115 111 double quality; 116 112 if (applyLinearScaling) { 117 var calculator = new OnlineWeighted ResidualsMeanSquaredErrorCalculator(positiveClassValue, classValuesMax, classValuesMin,113 var calculator = new OnlineWeightedClassificationMeanSquaredErrorCalculator(positiveClassValue, classValuesMax, classValuesMin, 118 114 definiteResidualsWeight, positiveClassResidualsWeight, negativeClassesResidualsWeight); 119 115 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, calculator, problemData.Dataset.Rows); … … 122 118 } else { 123 119 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 124 quality = OnlineWeighted ResidualsMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, positiveClassValue, classValuesMax,120 quality = OnlineWeightedClassificationMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, positiveClassValue, classValuesMax, 125 121 classValuesMin, definiteResidualsWeight, positiveClassResidualsWeight, negativeClassesResidualsWeight, out errorState); 126 122 } -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs
r16565 r16788 112 112 113 113 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 114 var estimatedValues = GetEstimatedValues(dataset, rows); 115 return GetEstimatedClassValues(estimatedValues); 116 } 117 public IEnumerable<double> GetEstimatedClassValues(IEnumerable<double> estimatedValues) { 114 118 if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current symbolic classification model."); 115 foreach (var x in GetEstimatedValues(dataset, rows)) {119 foreach (var x in estimatedValues) { 116 120 int classIndex = 0; 117 121 // find first threshold value which is larger than x => class index = threshold index + 1 … … 123 127 } 124 128 } 125 126 129 127 130 public override ISymbolicClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) { -
trunk/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
/branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis/3.4 (added) merged: 12213,12416,12448-12449,13401
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r16658 r16788 244 244 <Compile Include="OnlineCalculators\OnlineTheilsUStatisticCalculator.cs" /> 245 245 <Compile Include="OnlineCalculators\OnlineWeightedDirectionalSymmetryCalculator.cs" /> 246 <Compile Include="OnlineCalculators\OnlineWeightedClassificationMeanSquaredErrorCalculator.cs" /> 246 247 <Compile Include="Plugin.cs" /> 247 248 <Compile Include="Implementation\Classification\ThresholdCalculators\AccuracyMaximizationThresholdCalculator.cs" /> -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs
r16565 r16788 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 using HEAL.Attic;28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis { … … 121 121 122 122 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 123 var estimatedValues = GetEstimatedValues(dataset, rows); 124 return GetEstimatedClassValues(estimatedValues); 125 } 126 127 public virtual IEnumerable<double> GetEstimatedClassValues(IEnumerable<double> estimatedValues) { 123 128 if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model."); 124 foreach (var x in GetEstimatedValues(dataset, rows)) {129 foreach (var x in estimatedValues) { 125 130 int classIndex = 0; 126 131 // find first threshold value which is larger than x => class index = threshold index + 1 … … 132 137 } 133 138 } 139 134 140 #region events 135 141 public event EventHandler ThresholdsChanged; -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationModel.cs
r16565 r16788 34 34 void SetThresholdsAndClassValues(IEnumerable<double> thresholds, IEnumerable<double> classValues); 35 35 IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows); 36 IEnumerable<double> GetEstimatedClassValues(IEnumerable<double> estimatedValues); 36 37 37 38 event EventHandler ThresholdsChanged; -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedClassificationMeanSquaredErrorCalculator.cs
r16784 r16788 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 public class OnlineWeighted ResidualsMeanSquaredErrorCalculator : IOnlineCalculator {27 public class OnlineWeightedClassificationMeanSquaredErrorCalculator : IOnlineCalculator { 28 28 29 29 private double sse; … … 42 42 public double NegativeClassesResidualsWeight { get; private set; } 43 43 44 public OnlineWeighted ResidualsMeanSquaredErrorCalculator(double positiveClassValue, double classValuesMax, double classValuesMin,44 public OnlineWeightedClassificationMeanSquaredErrorCalculator(double positiveClassValue, double classValuesMax, double classValuesMin, 45 45 double definiteResidualsWeight, double positiveClassResidualsWeight, double negativeClassesResidualsWeight) { 46 46 PositiveClassValue = positiveClassValue; … … 93 93 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 94 94 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 95 OnlineWeighted ResidualsMeanSquaredErrorCalculator calculator = new OnlineWeightedResidualsMeanSquaredErrorCalculator(positiveClassValue, classValuesMax, classValuesMin, definiteResidualsWeight, positiveClassResidualsWeight, negativeClassesResidualsWeight);95 OnlineWeightedClassificationMeanSquaredErrorCalculator calculator = new OnlineWeightedClassificationMeanSquaredErrorCalculator(positiveClassValue, classValuesMax, classValuesMin, definiteResidualsWeight, positiveClassResidualsWeight, negativeClassesResidualsWeight); 96 96 97 97 // always move forward both enumerators (do not use short-circuit evaluation!)
Note: See TracChangeset
for help on using the changeset viewer.