Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs @ 5685

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

#1418 Implemented validation best solution analyzers for symbolic classification and regression, added analyzers to symbolic data analysis problem classes and changed details of parameter wiring in problem classes.

File size: 5.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21using System.Linq;
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
25using HeuristicLab.Parameters;
26using HeuristicLab.Data;
27
28namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
29  [Item("Symbolic Classification Problem (single objective)", "Represents a single objective symbolic classfication problem.")]
30  [StorableClass]
31  [Creatable("Problems")]
32  public class SymbolicClassificationSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<IClassificationProblemData, ISymbolicClassificationSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator> {
33    private const double PunishmentFactor = 10;
34    private const int InitialMaximumTreeDepth = 8;
35    private const int InitialMaximumTreeLength = 25;
36    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
37    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
38    private const string LowerEstimationLimitParameterDescription = "The lower limit for the estimated value that can be returned by the symbolic classification model.";
39    private const string UpperEstimationLimitParameterDescription = "The upper limit for the estimated value that can be returned by the symbolic classification model.";
40
41    #region parameter properties
42    public IFixedValueParameter<DoubleValue> LowerEstimationLimitParameter {
43      get { return (IFixedValueParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
44    }
45    public IFixedValueParameter<DoubleValue> UpperEstimationLimitParameter {
46      get { return (IFixedValueParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
47    }
48    #endregion
49    #region properties
50    public DoubleValue LowerEstimationLimit {
51      get { return LowerEstimationLimitParameter.Value; }
52    }
53    public DoubleValue UpperEstimationLimit {
54      get { return UpperEstimationLimitParameter.Value; }
55    }
56    #endregion
57    [StorableConstructor]
58    protected SymbolicClassificationSingleObjectiveProblem(bool deserializing) : base(deserializing) { }
59    protected SymbolicClassificationSingleObjectiveProblem(SymbolicClassificationSingleObjectiveProblem original, Cloner cloner) : base(original, cloner) { }
60    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicClassificationSingleObjectiveProblem(this, cloner); }
61
62    public SymbolicClassificationSingleObjectiveProblem()
63      : base(new ClassificationProblemData(), new SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
64      Parameters.Add(new FixedValueParameter<DoubleValue>(LowerEstimationLimitParameterName, LowerEstimationLimitParameterDescription, new DoubleValue()));
65      Parameters.Add(new FixedValueParameter<DoubleValue>(UpperEstimationLimitParameterName, UpperEstimationLimitParameterDescription, new DoubleValue()));
66
67      MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
68      MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
69
70      InitializeOperators();
71    }
72
73    private void InitializeOperators() {
74      Operators.Add(new SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer());
75      Operators.Add(new SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer());
76      ParameterizeOperators();
77    }
78
79    private void UpdateEstimationLimits() {
80      if (ProblemData.TrainingPartitionStart.Value < ProblemData.TrainingPartitionEnd.Value) {
81        var targetValues = ProblemData.Dataset.GetVariableValues(ProblemData.TargetVariable, ProblemData.TrainingPartitionStart.Value, ProblemData.TrainingPartitionEnd.Value);
82        var mean = targetValues.Average();
83        var range = targetValues.Max() - targetValues.Min();
84        UpperEstimationLimit.Value = mean + PunishmentFactor * range;
85        LowerEstimationLimit.Value = mean - PunishmentFactor * range;
86      }
87    }
88
89    protected override void OnProblemDataChanged() {
90      base.OnProblemDataChanged();
91      UpdateEstimationLimits();
92    }
93
94    protected override void ParameterizeOperators() {
95      base.ParameterizeOperators();
96      var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
97      foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedEvaluator<IClassificationProblemData>>()) {
98        op.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameterName;
99        op.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameterName;
100      }
101    }
102
103    public override void ImportProblemDataFromFile(string fileName) {
104      ClassificationProblemData problemData = ClassificationProblemData.ImportFromFile(fileName);
105      ProblemData = problemData;
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.