Free cookie consent management tool by TermsFeed Policy Generator

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

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

Added new plugins for multi-variate regression. #1089

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