Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs @ 7843

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

#1081 small changes in calculation of time series solution results

File size: 28.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Concurrent;
24using System.Collections.Generic;
25using System.Linq;
26using HeuristicLab.Common;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.DataAnalysis {
32  [StorableClass]
33  public abstract class TimeSeriesPrognosisSolutionBase : DataAnalysisSolution, ITimeSeriesPrognosisSolution {
34    private const string TrainingMeanSquaredErrorResultName = "Mean squared error (training)";
35    private const string TestMeanSquaredErrorResultName = "Mean squared error (test)";
36    private const string TrainingMeanAbsoluteErrorResultName = "Mean absolute error (training)";
37    private const string TestMeanAbsoluteErrorResultName = "Mean absolute error (test)";
38    private const string TrainingSquaredCorrelationResultName = "Pearson's R² (training)";
39    private const string TestSquaredCorrelationResultName = "Pearson's R² (test)";
40    private const string TrainingRelativeErrorResultName = "Average relative error (training)";
41    private const string TestRelativeErrorResultName = "Average relative error (test)";
42    private const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)";
43    private const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)";
44    private const string TrainingDirectionalSymmetryResultName = "Average directional symmetry (training)";
45    private const string TestDirectionalSymmetryResultName = "Average directional symmetry (test)";
46    private const string TrainingWeightedDirectionalSymmetryResultName = "Average weighted directional symmetry (training)";
47    private const string TestWeightedDirectionalSymmetryResultName = "Average weighted directional symmetry (test)";
48    private const string TrainingTheilsUStatisticLastResultName = "Average Theil's U (last) (training)";
49    private const string TestTheilsUStatisticLastResultName = "Average Theil's U (last) (test)";
50    private const string TrainingTheilsUStatisticMeanResultName = "Average Theil's U (mean) (training)";
51    private const string TestTheilsUStatisticMeanResultName = "Average Theil's U (mean) (test)";
52    private const string TrainingTheilsUStatisticMaResultName = "Average Theil's U (moving average) (training)";
53    private const string TestTheilsUStatisticMaResultName = "Average Theil's U (moving average) (test)";
54
55    public new ITimeSeriesPrognosisModel Model {
56      get { return (ITimeSeriesPrognosisModel)base.Model; }
57      protected set { base.Model = value; }
58    }
59
60    public new ITimeSeriesPrognosisProblemData ProblemData {
61      get { return (ITimeSeriesPrognosisProblemData)base.ProblemData; }
62      set { base.ProblemData = value; }
63    }
64
65    [Storable]
66    private int horizon;
67    public int Horizon {
68      get { return horizon; }
69      set {
70        if (horizon != value) {
71          horizon = value;
72          RecalculateResults();
73        }
74      }
75    }
76
77    public abstract IEnumerable<IEnumerable<double>> PrognosedTrainingValues { get; }
78    public abstract IEnumerable<IEnumerable<double>> PrognosedTestValues { get; }
79    public abstract IEnumerable<IEnumerable<IEnumerable<double>>> GetPrognosedValues(IEnumerable<int> rows, int horizon);
80
81    #region Results
82    public double[] TrainingMeanSquaredError {
83      get { return ((DoubleArray)this[TrainingMeanSquaredErrorResultName].Value).ToArray(); }
84      private set { this[TrainingMeanSquaredErrorResultName].Value = new DoubleArray(value); }
85    }
86    public double[] TestMeanSquaredError {
87      get { return ((DoubleArray)this[TestMeanSquaredErrorResultName].Value).ToArray(); }
88      private set { this[TestMeanSquaredErrorResultName].Value = new DoubleArray(value); }
89    }
90    public double[] TrainingMeanAbsoluteError {
91      get { return ((DoubleArray)this[TrainingMeanAbsoluteErrorResultName].Value).ToArray(); }
92      private set { this[TrainingMeanAbsoluteErrorResultName].Value = new DoubleArray(value); }
93    }
94    public double[] TestMeanAbsoluteError {
95      get { return ((DoubleArray)this[TestMeanAbsoluteErrorResultName].Value).ToArray(); }
96      private set { this[TestMeanAbsoluteErrorResultName].Value = new DoubleArray(value); }
97    }
98    public double[] TrainingRSquared {
99      get { return ((DoubleArray)this[TrainingSquaredCorrelationResultName].Value).ToArray(); }
100      private set { this[TrainingSquaredCorrelationResultName].Value = new DoubleArray(value); }
101    }
102    public double[] TestRSquared {
103      get { return ((DoubleArray)this[TestSquaredCorrelationResultName].Value).ToArray(); }
104      private set { this[TestSquaredCorrelationResultName].Value = new DoubleArray(value); }
105    }
106    public double[] TrainingRelativeError {
107      get { return ((DoubleArray)this[TrainingRelativeErrorResultName].Value).ToArray(); }
108      private set { this[TrainingRelativeErrorResultName].Value = new DoubleArray(value); }
109    }
110    public double[] TestRelativeError {
111      get { return ((DoubleArray)this[TestRelativeErrorResultName].Value).ToArray(); }
112      private set { this[TestRelativeErrorResultName].Value = new DoubleArray(value); }
113    }
114    public double[] TrainingNormalizedMeanSquaredError {
115      get { return ((DoubleArray)this[TrainingNormalizedMeanSquaredErrorResultName].Value).ToArray(); }
116      private set { this[TrainingNormalizedMeanSquaredErrorResultName].Value = new DoubleArray(value); }
117    }
118    public double[] TestNormalizedMeanSquaredError {
119      get { return ((DoubleArray)this[TestNormalizedMeanSquaredErrorResultName].Value).ToArray(); }
120      private set { this[TestNormalizedMeanSquaredErrorResultName].Value = new DoubleArray(value); }
121    }
122    public double[] TrainingDirectionalSymmetry {
123      get { return ((DoubleArray)this[TrainingDirectionalSymmetryResultName].Value).ToArray(); }
124      private set { this[TrainingDirectionalSymmetryResultName].Value = new DoubleArray(value); }
125    }
126    public double[] TestDirectionalSymmetry {
127      get { return ((DoubleArray)this[TestDirectionalSymmetryResultName].Value).ToArray(); }
128      private set { this[TestDirectionalSymmetryResultName].Value = new DoubleArray(value); }
129    }
130    public double[] TrainingWeightedDirectionalSymmetry {
131      get { return ((DoubleArray)this[TrainingWeightedDirectionalSymmetryResultName].Value).ToArray(); }
132      private set { this[TrainingWeightedDirectionalSymmetryResultName].Value = new DoubleArray(value); }
133    }
134    public double[] TestWeightedDirectionalSymmetry {
135      get { return ((DoubleArray)this[TestWeightedDirectionalSymmetryResultName].Value).ToArray(); }
136      private set { this[TestWeightedDirectionalSymmetryResultName].Value = new DoubleArray(value); }
137    }
138    public double[] TrainingTheilsUStatisticLast {
139      get { return ((DoubleArray)this[TrainingTheilsUStatisticLastResultName].Value).ToArray(); }
140      private set { this[TrainingTheilsUStatisticLastResultName].Value = new DoubleArray(value); }
141    }
142    public double[] TestTheilsUStatisticLast {
143      get { return ((DoubleArray)this[TestTheilsUStatisticLastResultName].Value).ToArray(); }
144      private set { this[TestTheilsUStatisticLastResultName].Value = new DoubleArray(value); }
145    }
146    public double[] TrainingTheilsUStatisticMean {
147      get { return ((DoubleArray)this[TrainingTheilsUStatisticMeanResultName].Value).ToArray(); }
148      private set { this[TrainingTheilsUStatisticMeanResultName].Value = new DoubleArray(value); }
149    }
150    public double[] TestTheilsUStatisticMean {
151      get { return ((DoubleArray)this[TestTheilsUStatisticMeanResultName].Value).ToArray(); }
152      private set { this[TestTheilsUStatisticMeanResultName].Value = new DoubleArray(value); }
153    }
154    public double[] TrainingTheilsUStatisticMovingAverage {
155      get { return ((DoubleArray)this[TrainingTheilsUStatisticMaResultName].Value).ToArray(); }
156      private set { this[TrainingTheilsUStatisticMaResultName].Value = new DoubleArray(value); }
157    }
158    public double[] TestTheilsUStatisticMovingAverage {
159      get { return ((DoubleArray)this[TestTheilsUStatisticMaResultName].Value).ToArray(); }
160      private set { this[TestTheilsUStatisticMaResultName].Value = new DoubleArray(value); }
161    }
162    #endregion
163
164    [StorableConstructor]
165    protected TimeSeriesPrognosisSolutionBase(bool deserializing) : base(deserializing) { }
166    protected TimeSeriesPrognosisSolutionBase(TimeSeriesPrognosisSolutionBase original, Cloner cloner)
167      : base(original, cloner) {
168      this.horizon = original.horizon;
169    }
170    protected TimeSeriesPrognosisSolutionBase(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData)
171      : base(model, problemData) {
172      Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleArray()));
173      Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleArray()));
174      Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleArray()));
175      Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleArray()));
176      Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleArray()));
177      Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleArray()));
178      Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new DoubleArray()));
179      Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new DoubleArray()));
180      Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleArray()));
181      Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleArray()));
182      Add(new Result(TrainingDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the training partition", new DoubleArray()));
183      Add(new Result(TestDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the test partition", new DoubleArray()));
184      Add(new Result(TrainingWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the training partition", new DoubleArray()));
185      Add(new Result(TestWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the test partition", new DoubleArray()));
186      Add(new Result(TrainingTheilsUStatisticLastResultName, "The average Theil's U statistic (reference: previous value) of the forecasts of the model on the training partition", new DoubleArray()));
187      Add(new Result(TestTheilsUStatisticLastResultName, "The average Theil's U statistic (reference: previous value) of the forecasts of the model on the test partition", new DoubleArray()));
188      Add(new Result(TrainingTheilsUStatisticMeanResultName, "The average Theil's U statistic (reference: mean value) of the forecasts of the model on the training partition", new DoubleArray()));
189      Add(new Result(TestTheilsUStatisticMeanResultName, "The average Theil's U statistic (reference: mean value) of the forecasts of the model on the test partition", new DoubleArray()));
190      Add(new Result(TrainingTheilsUStatisticMaResultName, "The average Theil's U statistic (reference: moving average) of the forecasts of the model on the training partition", new DoubleArray()));
191      Add(new Result(TestTheilsUStatisticMaResultName, "The average Theil's U statistic (reference: moving average) of the forecasts of the model on the test partition", new DoubleArray()));
192      horizon = 1;
193    }
194
195    [StorableHook(HookType.AfterDeserialization)]
196    private void AfterDeserialization() {
197      if (horizon == 0) horizon = 1;
198      bool anyNewResult = false;
199      if (!ContainsKey(TrainingTheilsUStatisticLastResultName)) {
200        Add(new Result(TrainingTheilsUStatisticLastResultName, "The average Theil's U statistic (reference: previous value) of the forecasts of the model on the training partition", new DoubleArray()));
201        anyNewResult = true;
202      }
203      if (!ContainsKey(TestTheilsUStatisticLastResultName)) {
204        Add(new Result(TestTheilsUStatisticLastResultName, "The average Theil's U statistic (reference: previous value) of the forecasts of the model on the test partition", new DoubleArray()));
205        anyNewResult = true;
206      }
207      if (!ContainsKey(TrainingTheilsUStatisticMeanResultName)) {
208        Add(new Result(TrainingTheilsUStatisticMeanResultName, "The average Theil's U statistic (reference: mean value) of the forecasts of the model on the training partition", new DoubleArray()));
209        anyNewResult = true;
210      }
211      if (!ContainsKey(TestTheilsUStatisticMeanResultName)) {
212        Add(new Result(TestTheilsUStatisticMeanResultName, "The average Theil's U statistic (reference: mean value) of the forecasts of the model on the test partition", new DoubleArray()));
213        anyNewResult = true;
214      }
215      if (!ContainsKey(TrainingTheilsUStatisticMaResultName)) {
216        Add(new Result(TrainingTheilsUStatisticMaResultName, "The average Theil's U statistic (reference: moving average) of the forecasts of the model on the training partition", new DoubleArray()));
217        anyNewResult = true;
218      }
219      if (!ContainsKey(TestTheilsUStatisticMaResultName)) {
220        Add(new Result(TestTheilsUStatisticMaResultName, "The average Theil's U statistic (reference: moving average) of the forecasts of the model on the test partition", new DoubleArray()));
221        anyNewResult = true;
222      }
223      if (anyNewResult)
224        RecalculateResults();
225    }
226
227    protected void CalculateResults() {
228      string[] targetVariables = ProblemData.TargetVariables.ToArray();
229
230      var trainingMseCalculators = new OnlineMeanSquaredErrorCalculator[targetVariables.Length];
231      var testMseCalculators = new OnlineMeanSquaredErrorCalculator[targetVariables.Length];
232      var trainingMaeCalculators = new OnlineMeanAbsoluteErrorCalculator[targetVariables.Length];
233      var testMaeCalculators = new OnlineMeanAbsoluteErrorCalculator[targetVariables.Length];
234      var trainingRSquaredCalculators = new OnlinePearsonsRSquaredCalculator[targetVariables.Length];
235      var testRSquaredCalculators = new OnlinePearsonsRSquaredCalculator[targetVariables.Length];
236      var trainingRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator[targetVariables.Length];
237      var testRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator[targetVariables.Length];
238      var trainingNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator[targetVariables.Length];
239      var testNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator[targetVariables.Length];
240
241      var trainingDsCalculators = new OnlineDirectionalSymmetryCalculator[targetVariables.Length];
242      var testDsCalculators = new OnlineDirectionalSymmetryCalculator[targetVariables.Length];
243      var trainingWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator[targetVariables.Length];
244      var testWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator[targetVariables.Length];
245      var trainingTheilsULastCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
246      var testTheilsULastCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
247      var trainingTheilsUMeanCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
248      var testTheilsUMeanCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
249      var trainingTheilsUMovingAverageCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
250      var testTheilsUMovingAverageCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
251      for (int i = 0; i < targetVariables.Length; i++) {
252        trainingMseCalculators[i] = new OnlineMeanSquaredErrorCalculator();
253        testMseCalculators[i] = new OnlineMeanSquaredErrorCalculator();
254        trainingMaeCalculators[i] = new OnlineMeanAbsoluteErrorCalculator();
255        testMaeCalculators[i] = new OnlineMeanAbsoluteErrorCalculator();
256        trainingRSquaredCalculators[i] = new OnlinePearsonsRSquaredCalculator();
257        testRSquaredCalculators[i] = new OnlinePearsonsRSquaredCalculator();
258        trainingRelErrorCalculators[i] = new OnlineMeanAbsolutePercentageErrorCalculator();
259        testRelErrorCalculators[i] = new OnlineMeanAbsolutePercentageErrorCalculator();
260        trainingNmseCalculators[i] = new OnlineNormalizedMeanSquaredErrorCalculator();
261        testNmseCalculators[i] = new OnlineNormalizedMeanSquaredErrorCalculator();
262
263        trainingDsCalculators[i] = new OnlineDirectionalSymmetryCalculator();
264        testDsCalculators[i] = new OnlineDirectionalSymmetryCalculator();
265        trainingWdsCalculators[i] = new OnlineWeightedDirectionalSymmetryCalculator();
266        testWdsCalculators[i] = new OnlineWeightedDirectionalSymmetryCalculator();
267        trainingTheilsULastCalculators[i] = new OnlineTheilsUStatisticCalculator();
268        testTheilsULastCalculators[i] = new OnlineTheilsUStatisticCalculator();
269        trainingTheilsUMeanCalculators[i] = new OnlineTheilsUStatisticCalculator();
270        testTheilsUMeanCalculators[i] = new OnlineTheilsUStatisticCalculator();
271        trainingTheilsUMovingAverageCalculators[i] = new OnlineTheilsUStatisticCalculator();
272        testTheilsUMovingAverageCalculators[i] = new OnlineTheilsUStatisticCalculator();
273      }
274
275      var allPrognosedTrainingValues = GetPrognosedValues(ProblemData.TrainingIndizes, horizon).GetEnumerator();
276      double[] mean = new double[targetVariables.Length];
277      for (int t = 0; t < targetVariables.Length; t++) {
278        double variance;
279        OnlineCalculatorError meanErrorState, varErrorState;
280        OnlineMeanAndVarianceCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TrainingIndizes), out mean[t], out variance, out meanErrorState, out varErrorState);
281        if (meanErrorState != OnlineCalculatorError.None) mean[t] = 0.0;
282      }
283      foreach (var row in ProblemData.TrainingIndizes) {
284        if (row + horizon < ProblemData.Dataset.Rows) {
285          allPrognosedTrainingValues.MoveNext();
286          var prognosedTrainingValues = allPrognosedTrainingValues.Current.SelectMany(x => x.ToArray()).ToArray();
287          for (int t = 0; t < targetVariables.Length; t++) {
288            var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariables[t],
289                                                                         Enumerable.Range(row, horizon));
290            int maWindow = 10 * horizon;
291            var movingAverageContinuation = from h in Enumerable.Range(0, horizon)
292                                            select (from r in Enumerable.Range(row + h - maWindow, maWindow - h)
293                                                    where r > 0
294                                                    select ProblemData.Dataset.GetDoubleValue(targetVariables[t], r)
295                                                   ).Average();
296            double startValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], row - 1);
297            var prognosedContinuation = prognosedTrainingValues.Skip(t).TakeEvery(targetVariables.Length);
298            trainingDsCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
299            trainingWdsCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
300            trainingTheilsULastCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
301            trainingTheilsUMeanCalculators[t].Add(startValue, actualContinuation.Select(x => mean[t]), actualContinuation, prognosedContinuation);
302            trainingTheilsUMovingAverageCalculators[t].Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
303
304            var actualContinuationEnumerator = actualContinuation.GetEnumerator();
305            var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator();
306            while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) {
307              trainingMseCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
308              trainingMaeCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
309              trainingRelErrorCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
310              trainingRSquaredCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
311              trainingNmseCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
312            }
313            if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext())
314              throw new ArgumentException(
315                "Different number of elements in Actual continuation and prognosed continuation.");
316          }
317        }
318      }
319      var allPrognosedTestValues = GetPrognosedValues(ProblemData.TestIndizes, horizon).ToArray().AsEnumerable().GetEnumerator();
320      foreach (var row in ProblemData.TestIndizes) {
321        if (row + horizon < ProblemData.Dataset.Rows) {
322          allPrognosedTestValues.MoveNext();
323          var prognosedTestValues = allPrognosedTestValues.Current.SelectMany(x => x);
324          for (int t = 0; t < targetVariables.Length; t++) {
325            var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariables[t],
326                                                                         Enumerable.Range(row, horizon));
327            int maWindow = 10 * horizon;
328            var movingAverageContinuation = from h in Enumerable.Range(0, horizon)
329                                            select (from r in Enumerable.Range(row + h - maWindow, maWindow - h)
330                                                    where r > 0
331                                                    select ProblemData.Dataset.GetDoubleValue(targetVariables[t], r)
332                                                   ).Average();
333            double startValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], row - 1);
334            var prognosedContinuation = prognosedTestValues.Skip(t).TakeEvery(targetVariables.Length).ToArray();
335            testDsCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
336            testWdsCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
337            testTheilsULastCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
338            testTheilsUMeanCalculators[t].Add(startValue, actualContinuation.Select(x => mean[t]), actualContinuation, prognosedContinuation);
339            testTheilsUMovingAverageCalculators[t].Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
340
341            var actualContinuationEnumerator = actualContinuation.GetEnumerator();
342            var prognosedContinuationEnumerator = prognosedContinuation.AsEnumerable().GetEnumerator();
343            while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) {
344              testMseCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
345              testMaeCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
346              testRelErrorCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
347              testRSquaredCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
348              testNmseCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
349            }
350            if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext())
351              throw new ArgumentException(
352                "Different number of elements in Actual continuation and prognosed continuation.");
353          }
354        }
355      }
356
357
358      TrainingMeanSquaredError = trainingMseCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
359        .ToArray();
360      TestMeanSquaredError = testMseCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
361        .ToArray();
362      TrainingMeanAbsoluteError = trainingMaeCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
363        .ToArray();
364      TestMeanAbsoluteError = testMaeCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
365        .ToArray();
366      TrainingRelativeError = trainingRelErrorCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
367        .ToArray();
368      TestRelativeError = testRelErrorCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
369        .ToArray();
370      TrainingRSquared = trainingRSquaredCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
371        .ToArray();
372      TestRSquared = testRSquaredCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
373        .ToArray();
374      TrainingNormalizedMeanSquaredError = trainingNmseCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
375        .ToArray();
376      TestNormalizedMeanSquaredError = testNmseCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
377        .ToArray();
378
379      TrainingDirectionalSymmetry = trainingDsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
380        .ToArray();
381      TestDirectionalSymmetry = testDsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
382        .ToArray();
383      TrainingWeightedDirectionalSymmetry = trainingWdsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
384        .ToArray();
385      TestWeightedDirectionalSymmetry = testWdsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
386        .ToArray();
387      TrainingTheilsUStatisticLast = trainingTheilsULastCalculators
388        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
389        .ToArray();
390      TestTheilsUStatisticLast = testTheilsULastCalculators
391        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
392        .ToArray();
393      TrainingTheilsUStatisticMean = trainingTheilsUMeanCalculators
394        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
395        .ToArray();
396      TestTheilsUStatisticMean = testTheilsUMeanCalculators
397        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
398        .ToArray();
399      TrainingTheilsUStatisticMovingAverage = trainingTheilsUMovingAverageCalculators
400        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
401        .ToArray();
402      TestTheilsUStatisticMovingAverage = testTheilsUMovingAverageCalculators
403        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
404        .ToArray();
405    }
406  }
407}
Note: See TracBrowser for help on using the repository browser.