Free cookie consent management tool by TermsFeed Policy Generator

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

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

worked on data analysis feature exploration branch. #1142

File size: 8.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 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    protected SingleObjectiveSymbolicTimeSeriesPrognosisProblem(SingleObjectiveSymbolicTimeSeriesPrognosisProblem original, Cloner cloner)
90      : base(original, cloner) {
91        AttachEventHandlers();
92    }
93    public SingleObjectiveSymbolicTimeSeriesPrognosisProblem()
94      : base() {
95      var evaluator = new SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator();
96      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()));
97      Parameters.Add(new ValueParameter<ISingleObjectiveSymbolicTimeSeriesPrognosisEvaluator>("Evaluator", "The operator which should be used to evaluate symbolic time series prognosis solutions.", evaluator));
98      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The minimal error value that reached by symbolic time series prognosis solutions for the problem."));
99      evaluator.QualityParameter.ActualName = "TrainingMeanSquaredError";
100
101      ParameterizeEvaluator();
102
103      InitializeOperators();
104      AttachEventHandlers();
105    }
106
107    [StorableHook(HookType.AfterDeserialization)]
108    private void AfterDeserialization() {
109      AttachEventHandlers();
110    }
111
112    public override IDeepCloneable Clone(Cloner cloner) {
113      return new SingleObjectiveSymbolicTimeSeriesPrognosisProblem(this, cloner);
114    }
115
116    #region event handling
117    protected override void OnMultiVariateDataAnalysisProblemChanged(EventArgs e) {
118      base.OnMultiVariateDataAnalysisProblemChanged(e);
119      BestKnownQualityParameter.Value = null;
120      // paritions could be changed
121      ParameterizeEvaluator();
122      ParameterizeAnalyzers();
123    }
124
125    protected override void OnSolutionParameterNameChanged(EventArgs e) {
126      ParameterizeEvaluator();
127      ParameterizeAnalyzers();
128    }
129
130    protected virtual void OnEvaluatorChanged(EventArgs e) {
131      ParameterizeEvaluator();
132      ParameterizeAnalyzers();
133      RaiseEvaluatorChanged(e);
134    }
135    #endregion
136
137    #region Helpers
138    private void AttachEventHandlers() {
139    }
140
141    private void InitializeOperators() {
142      AddOperator(new ValidationBestScaledSymbolicTimeSeriesPrognosisSolutionAnalyzer());
143      ParameterizeAnalyzers();
144    }
145
146    private void ParameterizeEvaluator() {
147      Evaluator.TimeSeriesPrognosisModelParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
148      Evaluator.TimeSeriesExpressionInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
149      Evaluator.ProblemDataParameter.ActualName = MultiVariateDataAnalysisProblemDataParameter.Name;
150      Evaluator.PredictionHorizonParameter.ActualName = PredictionHorizonParameter.Name;
151      Evaluator.SamplesStartParameter.Value = TrainingSamplesStart;
152      Evaluator.SamplesEndParameter.Value = TrainingSamplesEnd;
153    }
154
155    private void ParameterizeAnalyzers() {
156      foreach (var analyzer in Analyzers) {
157        var bestValidationSolutionAnalyzer = analyzer as ValidationBestScaledSymbolicTimeSeriesPrognosisSolutionAnalyzer;
158        if (bestValidationSolutionAnalyzer != null) {
159          bestValidationSolutionAnalyzer.ProblemDataParameter.ActualName = MultiVariateDataAnalysisProblemDataParameter.Name;
160          bestValidationSolutionAnalyzer.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
161          bestValidationSolutionAnalyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
162          bestValidationSolutionAnalyzer.ValidationSamplesStartParameter.Value = ValidationSamplesStart;
163          bestValidationSolutionAnalyzer.ValidationSamplesEndParameter.Value = ValidationSamplesEnd;
164          bestValidationSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
165          bestValidationSolutionAnalyzer.ValidationPredictionHorizonParameter.ActualName = PredictionHorizonParameter.Name;
166          bestValidationSolutionAnalyzer.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
167          bestValidationSolutionAnalyzer.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
168        }
169      }
170      foreach (ISymbolicExpressionTreeAnalyzer analyzer in Operators.OfType<ISymbolicExpressionTreeAnalyzer>()) {
171        analyzer.SymbolicExpressionTreeParameter.ActualName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
172      }
173    }
174    #endregion
175  }
176}
Note: See TracBrowser for help on using the repository browser.