Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Symbolic/Evaluators/SymbolicTimeSeriesPrognosisNormalizedMseEvaluator.cs @ 4401

Last change on this file since 4401 was 4401, checked in by gkronber, 13 years ago

Added model and solution classes for time series prognosis and added views for time series prognosis solutions. #1142

File size: 10.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.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Problems.DataAnalysis.SupportVectorMachine;
29using HeuristicLab.Problems.DataAnalysis;
30using HeuristicLab.Problems.DataAnalysis.Evaluators;
31using HeuristicLab.Parameters;
32using HeuristicLab.Optimization;
33using HeuristicLab.Operators;
34using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic;
35using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
36using System.Collections.Generic;
37using HeuristicLab.Problems.DataAnalysis.Regression;
38using HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic.Interfaces;
39
40namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis.Symbolic.Evaluators {
41  [Item("SymbolicTimeSeriesPrognosisNormalizedMseEvaluator", "")]
42  [StorableClass]
43  public class SymbolicTimeSeriesPrognosisNormalizedMseEvaluator : SingleSuccessorOperator, ISingleObjectiveSymbolicTimeSeriesPrognosisEvaluator {
44    private const string RandomParameterName = "Random";
45    private const string DataAnalysisProblemDataParameterName = "MultiVariateDataAnalysisProblemData";
46    private const string TimeSeriesExpressionInterpreterParameterName = "TimeSeriesExpressionInterpreter";
47    private const string TimeSeriesPrognosisModelParameterName = "TimeSeriesPrognosisModel";
48    private const string PredictionHorizontParameterName = "PredictionHorizon";
49    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
50    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
51    private const string ConditionVariableParameterName = "ConditionVariableName";
52    private const string SamplesStartParameterName = "SamplesStart";
53    private const string SamplesEndParameterName = "SamplesEnd";
54    private const string QualityParameterName = "Quality";
55    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
56
57    #region parameter properties
58    public ILookupParameter<IRandom> RandomParameter {
59      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
60    }
61    public ILookupParameter<MultiVariateDataAnalysisProblemData> ProblemDataParameter {
62      get { return (ILookupParameter<MultiVariateDataAnalysisProblemData>)Parameters[DataAnalysisProblemDataParameterName]; }
63    }
64    public ILookupParameter<ISymbolicTimeSeriesExpressionInterpreter> TimeSeriesExpressionInterpreterParameter {
65      get { return (ILookupParameter<ISymbolicTimeSeriesExpressionInterpreter>)Parameters[TimeSeriesExpressionInterpreterParameterName]; }
66    }
67    public IValueLookupParameter<IntValue> PredictionHorizonParameter {
68      get { return (IValueLookupParameter<IntValue>)Parameters[PredictionHorizontParameterName]; }
69    }
70    public OptionalValueParameter<StringValue> ConditionVariableNameParameter {
71      get { return (OptionalValueParameter<StringValue>)Parameters[ConditionVariableParameterName]; }
72    }
73    public IValueLookupParameter<IntValue> SamplesStartParameter {
74      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
75    }
76    public IValueLookupParameter<IntValue> SamplesEndParameter {
77      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
78    }
79    public IValueLookupParameter<DoubleArray> LowerEstimationLimitParameter {
80      get { return (IValueLookupParameter<DoubleArray>)Parameters[LowerEstimationLimitParameterName]; }
81    }
82    public IValueLookupParameter<DoubleArray> UpperEstimationLimitParameter {
83      get { return (IValueLookupParameter<DoubleArray>)Parameters[UpperEstimationLimitParameterName]; }
84    }
85    public ILookupParameter<SymbolicExpressionTree> TimeSeriesPrognosisModelParameter {
86      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[TimeSeriesPrognosisModelParameterName]; }
87    }
88    public ILookupParameter<DoubleValue> QualityParameter {
89      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
90    }
91    public IValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
92      get { return (IValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
93    }
94    #endregion
95    #region
96    public IRandom Random {
97      get { return RandomParameter.ActualValue; }
98    }
99    public MultiVariateDataAnalysisProblemData ProblemData {
100      get { return ProblemDataParameter.ActualValue; }
101    }
102    public ISymbolicTimeSeriesExpressionInterpreter TimeSeriesExpressionInterpreter {
103      get { return TimeSeriesExpressionInterpreterParameter.ActualValue; }
104    }
105    public IntValue PredictionHorizon {
106      get { return PredictionHorizonParameter.ActualValue; }
107    }
108    public StringValue ConditionVariableName {
109      get { return ConditionVariableNameParameter.Value; }
110    }
111    public IntValue SamplesStart {
112      get { return SamplesStartParameter.ActualValue; }
113    }
114    public IntValue SamplesEnd {
115      get { return SamplesEndParameter.ActualValue; }
116    }
117    public DoubleArray LowerEstimationLimit {
118      get { return LowerEstimationLimitParameter.ActualValue; }
119    }
120    public DoubleArray UpperEstimationLimit {
121      get { return UpperEstimationLimitParameter.ActualValue; }
122    }
123    public SymbolicExpressionTree TimeSeriesPrognosisModel {
124      get { return TimeSeriesPrognosisModelParameter.ActualValue; }
125    }
126    public PercentValue RelativeNumberOfEvaluatedSamples {
127      get { return RelativeNumberOfEvaluatedSamplesParameter.Value; }
128    }
129    #endregion
130
131    public SymbolicTimeSeriesPrognosisNormalizedMseEvaluator()
132      : base() {
133      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "A random number generator."));
134      Parameters.Add(new LookupParameter<MultiVariateDataAnalysisProblemData>(DataAnalysisProblemDataParameterName, "The data analysis problem data to use for training."));
135      Parameters.Add(new LookupParameter<ISymbolicTimeSeriesExpressionInterpreter>(TimeSeriesExpressionInterpreterParameterName, "The interpreter that should be used to evaluate the time series model represented as a symbolic expression tree."));
136      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The first index of the data set partition to use for training."));
137      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The last index of the data set partition to use for training."));
138      Parameters.Add(new ValueLookupParameter<IntValue>(PredictionHorizontParameterName, "The number of time steps for which to create a forecast."));
139      Parameters.Add(new ValueLookupParameter<DoubleArray>(LowerEstimationLimitParameterName, "The lower limit for estimated values."));
140      Parameters.Add(new ValueLookupParameter<DoubleArray>(UpperEstimationLimitParameterName, "The upper limit for estimated values."));
141      Parameters.Add(new OptionalValueParameter<StringValue>(ConditionVariableParameterName, "The name of the condition variable indicating if a row should be considered for evaluation or not."));
142      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(TimeSeriesPrognosisModelParameterName, "The time series prognosis model encoded as a symbolic expression tree."));
143      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The quality of the time series prognosis model encoded as a symbolic expression tree."));
144      Parameters.Add(new ValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.", new PercentValue(1)));
145    }
146
147    public override IOperation Apply() {
148      double quality;
149      string conditionVariableName = ConditionVariableName == null ? null : ConditionVariableName.Value;
150      int nRows = (int)Math.Ceiling((SamplesEnd.Value - SamplesStart.Value) * RelativeNumberOfEvaluatedSamples.Value);
151      IEnumerable<int> rows = RandomEnumerable.SampleRandomNumbers(Random.Next(), SamplesStart.Value, SamplesEnd.Value, nRows);
152
153      quality = Evaluate(TimeSeriesPrognosisModel, ProblemData, TimeSeriesExpressionInterpreter,
154        conditionVariableName, rows, PredictionHorizon.Value, LowerEstimationLimit, UpperEstimationLimit);
155      QualityParameter.ActualValue = new DoubleValue(quality);
156      return base.Apply();
157    }
158
159    public static double Evaluate(SymbolicExpressionTree tree, MultiVariateDataAnalysisProblemData problemData,
160      ISymbolicTimeSeriesExpressionInterpreter interpreter,
161     IEnumerable<int> rows, int predictionHorizon, DoubleArray lowerEstimationLimit, DoubleArray upperEstimationLimit) {
162      return Evaluate(tree, problemData, interpreter, null, rows, predictionHorizon, lowerEstimationLimit, upperEstimationLimit);
163    }
164
165    public static double Evaluate(SymbolicExpressionTree tree, MultiVariateDataAnalysisProblemData problemData,
166      ISymbolicTimeSeriesExpressionInterpreter interpreter, string conditionVariableName,
167      IEnumerable<int> rows, int predictionHorizon, DoubleArray lowerEstimationLimit, DoubleArray upperEstimationLimit) {
168      double[] zeros = new double[problemData.TargetVariables.CheckedItems.Count()];
169      double[] ones = Enumerable.Repeat(1.0, zeros.Length).ToArray();
170      return SymbolicTimeSeriesPrognosisScaledNormalizedMseEvaluator.Evaluate(tree, problemData, interpreter, conditionVariableName, rows,
171        predictionHorizon, lowerEstimationLimit, upperEstimationLimit, ones, zeros);
172    }
173  }
174}
Note: See TracBrowser for help on using the repository browser.