Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs @ 11987

Last change on this file since 11987 was 11026, checked in by bburlacu, 10 years ago

#2143:

  • Removed ToArray() calls from SymbolicClassificationPruningOperator.cs and SymbolicRegressionPruningOperator.cs.
  • Changed UpdateCounter, UpdateInterval, PruningProbability, PopulationSliceParameter to FixedValueParameters in SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs.
  • Removed empty operator data member
  • Added parameter descriptions
  • Improved source organization
File size: 3.7 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#endregion
23
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
31  [StorableClass]
32  [Item("SymbolicClassificationPruningOperator", "An operator which prunes symbolic classificaton trees.")]
33  public class SymbolicClassificationPruningOperator : SymbolicDataAnalysisExpressionPruningOperator {
34    private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator";
35    private const string ModelCreatorParameterName = "ModelCreator";
36
37    #region parameter properties
38    public ILookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
39      get { return (ILookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
40    }
41    #endregion
42
43    protected SymbolicClassificationPruningOperator(SymbolicClassificationPruningOperator original, Cloner cloner)
44      : base(original, cloner) {
45    }
46
47    public override IDeepCloneable Clone(Cloner cloner) {
48      return new SymbolicClassificationPruningOperator(this, cloner);
49    }
50
51    [StorableConstructor]
52    protected SymbolicClassificationPruningOperator(bool deserializing) : base(deserializing) { }
53
54    public SymbolicClassificationPruningOperator() {
55      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, new SymbolicClassificationSolutionImpactValuesCalculator()));
56      Parameters.Add(new LookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName));
57    }
58
59    protected override ISymbolicDataAnalysisModel CreateModel() {
60      var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(SymbolicExpressionTree, Interpreter, EstimationLimits.Lower, EstimationLimits.Upper);
61      var problemData = (IClassificationProblemData)ProblemData;
62      var rows = problemData.TrainingIndices;
63      model.RecalculateModelParameters(problemData, rows);
64      return model;
65    }
66
67    protected override double Evaluate(IDataAnalysisModel model) {
68      var classificationModel = (IClassificationModel)model;
69      var classificationProblemData = (IClassificationProblemData)ProblemData;
70      var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size);
71      var estimatedValues = classificationModel.GetEstimatedClassValues(ProblemData.Dataset, trainingIndices);
72      var targetValues = ProblemData.Dataset.GetDoubleValues(classificationProblemData.TargetVariable, trainingIndices);
73      OnlineCalculatorError errorState;
74      var quality = OnlineAccuracyCalculator.Calculate(targetValues, estimatedValues, out errorState);
75      if (errorState != OnlineCalculatorError.None) return double.NaN;
76      return quality;
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.