Changeset 12211 for branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Timestamp:
- 03/17/15 11:38:41 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SensitivityEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.cs
r12210 r12211 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 24 using HeuristicLab.Common; 7 25 using HeuristicLab.Core; … … 12 30 13 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.SingleObjective { 14 [Item("Weighted Performance Measures Evaluator", " Description")]32 [Item("Weighted Performance Measures Evaluator", "Calculates the quality a symbolic classification solution based on three weighted measures(normalized mean squared error, false negative rate and false positve rate).")] 15 33 [StorableClass] 16 34 public class SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator : SymbolicClassificationSingleObjectiveEvaluator { 17 35 private const string NormalizedMeanSquaredErrorWeightingFactorParameterName = "NormalizedMeanSquaredErrorWeightingFactor"; 18 private const string BetaParameterName = "Beta";19 private const string GammaParameterName = "Gamma";36 private const string FalseNegativeRateWeightingFactorParameterName = "FalseNegativeRateWeightingFactor"; 37 private const string FalsePositiveRateWeightingFactorParameterName = "FalsePositiveRateWeightingFactor"; 20 38 private const string ModelCreatorParameterName = "ModelCreator"; 21 39 … … 26 44 get { return (IFixedValueParameter<DoubleValue>)Parameters[NormalizedMeanSquaredErrorWeightingFactorParameterName]; } 27 45 } 28 public IFixedValueParameter<DoubleValue> BetaParameter {29 get { return (IFixedValueParameter<DoubleValue>)Parameters[ BetaParameterName]; }46 public IFixedValueParameter<DoubleValue> FalseNegativeRateWeightingFactorParameter { 47 get { return (IFixedValueParameter<DoubleValue>)Parameters[FalseNegativeRateWeightingFactorParameterName]; } 30 48 } 31 public IFixedValueParameter<DoubleValue> GammaParameter {32 get { return (IFixedValueParameter<DoubleValue>)Parameters[ GammaParameterName]; }49 public IFixedValueParameter<DoubleValue> FalsePositiveRateWeightingFactorParameter { 50 get { return (IFixedValueParameter<DoubleValue>)Parameters[FalsePositiveRateWeightingFactorParameterName]; } 33 51 } 34 52 public ILookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { … … 36 54 } 37 55 #endregion 56 57 public double NormalizedMeanSquaredErrorWeightingFactor { 58 get { 59 return NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value; 60 } 61 } 62 public double FalseNegativeRateWeightingFactor { 63 get { 64 return FalseNegativeRateWeightingFactorParameter.Value.Value; 65 } 66 } 67 public double FalsePositiveRateWeightingFactor { 68 get { 69 return FalsePositiveRateWeightingFactorParameter.Value.Value; 70 } 71 } 38 72 39 73 [StorableConstructor] … … 49 83 : base() { 50 84 Parameters.Add(new FixedValueParameter<DoubleValue>(NormalizedMeanSquaredErrorWeightingFactorParameterName, "The weighting factor of the normalized mean squared error.", new DoubleValue(1))); 51 Parameters.Add(new FixedValueParameter<DoubleValue>( BetaParameterName, "Beta1", new DoubleValue(1)));52 Parameters.Add(new FixedValueParameter<DoubleValue>( GammaParameterName, "Gamma1", new DoubleValue(1)));85 Parameters.Add(new FixedValueParameter<DoubleValue>(FalseNegativeRateWeightingFactorParameterName, "The weighting factor of the false negative rate (1-sensitivity).", new DoubleValue(1))); 86 Parameters.Add(new FixedValueParameter<DoubleValue>(FalsePositiveRateWeightingFactorParameterName, "The weighting factor of the false positive rate (1-specificity).", new DoubleValue(1))); 53 87 Parameters.Add(new LookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "ModelCreator")); 54 88 } … … 58 92 var solution = SymbolicExpressionTreeParameter.ActualValue; 59 93 var creator = ModelCreatorParameter.ActualValue; 60 double normalizedMeanSquaredErrorWeightingFactor = NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value;61 double beta = BetaParameter.Value.Value;62 double gamma = GammaParameter.Value.Value;63 94 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 64 ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, creator, normalizedMeanSquaredErrorWeightingFactor, beta, gamma);95 ProblemDataParameter.ActualValue, rows, ApplyLinearScalingParameter.ActualValue.Value, creator, NormalizedMeanSquaredErrorWeightingFactor, FalseNegativeRateWeightingFactor, FalsePositiveRateWeightingFactor); 65 96 QualityParameter.ActualValue = new DoubleValue(quality); 66 97 return base.InstrumentedApply(); … … 68 99 69 100 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, 70 IEnumerable<int> rows, bool applyLinearScaling, ISymbolicClassificationModelCreator modelCreator, double normalizedMeanSquaredErrorWeightingFactor, double betaParameter, double gammaParameter) {101 IEnumerable<int> rows, bool applyLinearScaling, ISymbolicClassificationModelCreator modelCreator, double normalizedMeanSquaredErrorWeightingFactor, double falseNegativeRateWeightingFactor, double falsePositiveRateWeightingFactor) { 71 102 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 72 103 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 73 104 OnlineCalculatorError errorState; 74 105 double nmse; 75 76 //calculate qualitymeasures106 107 //calculate performance measures 77 108 var model = modelCreator.CreateSymbolicClassificationModel(solution, interpreter, lowerEstimationLimit, upperEstimationLimit); 78 109 string positiveClassName = problemData.PositiveClass; 79 110 model.RecalculateModelParameters(problemData, rows); 80 111 var performanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, problemData.GetClassValue(positiveClassName)); 81 var estimated = model.GetEstimatedClassValues(problemData.Dataset, rows); 82 performanceCalculator.Calculate(estimated, targetValues); 83 if (performanceCalculator.ErrorState != OnlineCalculatorError.None) return Double.NaN; 112 var estimatedClassValues = model.GetEstimatedClassValues(problemData.Dataset, rows); 113 performanceCalculator.Calculate(estimatedClassValues, targetValues); 114 if (performanceCalculator.ErrorState != OnlineCalculatorError.None) 115 return Double.NaN; 116 double falseNegativeRate = 1 - performanceCalculator.TruePositiveRate; 84 117 double falsePositiveRate = performanceCalculator.FalsePositiveRate; 85 double falseNegativeRate = 1 - performanceCalculator.TruePositiveRate;86 118 87 119 if (applyLinearScaling) { … … 95 127 } 96 128 if (errorState != OnlineCalculatorError.None) return Double.NaN; 97 return normalizedMeanSquaredErrorWeightingFactor * nmse + betaParameter * falsePositiveRate + gammaParameter * falseNegativeRate; 129 130 return normalizedMeanSquaredErrorWeightingFactor * nmse + falseNegativeRateWeightingFactor * falseNegativeRate + falsePositiveRateWeightingFactor * falsePositiveRate; 98 131 } 99 132 … … 105 138 106 139 double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, 107 problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, ModelCreatorParameter.ActualValue, NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value, BetaParameter.Value.Value, GammaParameter.Value.Value);140 problemData, rows, ApplyLinearScalingParameter.ActualValue.Value, ModelCreatorParameter.ActualValue, NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value, FalseNegativeRateWeightingFactor, FalsePositiveRateWeightingFactor); 108 141 109 142 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
Note: See TracChangeset
for help on using the changeset viewer.