Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs @ 5846

Last change on this file since 5846 was 5846, checked in by gkronber, 13 years ago

#1453: changed *RSquaredEvaluators to return 0.0 (worst possible value) if the result returned by the OnlinePearsonsRSquaredEvaluator is double.NaN

File size: 3.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Data;
6using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
10  [Item("Pearson R² & Tree size Evaluator", "Calculates the Pearson R² and the tree size of a symbolic classification solution.")]
11  [StorableClass]
12  public class SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator : SymbolicClassificationMultiObjectiveEvaluator {
13    [StorableConstructor]
14    protected SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator(bool deserializing) : base(deserializing) { }
15    protected SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator(SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator original, Cloner cloner)
16      : base(original, cloner) {
17    }
18    public override IDeepCloneable Clone(Cloner cloner) {
19      return new SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator(this, cloner);
20    }
21
22    public SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator() : base() { }
23
24    public override IEnumerable<bool> Maximization { get { return new bool[2] { true, false }; } }
25
26    public override IOperation Apply() {
27      IEnumerable<int> rows = GenerateRowsToEvaluate();
28      double[] qualities = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, SymbolicExpressionTreeParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
29      QualitiesParameter.ActualValue = new DoubleArray(qualities);
30      return base.Apply();
31    }
32
33    public static double[] Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IClassificationProblemData problemData, IEnumerable<int> rows) {
34      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
35      IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows);
36      double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues);
37      return new double[] { double.IsNaN(r2) ? 0.0 : r2, solution.Length };
38    }
39
40    public override double[] Evaluate(IExecutionContext context, ISymbolicExpressionTree tree, IClassificationProblemData problemData, IEnumerable<int> rows) {
41      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
42      EstimationLimitsParameter.ExecutionContext = context;
43
44      double[] quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
45
46      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
47      EstimationLimitsParameter.ExecutionContext = null;
48
49      return quality;
50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.