Free cookie consent management tool by TermsFeed Policy Generator

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

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

Location:
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj

    r16658 r16788  
    126126    <Compile Include="ModelCreators\NormalDistributedThresholdsModelCreator.cs" />
    127127    <Compile Include="MultiObjective\SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs" />
     128    <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveWeightedPerformanceMeasuresEvaluator.cs" />
     129    <Compile Include="SingleObjective\SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator.cs" />
    128130    <Compile Include="SymbolicClassificationPhenotypicDiversityAnalyzer.cs" />
    129131    <Compile Include="SymbolicClassificationPruningAnalyzer.cs" />
  • 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);
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator.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
    3233namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     34  [NonDiscoverableType]
    3335  [Item("Weighted Residuals Mean Squared Error Evaluator", @"A modified mean squared error evaluator that enables the possibility to weight residuals differently.
    3436The 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).
     
    3638All other cases are represented by the third category (NegativeClassesResidualsWeight).
    3739The 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   [StorableClass]
    39   public class SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator : SymbolicClassificationSingleObjectiveEvaluator {
     40  [StorableType("A3193296-1A0F-46E2-8F43-22E2ED9CFFC5")]
     41  public sealed class SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator : SymbolicClassificationSingleObjectiveEvaluator {
    4042    private const string DefiniteResidualsWeightParameterName = "DefiniteResidualsWeight";
    4143    private const string PositiveClassResidualsWeightParameterName = "PositiveClassResidualsWeight";
    4244    private const string NegativeClassesResidualsWeightParameterName = "NegativeClassesResidualsWeight";
    4345    [StorableConstructor]
    44     protected SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { }
    45     protected SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator(SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator original, Cloner cloner)
     46    private SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator(StorableConstructorFlag _) : base(_) { }
     47    private SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator(SymbolicClassificationSingleObjectiveWeightedResidualsMeanSquaredErrorEvaluator original, Cloner cloner)
    4648      : base(original, cloner) {
    4749    }
     
    7375
    7476    public double DefiniteResidualsWeight {
    75       get {
    76         return DefiniteResidualsWeightParameter.Value.Value;
    77       }
     77      get { return DefiniteResidualsWeightParameter.Value.Value; }
    7878    }
    7979    public double PositiveClassResidualsWeight {
    80       get {
    81         return PositiveClassResidualsWeightParameter.Value.Value;
    82       }
     80      get { return PositiveClassResidualsWeightParameter.Value.Value; }
    8381    }
    8482    public double NegativeClassesResidualsWeight {
    85       get {
    86         return NegativeClassesResidualsWeightParameter.Value.Value;
    87       }
     83      get { return NegativeClassesResidualsWeightParameter.Value.Value; }
    8884    }
    8985    #endregion
     
    9894    }
    9995
    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,
    10197      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);
    10399      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    104100      OnlineCalculatorError errorState;
     
    115111      double quality;
    116112      if (applyLinearScaling) {
    117         var calculator = new OnlineWeightedResidualsMeanSquaredErrorCalculator(positiveClassValue, classValuesMax, classValuesMin,
     113        var calculator = new OnlineWeightedClassificationMeanSquaredErrorCalculator(positiveClassValue, classValuesMax, classValuesMin,
    118114          definiteResidualsWeight, positiveClassResidualsWeight, negativeClassesResidualsWeight);
    119115        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, calculator, problemData.Dataset.Rows);
     
    122118      } else {
    123119        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    124         quality = OnlineWeightedResidualsMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, positiveClassValue, classValuesMax,
     120        quality = OnlineWeightedClassificationMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, positiveClassValue, classValuesMax,
    125121          classValuesMin, definiteResidualsWeight, positiveClassResidualsWeight, negativeClassesResidualsWeight, out errorState);
    126122      }
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs

    r16565 r16788  
    112112
    113113    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) {
    114118      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) {
    116120        int classIndex = 0;
    117121        // find first threshold value which is larger than x => class index = threshold index + 1
     
    123127      }
    124128    }
    125 
    126129
    127130    public override ISymbolicClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
Note: See TracChangeset for help on using the changeset viewer.