Changeset 16788 for trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.cs
- Timestamp:
- 04/16/19 11:43:52 (5 years ago)
- Location:
- trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
-
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);
Note: See TracChangeset
for help on using the changeset viewer.