Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1418 Added upper and lower estimation bounds for symbolic classification and regression.

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.Data;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
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      UpdateEstimationLimits();
72    }
73
74    private void InitializeOperators() {
75      Operators.Add(new SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer());
76      Operators.Add(new SymbolicClassificationSingleObjectiveValidationBestSolutionAnalyzer());
77      ParameterizeOperators();
78    }
79
80    private void UpdateEstimationLimits() {
81      if (ProblemData.TrainingPartitionStart.Value < ProblemData.TrainingPartitionEnd.Value) {
82        var targetValues = ProblemData.Dataset.GetVariableValues(ProblemData.TargetVariable, ProblemData.TrainingPartitionStart.Value, ProblemData.TrainingPartitionEnd.Value);
83        var mean = targetValues.Average();
84        var range = targetValues.Max() - targetValues.Min();
85        UpperEstimationLimit.Value = mean + PunishmentFactor * range;
86        LowerEstimationLimit.Value = mean - PunishmentFactor * range;
87      }
88    }
89
90    protected override void OnProblemDataChanged() {
91      base.OnProblemDataChanged();
92      UpdateEstimationLimits();
93    }
94
95    protected override void ParameterizeOperators() {
96      base.ParameterizeOperators();
97      var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
98      foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) {
99        op.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameterName;
100        op.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameterName;
101      }
102    }
103
104    public override void ImportProblemDataFromFile(string fileName) {
105      ClassificationProblemData problemData = ClassificationProblemData.ImportFromFile(fileName);
106      ProblemData = problemData;
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.