Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs @ 10486

Last change on this file since 10486 was 10469, checked in by bburlacu, 11 years ago

#2143: Refactored pruning analyzer and operators as per review.

File size: 2.8 KB
Line 
1using System.Linq;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Parameters;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6
7namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
8  [StorableClass]
9  [Item("SymbolicRegressionPruningOperator", "An operator which prunes symbolic regression trees.")]
10  public class SymbolicRegressionPruningOperator : SymbolicDataAnalysisExpressionPruningOperator {
11    private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator";
12    private const string ImpactValuesCalculatorParameterDescription = "The impact values calculator to be used for figuring out the node impacts.";
13
14    private const string EvaluatorParameterName = "Evaluator";
15
16    public ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
17      get { return (ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
18    }
19
20    protected SymbolicRegressionPruningOperator(SymbolicRegressionPruningOperator original, Cloner cloner)
21      : base(original, cloner) {
22    }
23    public override IDeepCloneable Clone(Cloner cloner) {
24      return new SymbolicRegressionPruningOperator(this, cloner);
25    }
26
27    [StorableConstructor]
28    protected SymbolicRegressionPruningOperator(bool deserializing) : base(deserializing) { }
29
30    public SymbolicRegressionPruningOperator() {
31      var impactValuesCalculator = new SymbolicRegressionSolutionImpactValuesCalculator();
32      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, ImpactValuesCalculatorParameterDescription, impactValuesCalculator));
33      Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
34    }
35
36    protected override ISymbolicDataAnalysisModel CreateModel() {
37      return new SymbolicRegressionModel(SymbolicExpressionTree, Interpreter, EstimationLimits.Lower, EstimationLimits.Upper);
38    }
39
40    protected override double Evaluate(IDataAnalysisModel model) {
41      var regressionModel = (IRegressionModel)model;
42      var regressionProblemData = (IRegressionProblemData)ProblemData;
43      var trainingIndices = ProblemData.TrainingIndices.ToList();
44      var estimatedValues = regressionModel.GetEstimatedValues(ProblemData.Dataset, trainingIndices); // also bounds the values
45      var targetValues = ProblemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, trainingIndices);
46      OnlineCalculatorError errorState;
47      var quality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);
48      if (errorState != OnlineCalculatorError.None) return double.NaN;
49      return quality;
50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.