Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/SingleObjectiveSymbolicVectorRegressionProblem.cs @ 4128

Last change on this file since 4128 was 4087, checked in by gkronber, 14 years ago

Fixed bugs in symbolic vector regression operators. #1089

File size: 7.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Analyzers;
30using HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Evaluators;
31using HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Interfaces;
32
33namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic {
34  [Item("Symbolic Vector Regression Problem", "Represents a symbolic vector regression problem.")]
35  [Creatable("Problems")]
36  [StorableClass]
37  public class SingleObjectiveSymbolicVectorRegressionProblem : SymbolicVectorRegressionProblem, ISingleObjectiveProblem {
38
39    #region Parameter Properties
40    public ValueParameter<BoolValue> MaximizationParameter {
41      get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
42    }
43    IParameter ISingleObjectiveProblem.MaximizationParameter {
44      get { return MaximizationParameter; }
45    }
46    public new ValueParameter<ISingleObjectiveSymbolicVectorRegressionEvaluator> EvaluatorParameter {
47      get { return (ValueParameter<ISingleObjectiveSymbolicVectorRegressionEvaluator>)Parameters["Evaluator"]; }
48    }
49    IParameter IProblem.EvaluatorParameter {
50      get { return EvaluatorParameter; }
51    }
52
53    public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
54      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
55    }
56    IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
57      get { return BestKnownQualityParameter; }
58    }
59    #endregion
60
61    #region Properties
62    public new ISingleObjectiveSymbolicVectorRegressionEvaluator Evaluator {
63      get { return EvaluatorParameter.Value; }
64      set { EvaluatorParameter.Value = value; }
65    }
66    ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
67      get { return EvaluatorParameter.Value; }
68    }
69    IEvaluator IProblem.Evaluator {
70      get { return EvaluatorParameter.Value; }
71    }
72    public DoubleValue BestKnownQuality {
73      get { return BestKnownQualityParameter.Value; }
74    }
75    #endregion
76
77    public SingleObjectiveSymbolicVectorRegressionProblem()
78      : base() {
79      var evaluator = new SymbolicVectorRegressionScaledNormalizedMseEvaluator();
80      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(false).AsReadOnly()));
81      Parameters.Add(new ValueParameter<ISingleObjectiveSymbolicVectorRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
82      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
83
84      ParameterizeEvaluator();
85
86      Initialize();
87    }
88
89    [StorableConstructor]
90    private SingleObjectiveSymbolicVectorRegressionProblem(bool deserializing) : base() { }
91
92    [StorableHook(HookType.AfterDeserialization)]
93    private void AfterDeserializationHook() {
94      Initialize();
95    }
96
97    public override IDeepCloneable Clone(Cloner cloner) {
98      SingleObjectiveSymbolicVectorRegressionProblem clone = (SingleObjectiveSymbolicVectorRegressionProblem)base.Clone(cloner);
99      clone.Initialize();
100      return clone;
101    }
102
103    private void RegisterParameterValueEvents() {
104      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
105    }
106
107    #region event handling
108    protected override void OnMultiVariateDataAnalysisProblemChanged(EventArgs e) {
109      base.OnMultiVariateDataAnalysisProblemChanged(e);
110      BestKnownQualityParameter.Value = null;
111      // paritions could be changed
112      ParameterizeEvaluator();
113      ParameterizeAnalyzers();
114    }
115
116    protected override void OnSolutionParameterNameChanged(EventArgs e) {
117      ParameterizeEvaluator();
118    }
119
120    protected virtual void OnEvaluatorChanged(EventArgs e) {
121      ParameterizeEvaluator();
122      ParameterizeAnalyzers();
123      RaiseEvaluatorChanged(e);
124    }
125    #endregion
126
127    #region event handlers
128    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
129      OnEvaluatorChanged(e);
130    }
131    #endregion
132
133    #region Helpers
134    private void Initialize() {
135      InitializeOperators();
136      RegisterParameterValueEvents();
137    }
138
139    private void InitializeOperators() {
140      AddOperator(new ValidationBestScaledSymbolicVectorRegressionSolutionAnalyzer());
141      ParameterizeAnalyzers();
142    }
143
144    private void ParameterizeEvaluator() {
145      Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
146      Evaluator.MultiVariateDataAnalysisProblemDataParameter.ActualName = MultiVariateDataAnalysisProblemDataParameter.Name;
147      Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
148      Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
149    }
150
151    private void ParameterizeAnalyzers() {
152      foreach (var analyzer in Analyzers) {
153        var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicVectorRegressionSolutionAnalyzer;
154        if (bestValidationSolutionAnalyzer != null) {
155          bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = MultiVariateDataAnalysisProblemDataParameter.Name;
156          bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
157          bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
158          bestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
159          bestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
160          bestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
161          bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
162          bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
163        }
164      }
165    }
166    #endregion
167  }
168}
Note: See TracBrowser for help on using the repository browser.