[4113] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 31 | using HeuristicLab.PluginInfrastructure;
|
---|
| 32 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 33 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
| 34 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureManipulators;
|
---|
| 35 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Manipulators;
|
---|
| 36 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Crossovers;
|
---|
| 37 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Creators;
|
---|
| 38 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;
|
---|
| 39 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Analyzers;
|
---|
| 40 | using HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic.Evaluators;
|
---|
| 41 | using HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic.Analyzers;
|
---|
| 42 | using HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic.Interfaces;
|
---|
| 43 |
|
---|
| 44 | namespace 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 |
|
---|
[4118] | 87 | [StorableConstructor]
|
---|
| 88 | protected SingleObjectiveSymbolicTimeSeriesPrognosisProblem(bool deserializing) : base(deserializing) { }
|
---|
[5275] | 89 | protected SingleObjectiveSymbolicTimeSeriesPrognosisProblem(SingleObjectiveSymbolicTimeSeriesPrognosisProblem original, Cloner cloner)
|
---|
| 90 | : base(original, cloner) {
|
---|
| 91 | AttachEventHandlers();
|
---|
| 92 | }
|
---|
[4113] | 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 |
|
---|
[4118] | 103 | InitializeOperators();
|
---|
| 104 | AttachEventHandlers();
|
---|
[4113] | 105 | }
|
---|
| 106 |
|
---|
| 107 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[5275] | 108 | private void AfterDeserialization() {
|
---|
[4118] | 109 | AttachEventHandlers();
|
---|
[4113] | 110 | }
|
---|
| 111 |
|
---|
| 112 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[5275] | 113 | return new SingleObjectiveSymbolicTimeSeriesPrognosisProblem(this, cloner);
|
---|
[4113] | 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
|
---|
[4118] | 138 | private void AttachEventHandlers() {
|
---|
[4113] | 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;
|
---|
[5305] | 165 | bestValidationSolutionAnalyzer.ValidationPredictionHorizonParameter.ActualName = PredictionHorizonParameter.Name;
|
---|
[4113] | 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 | }
|
---|