Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs @ 5618

Last change on this file since 5618 was 5618, checked in by mkommend, 14 years ago

#1418: Added symbolic data analysis problems.

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