Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Symbolic/SingleObjectiveSymbolicTimeSeriesPrognosisProblem.cs @ 4235

Last change on this file since 4235 was 4118, checked in by abeham, 14 years ago

#1090

  • Fixed problem plugins reloading their operators on deserialization in following problems (forgot on them in the first commit)
    • SupportVectorRegressionProblem
    • SymbolicTimeSeriesPrognosisProblem
  • Fixed a bug in the FeatureSelectionProblem introduced in r4098
  • Fixed the issues mentioned in the code review of mkommend
File size: 8.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 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.Symbolic;
34using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators;
35using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
36using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
37using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
38using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
39using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers;
40using HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic.Evaluators;
41using HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic.Analyzers;
42using HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic.Interfaces;
43
44namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic {
45  [Item("Symbolic Time Series Prognosis Problem", "Represents a symbolic time series prognosis problem.")]
46  [Creatable("Problems")]
47  [StorableClass]
48  public class SingleObjectiveSymbolicTimeSeriesPrognosisProblem : SymbolicTimeSeriesPrognosisProblem, ISingleObjectiveProblem {
49
50    #region Parameter Properties
51    public ValueParameter<ISingleObjectiveSymbolicTimeSeriesPrognosisEvaluator> EvaluatorParameter {
52      get { return (ValueParameter<ISingleObjectiveSymbolicTimeSeriesPrognosisEvaluator>)Parameters["Evaluator"]; }
53    }
54    IParameter IProblem.EvaluatorParameter {
55      get { return EvaluatorParameter; }
56    }
57    public ValueParameter<BoolValue> MaximizationParameter {
58      get { return (ValueParameter<BoolValue>)Parameters["Maximization"]; }
59    }
60    IParameter ISingleObjectiveProblem.MaximizationParameter {
61      get { return MaximizationParameter; }
62    }
63    public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
64      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
65    }
66    IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
67      get { return BestKnownQualityParameter; }
68    }
69
70    #endregion
71
72    #region Properties
73    public ISingleObjectiveSymbolicTimeSeriesPrognosisEvaluator Evaluator {
74      get { return EvaluatorParameter.Value; }
75    }
76    ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
77      get { return Evaluator; }
78    }
79    IEvaluator IProblem.Evaluator {
80      get { return Evaluator; }
81    }
82    public DoubleValue BestKnownQuality {
83      get { return BestKnownQualityParameter.Value; }
84    }
85    #endregion
86
87    [StorableConstructor]
88    protected SingleObjectiveSymbolicTimeSeriesPrognosisProblem(bool deserializing) : base(deserializing) { }
89    public SingleObjectiveSymbolicTimeSeriesPrognosisProblem()
90      : base() {
91      var evaluator = new SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator();
92      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as the error of the time series prognosis model should be minimized.", (BoolValue)new BoolValue(false).AsReadOnly()));
93      Parameters.Add(new ValueParameter<ISingleObjectiveSymbolicTimeSeriesPrognosisEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic time series prognosis solutions.", evaluator));
94      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic time series prognosis solutions for the problem."));
95      evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError";
96
97      ParameterizeEvaluator();
98
99      InitializeOperators();
100      AttachEventHandlers();
101    }
102
103    [StorableHook(HookType.AfterDeserialization)]
104    private void AfterDeserializationHook() {
105      AttachEventHandlers();
106    }
107
108    public override IDeepCloneable Clone(Cloner cloner) {
109      SingleObjectiveSymbolicTimeSeriesPrognosisProblem clone = (SingleObjectiveSymbolicTimeSeriesPrognosisProblem)base.Clone(cloner);
110      clone.AttachEventHandlers();
111      return clone;
112    }
113
114    #region event handling
115    protected override void OnMultiVariateDataAnalysisProblemChanged(EventArgs e) {
116      base.OnMultiVariateDataAnalysisProblemChanged(e);
117      BestKnownQualityParameter.Value = null;
118      // paritions could be changed
119      ParameterizeEvaluator();
120      ParameterizeAnalyzers();
121    }
122
123    protected override void OnSolutionParameterNameChanged(EventArgs e) {
124      ParameterizeEvaluator();
125      ParameterizeAnalyzers();
126    }
127
128    protected virtual void OnEvaluatorChanged(EventArgs e) {
129      ParameterizeEvaluator();
130      ParameterizeAnalyzers();
131      RaiseEvaluatorChanged(e);
132    }
133    #endregion
134
135    #region Helpers
136    private void AttachEventHandlers() {
137    }
138
139    private void InitializeOperators() {
140      AddOperator(new ValidationBestScaledSymbolicTimeSeriesPrognosisSolutionAnalyzer());
141      ParameterizeAnalyzers();
142    }
143
144    private void ParameterizeEvaluator() {
145      Evaluator.TimeSeriesPrognosisModelParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
146      Evaluator.TimeSeriesExpressionInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
147      Evaluator.ProblemDataParameter.ActualName = MultiVariateDataAnalysisProblemDataParameter.Name;
148      Evaluator.PredictionHorizonParameter.ActualName = PredictionHorizonParameter.Name;
149      Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
150      Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
151    }
152
153    private void ParameterizeAnalyzers() {
154      foreach (var analyzer in Analyzers) {
155        var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicTimeSeriesPrognosisSolutionAnalyzer;
156        if (bestValidationSolutionAnalyzer != null) {
157          bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = MultiVariateDataAnalysisProblemDataParameter.Name;
158          bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
159          bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
160          bestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
161          bestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
162          bestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
163          bestValidationSolutionAnalyzer.PredictionHorizonParameter.ActualName = PredictionHorizonParameter.Name;
164          bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
165          bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
166        }
167      }
168      foreach (ISymbolicExpressionTreeAnalyzer analyzer in Operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
169        analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
170      }
171    }
172    #endregion
173  }
174}
Note: See TracBrowser for help on using the repository browser.