Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/15 11:38:41 (10 years ago)
Author:
ehopf
Message:

#2361: Simple refactoring of SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.

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
     22using System;
    223using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    624using HeuristicLab.Common;
    725using HeuristicLab.Core;
     
    1230
    1331namespace 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).")]
    1533  [StorableClass]
    1634  public class SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator : SymbolicClassificationSingleObjectiveEvaluator {
    1735    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";
    2038    private const string ModelCreatorParameterName = "ModelCreator";
    2139
     
    2644      get { return (IFixedValueParameter<DoubleValue>)Parameters[NormalizedMeanSquaredErrorWeightingFactorParameterName]; }
    2745    }
    28     public IFixedValueParameter<DoubleValue> BetaParameter {
    29       get { return (IFixedValueParameter<DoubleValue>)Parameters[BetaParameterName]; }
     46    public IFixedValueParameter<DoubleValue> FalseNegativeRateWeightingFactorParameter {
     47      get { return (IFixedValueParameter<DoubleValue>)Parameters[FalseNegativeRateWeightingFactorParameterName]; }
    3048    }
    31     public IFixedValueParameter<DoubleValue> GammaParameter {
    32       get { return (IFixedValueParameter<DoubleValue>)Parameters[GammaParameterName]; }
     49    public IFixedValueParameter<DoubleValue> FalsePositiveRateWeightingFactorParameter {
     50      get { return (IFixedValueParameter<DoubleValue>)Parameters[FalsePositiveRateWeightingFactorParameterName]; }
    3351    }
    3452    public ILookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
     
    3654    }
    3755    #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    }
    3872
    3973    [StorableConstructor]
     
    4983      : base() {
    5084      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)));
    5387      Parameters.Add(new LookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, "ModelCreator"));
    5488    }
     
    5892      var solution = SymbolicExpressionTreeParameter.ActualValue;
    5993      var creator = ModelCreatorParameter.ActualValue;
    60       double normalizedMeanSquaredErrorWeightingFactor = NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value;
    61       double beta = BetaParameter.Value.Value;
    62       double gamma = GammaParameter.Value.Value;
    6394      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);
    6596      QualityParameter.ActualValue = new DoubleValue(quality);
    6697      return base.InstrumentedApply();
     
    6899
    69100    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) {
    71102      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    72103      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    73104      OnlineCalculatorError errorState;
    74105      double nmse;
    75      
    76       //calculate quality measures
     106
     107      //calculate performance measures
    77108      var model = modelCreator.CreateSymbolicClassificationModel(solution, interpreter, lowerEstimationLimit, upperEstimationLimit);
    78109      string positiveClassName = problemData.PositiveClass;
    79110      model.RecalculateModelParameters(problemData, rows);
    80111      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;
    84117      double falsePositiveRate = performanceCalculator.FalsePositiveRate;
    85       double falseNegativeRate = 1 - performanceCalculator.TruePositiveRate;
    86118
    87119      if (applyLinearScaling) {
     
    95127      }
    96128      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    97       return normalizedMeanSquaredErrorWeightingFactor * nmse + betaParameter * falsePositiveRate + gammaParameter * falseNegativeRate;
     129
     130      return normalizedMeanSquaredErrorWeightingFactor * nmse + falseNegativeRateWeightingFactor * falseNegativeRate + falsePositiveRateWeightingFactor * falsePositiveRate;
    98131    }
    99132
     
    105138
    106139      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);
    108141
    109142      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
Note: See TracChangeset for help on using the changeset viewer.