Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs @ 11586

Last change on this file since 11586 was 10681, checked in by mkommend, 11 years ago

#1837: Corrected project files and merged trunk changes to the sliding window branch.

File size: 3.4 KB
Line 
1using System.Linq;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Parameters;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7
8namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
9  [StorableClass]
10  [Item("SymbolicClassificationPruningOperator", "An operator which prunes symbolic classificaton trees.")]
11  public class SymbolicClassificationPruningOperator : SymbolicDataAnalysisExpressionPruningOperator {
12    private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator";
13    private const string ModelCreatorParameterName = "ModelCreator";
14    private const string ApplyLinearScalingParmameterName = "ApplyLinearScaling";
15
16    #region parameter properties
17    public ILookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
18      get { return (ILookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
19    }
20
21    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
22      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParmameterName]; }
23    }
24    #endregion
25    #region properties
26    private ISymbolicClassificationModelCreator ModelCreator { get { return ModelCreatorParameter.ActualValue; } }
27    private BoolValue ApplyLinearScaling { get { return ApplyLinearScalingParameter.ActualValue; } }
28    #endregion
29
30    protected SymbolicClassificationPruningOperator(SymbolicClassificationPruningOperator
31      original, Cloner cloner)
32      : base(original, cloner) {
33    }
34    public override IDeepCloneable Clone(Cloner cloner) {
35      return new SymbolicClassificationPruningOperator(this, cloner);
36    }
37
38    [StorableConstructor]
39    protected SymbolicClassificationPruningOperator(bool deserializing) : base(deserializing) { }
40
41    public SymbolicClassificationPruningOperator() {
42      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, new SymbolicClassificationSolutionImpactValuesCalculator()));
43      Parameters.Add(new LookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName));
44    }
45
46    protected override ISymbolicDataAnalysisModel CreateModel() {
47      var model = ModelCreator.CreateSymbolicClassificationModel(SymbolicExpressionTree, Interpreter, EstimationLimits.Lower, EstimationLimits.Upper);
48      var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
49      var problemData = (IClassificationProblemData)ProblemData;
50      model.RecalculateModelParameters(problemData, rows);
51      return model;
52    }
53
54    protected override double Evaluate(IDataAnalysisModel model) {
55      var classificationModel = (IClassificationModel)model;
56      var classificationProblemData = (IClassificationProblemData)ProblemData;
57      var trainingIndices = ProblemData.TrainingIndices.ToList();
58      var estimatedValues = classificationModel.GetEstimatedClassValues(ProblemData.Dataset, trainingIndices);
59      var targetValues = ProblemData.Dataset.GetDoubleValues(classificationProblemData.TargetVariable, trainingIndices);
60      OnlineCalculatorError errorState;
61      var quality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);
62      if (errorState != OnlineCalculatorError.None) return double.NaN;
63      return quality;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.