Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveProblem.cs @ 7810

Last change on this file since 7810 was 7810, checked in by sforsten, 12 years ago

#1784:

  • removed obsolete import & export methods from RegressionProblem and ClassificationProblem, because they are implemented in the base classes
  • removed unnecessary references in Problems.QuadraticAssignment.Views
File size: 5.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
21
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Problems.Instances;
29
30namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
31  [Item("Symbolic Regression Problem (multi objective)", "Represents a multi objective symbolic regression problem.")]
32  [StorableClass]
33  [Creatable("Problems")]
34  public class SymbolicRegressionMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IRegressionProblemData, ISymbolicRegressionMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IRegressionProblem,
35    IProblemInstanceConsumer<IRegressionProblemData>, IProblemInstanceExporter<IRegressionProblemData> {
36    private const double PunishmentFactor = 10;
37    private const int InitialMaximumTreeDepth = 8;
38    private const int InitialMaximumTreeLength = 25;
39    private const string EstimationLimitsParameterName = "EstimationLimits";
40    private const string EstimationLimitsParameterDescription = "The lower and upper limit for the estimated value that can be returned by the symbolic regression model.";
41
42    #region parameter properties
43    public IFixedValueParameter<DoubleLimit> EstimationLimitsParameter {
44      get { return (IFixedValueParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
45    }
46    #endregion
47
48    #region properties
49    public DoubleLimit EstimationLimits {
50      get { return EstimationLimitsParameter.Value; }
51    }
52
53    #endregion
54
55    [StorableConstructor]
56    protected SymbolicRegressionMultiObjectiveProblem(bool deserializing) : base(deserializing) { }
57    protected SymbolicRegressionMultiObjectiveProblem(SymbolicRegressionMultiObjectiveProblem original, Cloner cloner) : base(original, cloner) { }
58    public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicRegressionMultiObjectiveProblem(this, cloner); }
59
60    public SymbolicRegressionMultiObjectiveProblem()
61      : base(new RegressionProblemData(), new SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
62      Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription));
63
64      EstimationLimitsParameter.Hidden = true;
65
66      Maximization = new BoolArray(new bool[] { true, false });
67      MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
68      MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
69
70      SymbolicExpressionTreeGrammarParameter.ValueChanged += (o, e) => ConfigureGrammarSymbols();
71
72      ConfigureGrammarSymbols();
73      InitializeOperators();
74      UpdateEstimationLimits();
75    }
76
77    private void ConfigureGrammarSymbols() {
78      var grammar = SymbolicExpressionTreeGrammar as TypeCoherentExpressionGrammar;
79      if (grammar != null) grammar.ConfigureAsDefaultRegressionGrammar();
80    }
81
82    private void InitializeOperators() {
83      Operators.Add(new SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer());
84      Operators.Add(new SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer());
85      ParameterizeOperators();
86    }
87
88    private void UpdateEstimationLimits() {
89      if (ProblemData.TrainingIndizes.Any()) {
90        var targetValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).ToList();
91        var mean = targetValues.Average();
92        var range = targetValues.Max() - targetValues.Min();
93        EstimationLimits.Upper = mean + PunishmentFactor * range;
94        EstimationLimits.Lower = mean - PunishmentFactor * range;
95      } else {
96        EstimationLimits.Upper = double.MaxValue;
97        EstimationLimits.Lower = double.MinValue;
98      }
99    }
100
101    protected override void OnProblemDataChanged() {
102      base.OnProblemDataChanged();
103      UpdateEstimationLimits();
104    }
105
106    protected override void ParameterizeOperators() {
107      base.ParameterizeOperators();
108      if (Parameters.ContainsKey(EstimationLimitsParameterName)) {
109        var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
110        foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) {
111          op.EstimationLimitsParameter.ActualName = EstimationLimitsParameter.Name;
112        }
113      }
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.