Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/SingleObjectiveSymbolicVectorRegressionProblem.cs @ 11301

Last change on this file since 11301 was 5275, checked in by gkronber, 14 years ago

Merged changes from trunk to data analysis exploration branch and added fractional distance metric evaluator. #1142

File size: 7.4 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    [StorableConstructor]
78    private SingleObjectiveSymbolicVectorRegressionProblem(bool deserializing) : base() { }
79    private SingleObjectiveSymbolicVectorRegressionProblem(SingleObjectiveSymbolicVectorRegressionProblem original, Cloner cloner)
80      : base(original, cloner) {
81        Initialize();
82    }
83    public SingleObjectiveSymbolicVectorRegressionProblem()
84      : base() {
85      var evaluator = new SymbolicVectorRegressionScaledNormalizedMseEvaluator();
86      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the regression model should be minimized.", (BoolValue)new BoolValue(false).AsReadOnly()));
87      Parameters.Add(new ValueParameter<ISingleObjectiveSymbolicVectorRegressionEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic regression solutions.", evaluator));
88      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic regression solutions for the problem."));
89
90      ParameterizeEvaluator();
91
92      Initialize();
93    }
94
95
96    [StorableHook(HookType.AfterDeserialization)]
97    private void AfterDeserialization() {
98      Initialize();
99    }
100
101    public override IDeepCloneable Clone(Cloner cloner) {
102      return new SingleObjectiveSymbolicVectorRegressionProblem(this, cloner);
103    }
104    private void RegisterParameterValueEvents() {
105      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
106    }
107
108    #region event handling
109    protected override void OnMultiVariateDataAnalysisProblemChanged(EventArgs e) {
110      base.OnMultiVariateDataAnalysisProblemChanged(e);
111      BestKnownQualityParameter.Value = null;
112      // paritions could be changed
113      ParameterizeEvaluator();
114      ParameterizeAnalyzers();
115    }
116
117    protected override void OnSolutionParameterNameChanged(EventArgs e) {
118      ParameterizeEvaluator();
119    }
120
121    protected virtual void OnEvaluatorChanged(EventArgs e) {
122      ParameterizeEvaluator();
123      ParameterizeAnalyzers();
124      RaiseEvaluatorChanged(e);
125    }
126    #endregion
127
128    #region event handlers
129    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
130      OnEvaluatorChanged(e);
131    }
132    #endregion
133
134    #region Helpers
135    private void Initialize() {
136      InitializeOperators();
137      RegisterParameterValueEvents();
138    }
139
140    private void InitializeOperators() {
141      AddOperator(new ValidationBestScaledSymbolicVectorRegressionSolutionAnalyzer());
142      ParameterizeAnalyzers();
143    }
144
145    private void ParameterizeEvaluator() {
146      Evaluator.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
147      Evaluator.MultiVariateDataAnalysisProblemDataParameter.ActualName = MultiVariateDataAnalysisProblemDataParameter.Name;
148      Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
149      Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
150    }
151
152    private void ParameterizeAnalyzers() {
153      foreach (var analyzer in Analyzers) {
154        var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicVectorRegressionSolutionAnalyzer;
155        if (bestValidationSolutionAnalyzer != null) {
156          bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = MultiVariateDataAnalysisProblemDataParameter.Name;
157          bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
158          bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
159          bestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
160          bestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
161          bestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
162          bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
163          bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
164        }
165      }
166    }
167    #endregion
168  }
169}
Note: See TracBrowser for help on using the repository browser.