Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/19 11:43:52 (5 years ago)
Author:
mkommend
Message:

#2361: Merged all changes from the sensitivity branch to trunk.

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  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    2829using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2930using HeuristicLab.Parameters;
    30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.PluginInfrastructure;
    3132
    32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.SingleObjective {
     33namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     34  [NonDiscoverableType]
    3335  [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   [StorableClass]
     36  [StorableType("0772F316-5E12-4153-857E-8625069B4677")]
    3537  public class SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator : SymbolicClassificationSingleObjectiveEvaluator {
    3638    private const string NormalizedMeanSquaredErrorWeightingFactorParameterName = "NormalizedMeanSquaredErrorWeightingFactor";
     
    5759
    5860    public double NormalizedMeanSquaredErrorWeightingFactor {
    59       get {
    60         return NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value;
    61       }
     61      get { return NormalizedMeanSquaredErrorWeightingFactorParameter.Value.Value; }
    6262    }
    6363    public double FalseNegativeRateWeightingFactor {
    64       get {
    65         return FalseNegativeRateWeightingFactorParameter.Value.Value;
    66       }
     64      get { return FalseNegativeRateWeightingFactorParameter.Value.Value; }
    6765    }
    6866    public double FalsePositiveRateWeightingFactor {
    69       get {
    70         return FalsePositiveRateWeightingFactorParameter.Value.Value;
    71       }
     67      get { return FalsePositiveRateWeightingFactorParameter.Value.Value; }
    7268    }
    7369
    7470    [StorableConstructor]
    75     protected SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(bool deserializing) : base(deserializing) { }
     71    protected SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(StorableConstructorFlag _) : base(_) { }
    7672    protected SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator original, Cloner cloner)
    7773      : base(original, cloner) {
     
    7975    public override IDeepCloneable Clone(Cloner cloner) {
    8076      return new SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator(this, cloner);
    81     }
    82 
    83     [StorableHook(HookType.AfterDeserialization)]
    84     private void AfterDeserialization() {
    85       // BackwardsCompatibility
    86       #region Backwards compatible code
    87       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       #endregion
    9277    }
    9378
     
    10287    public override IOperation InstrumentedApply() {
    10388      IEnumerable<int> rows = GenerateRowsToEvaluate();
    104       var solution = SymbolicExpressionTreeParameter.ActualValue;
     89      var tree = SymbolicExpressionTreeParameter.ActualValue;
    10590      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);
    10898      QualityParameter.ActualValue = new DoubleValue(quality);
    10999      return base.InstrumentedApply();
    110100    }
    111101
    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,
    113103                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);
    115105      var targetClassValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    116106      var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit).ToArray();
     
    124114      ISymbolicDiscriminantFunctionClassificationModel m;
    125115
    126       var model = modelCreator.CreateSymbolicClassificationModel(solution, interpreter, lowerEstimationLimit, upperEstimationLimit);
     116      var model = modelCreator.CreateSymbolicClassificationModel(problemData.TargetVariable, tree, interpreter, lowerEstimationLimit, upperEstimationLimit);
    127117      if ((m = model as ISymbolicDiscriminantFunctionClassificationModel) != null) {
    128118        m.ThresholdCalculator.Calculate(problemData, boundedEstimatedValues, targetClassValues, out classValues, out thresholds);
     
    133123        estimatedClassValues = model.GetEstimatedClassValues(problemData.Dataset, rows);
    134124      }
     125
    135126      var performanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, problemData.GetClassValue(positiveClassName));
    136127      performanceCalculator.Calculate(targetClassValues, estimatedClassValues);
Note: See TracChangeset for help on using the changeset viewer.