Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs @ 6784

Last change on this file since 6784 was 5809, checked in by mkommend, 14 years ago

#1418: Reintegrated branch into trunk.

File size: 9.4 KB
RevLine 
[3253]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3253]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;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[4068]30using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers;
[5809]31using HeuristicLab.PluginInfrastructure;
[3253]32
33namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
[4128]34  [Item("Symbolic Regression Problem (single objective)", "Represents a single objective symbolic regression problem.")]
[3253]35  [StorableClass]
[5809]36  [NonDiscoverableType]
[4722]37  public sealed class SymbolicRegressionProblem : SymbolicRegressionProblemBase, ISingleObjectiveDataAnalysisProblem {
[3253]38
39    #region Parameter Properties
40    public ValueParameter<BoolValue> MaximizationParameter {
41      get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
42    }
[5809]43    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
[3253]44      get { return MaximizationParameter; }
45    }
[4036]46    public new ValueParameter<ISymbolicRegressionEvaluator> EvaluatorParameter {
[3253]47      get { return (ValueParameter<ISymbolicRegressionEvaluator>)Parameters["Evaluator"]; }
48    }
[5809]49    IParameter IHeuristicOptimizationProblem.EvaluatorParameter {
[3253]50      get { return EvaluatorParameter; }
51    }
[3452]52    public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
53      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
[3253]54    }
[5809]55    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
[3253]56      get { return BestKnownQualityParameter; }
57    }
58    #endregion
59
60    #region Properties
[4036]61    public new ISymbolicRegressionEvaluator Evaluator {
[3253]62      get { return EvaluatorParameter.Value; }
63      set { EvaluatorParameter.Value = value; }
64    }
[5809]65    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
[3253]66      get { return EvaluatorParameter.Value; }
67    }
[5809]68    IEvaluator IHeuristicOptimizationProblem.Evaluator {
[3253]69      get { return EvaluatorParameter.Value; }
70    }
71    public DoubleValue BestKnownQuality {
72      get { return BestKnownQualityParameter.Value; }
73    }
74    #endregion
75
[4098]76    [StorableConstructor]
[4722]77    private SymbolicRegressionProblem(bool deserializing) : base(deserializing) { }
78    private SymbolicRegressionProblem(SymbolicRegressionProblem original, Cloner cloner)
79      : base(original, cloner) {
80      RegisterParameterEvents();
81      RegisterParameterValueEvents();
82    }
83
[3253]84    public SymbolicRegressionProblem()
85      : base() {
[4250]86      var evaluator = new SymbolicRegressionPearsonsRSquaredEvaluator();
87      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(true)));
[3253]88      Parameters.Add(new ValueParameter<ISymbolicRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
[3452]89      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
[3253]90
[4128]91      InitializeOperators();
[3253]92      ParameterizeEvaluator();
93
[4118]94      RegisterParameterEvents();
95      RegisterParameterValueEvents();
[3253]96    }
97
[3452]98    public override IDeepCloneable Clone(Cloner cloner) {
[4722]99      return new SymbolicRegressionProblem(this, cloner);
[3452]100    }
101
[3545]102    private void RegisterParameterValueEvents() {
103      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
[3269]104    }
105
[4128]106    private void RegisterParameterEvents() { }
[3545]107
108    #region event handling
109    protected override void OnDataAnalysisProblemChanged(EventArgs e) {
110      base.OnDataAnalysisProblemChanged(e);
[3800]111      BestKnownQualityParameter.Value = null;
[3545]112      // paritions could be changed
113      ParameterizeEvaluator();
[3651]114      ParameterizeAnalyzers();
[3480]115    }
[3532]116
[4128]117    protected override void OnSolutionParameterNameChanged(EventArgs e) {
118      base.OnSolutionParameterNameChanged(e);
[3545]119      ParameterizeEvaluator();
[3651]120      ParameterizeAnalyzers();
[3294]121    }
122
[4128]123    protected override void OnEvaluatorChanged(EventArgs e) {
124      base.OnEvaluatorChanged(e);
[3545]125      ParameterizeEvaluator();
[3651]126      ParameterizeAnalyzers();
[5365]127      ParameterizeProblem();
[3545]128      RaiseEvaluatorChanged(e);
129    }
130    #endregion
[3513]131
[3545]132    #region event handlers
133    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
134      OnEvaluatorChanged(e);
135    }
136    #endregion
[3253]137
[3545]138    #region Helpers
[4098]139    [StorableHook(HookType.AfterDeserialization)]
[4118]140    private void AfterDeserializationHook() {
141      // BackwardsCompatibility3.3
142      #region Backwards compatible code (remove with 3.4)
[4128]143      if (Operators == null || Operators.Count() == 0) InitializeOperators();
[4118]144      #endregion
[3545]145      RegisterParameterEvents();
146      RegisterParameterValueEvents();
[3253]147    }
148
149    private void InitializeOperators() {
[4128]150      AddOperator(new FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer());
[5260]151      AddOperator(new SymbolicRegressionOverfittingAnalyzer());
[5331]152      AddOperator(new TrainingBestScaledSymbolicRegressionSolutionAnalyzer());
[3651]153      ParameterizeAnalyzers();
[3253]154    }
155
156    private void ParameterizeEvaluator() {
[3452]157      Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
[3373]158      Evaluator.RegressionProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
[3545]159      Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
160      Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
[3253]161    }
[3545]162
[3651]163    private void ParameterizeAnalyzers() {
164      foreach (var analyzer in Analyzers) {
165        analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
[5260]166        var validationSolutionAnalyzer = analyzer as SymbolicRegressionValidationAnalyzer;
167        if (validationSolutionAnalyzer != null) {
168          validationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
169          validationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
170          validationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
171          validationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
172          validationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
173          validationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
174          validationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
175        }
176
[3996]177        var fixedBestValidationSolutionAnalyzer = analyzer as FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer;
178        if (fixedBestValidationSolutionAnalyzer != null) {
179          fixedBestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
180        }
[4468]181
[4127]182        var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicRegressionSolutionAnalyzer;
[3651]183        if (bestValidationSolutionAnalyzer != null) {
184          bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = DataAnalysisProblemDataParameter.Name;
185          bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
186          bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
187          bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
188          bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
[3806]189          bestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
190          bestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
[3791]191          bestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
[3800]192          bestValidationSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
[3651]193        }
194      }
[3253]195    }
[5365]196
197    private void ParameterizeProblem() {
198      if (MaximizationParameter.Value != null) {
199        MaximizationParameter.Value.Value = Evaluator.Maximization;
200      } else {
201        MaximizationParameter.Value = new BoolValue(Evaluator.Maximization);
202      }
203    }
[3253]204    #endregion
205  }
206}
Note: See TracBrowser for help on using the repository browser.