Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/12/12 10:31:56 (12 years ago)
Author:
mkommend
Message:

#1081: Improved performance of time series prognosis.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs

    r7194 r7989  
    2121
    2222using System;
    23 using System.Collections.Concurrent;
    2423using System.Collections.Generic;
    2524using System.Linq;
     
    7574    }
    7675
    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);
     76    public abstract IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, int horizon);
    8077
    8178    #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); }
     79    public double TrainingMeanSquaredError {
     80      get { return ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value; }
     81      private set { ((DoubleValue)this[TrainingMeanSquaredErrorResultName].Value).Value = value; }
     82    }
     83    public double TestMeanSquaredError {
     84      get { return ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value; }
     85      private set { ((DoubleValue)this[TestMeanSquaredErrorResultName].Value).Value = value; }
     86    }
     87    public double TrainingMeanAbsoluteError {
     88      get { return ((DoubleValue)this[TrainingMeanAbsoluteErrorResultName].Value).Value; }
     89      private set { ((DoubleValue)this[TrainingMeanAbsoluteErrorResultName].Value).Value = value; }
     90    }
     91    public double TestMeanAbsoluteError {
     92      get { return ((DoubleValue)this[TestMeanAbsoluteErrorResultName].Value).Value; }
     93      private set { ((DoubleValue)this[TestMeanAbsoluteErrorResultName].Value).Value = value; }
     94    }
     95    public double TrainingRSquared {
     96      get { return ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value; }
     97      private set { ((DoubleValue)this[TrainingSquaredCorrelationResultName].Value).Value = value; }
     98    }
     99    public double TestRSquared {
     100      get { return ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value; }
     101      private set { ((DoubleValue)this[TestSquaredCorrelationResultName].Value).Value = value; }
     102    }
     103    public double TrainingRelativeError {
     104      get { return ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value; }
     105      private set { ((DoubleValue)this[TrainingRelativeErrorResultName].Value).Value = value; }
     106    }
     107    public double TestRelativeError {
     108      get { return ((DoubleValue)this[TestRelativeErrorResultName].Value).Value; }
     109      private set { ((DoubleValue)this[TestRelativeErrorResultName].Value).Value = value; }
     110    }
     111    public double TrainingNormalizedMeanSquaredError {
     112      get { return ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value; }
     113      private set { ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value = value; }
     114    }
     115    public double TestNormalizedMeanSquaredError {
     116      get { return ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value; }
     117      private set { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; }
     118    }
     119    public double TrainingDirectionalSymmetry {
     120      get { return ((DoubleValue)this[TrainingDirectionalSymmetryResultName].Value).Value; }
     121      private set { ((DoubleValue)this[TrainingDirectionalSymmetryResultName].Value).Value = value; }
     122    }
     123    public double TestDirectionalSymmetry {
     124      get { return ((DoubleValue)this[TestDirectionalSymmetryResultName].Value).Value; }
     125      private set { ((DoubleValue)this[TestDirectionalSymmetryResultName].Value).Value = value; }
     126    }
     127    public double TrainingWeightedDirectionalSymmetry {
     128      get { return ((DoubleValue)this[TrainingWeightedDirectionalSymmetryResultName].Value).Value; }
     129      private set { ((DoubleValue)this[TrainingWeightedDirectionalSymmetryResultName].Value).Value = value; }
     130    }
     131    public double TestWeightedDirectionalSymmetry {
     132      get { return ((DoubleValue)this[TestWeightedDirectionalSymmetryResultName].Value).Value; }
     133      private set { ((DoubleValue)this[TestWeightedDirectionalSymmetryResultName].Value).Value = value; }
     134    }
     135    public double TrainingTheilsUStatisticLast {
     136      get { return ((DoubleValue)this[TrainingTheilsUStatisticLastResultName].Value).Value; }
     137      private set { ((DoubleValue)this[TrainingTheilsUStatisticLastResultName].Value).Value = value; }
     138    }
     139    public double TestTheilsUStatisticLast {
     140      get { return ((DoubleValue)this[TestTheilsUStatisticLastResultName].Value).Value; }
     141      private set { ((DoubleValue)this[TestTheilsUStatisticLastResultName].Value).Value = value; }
     142    }
     143    public double TrainingTheilsUStatisticMean {
     144      get { return ((DoubleValue)this[TrainingTheilsUStatisticMeanResultName].Value).Value; }
     145      private set { ((DoubleValue)this[TrainingTheilsUStatisticMeanResultName].Value).Value = value; }
     146    }
     147    public double TestTheilsUStatisticMean {
     148      get { return ((DoubleValue)this[TestTheilsUStatisticMeanResultName].Value).Value; }
     149      private set { ((DoubleValue)this[TestTheilsUStatisticMeanResultName].Value).Value = value; }
     150    }
     151    public double TrainingTheilsUStatisticMovingAverage {
     152      get { return ((DoubleValue)this[TrainingTheilsUStatisticMaResultName].Value).Value; }
     153      private set { ((DoubleValue)this[TrainingTheilsUStatisticMaResultName].Value).Value = value; }
     154    }
     155    public double TestTheilsUStatisticMovingAverage {
     156      get { return ((DoubleValue)this[TestTheilsUStatisticMaResultName].Value).Value; }
     157      private set { ((DoubleValue)this[TestTheilsUStatisticMaResultName].Value).Value = value; }
    161158    }
    162159    #endregion
     
    170167    protected TimeSeriesPrognosisSolutionBase(ITimeSeriesPrognosisModel model, ITimeSeriesPrognosisProblemData problemData)
    171168      : 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()));
     169      Add(new Result(TrainingMeanSquaredErrorResultName, "Mean of squared errors of the model on the training partition", new DoubleValue()));
     170      Add(new Result(TestMeanSquaredErrorResultName, "Mean of squared errors of the model on the test partition", new DoubleValue()));
     171      Add(new Result(TrainingMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the training partition", new DoubleValue()));
     172      Add(new Result(TestMeanAbsoluteErrorResultName, "Mean of absolute errors of the model on the test partition", new DoubleValue()));
     173      Add(new Result(TrainingSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
     174      Add(new Result(TestSquaredCorrelationResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
     175      Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new DoubleValue()));
     176      Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new DoubleValue()));
     177      Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue()));
     178      Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue()));
     179      Add(new Result(TrainingDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the training partition", new DoubleValue()));
     180      Add(new Result(TestDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the test partition", new DoubleValue()));
     181      Add(new Result(TrainingWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the training partition", new DoubleValue()));
     182      Add(new Result(TestWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the test partition", new DoubleValue()));
     183      Add(new Result(TrainingTheilsUStatisticLastResultName, "The average Theil's U statistic (reference: previous value) of the forecasts of the model on the training partition", new DoubleValue()));
     184      Add(new Result(TestTheilsUStatisticLastResultName, "The average Theil's U statistic (reference: previous value) of the forecasts of the model on the test partition", new DoubleValue()));
     185      Add(new Result(TrainingTheilsUStatisticMeanResultName, "The average Theil's U statistic (reference: mean value) of the forecasts of the model on the training partition", new DoubleValue()));
     186      Add(new Result(TestTheilsUStatisticMeanResultName, "The average Theil's U statistic (reference: mean value) of the forecasts of the model on the test partition", new DoubleValue()));
     187      Add(new Result(TrainingTheilsUStatisticMaResultName, "The average Theil's U statistic (reference: moving average) of the forecasts of the model on the training partition", new DoubleValue()));
     188      Add(new Result(TestTheilsUStatisticMaResultName, "The average Theil's U statistic (reference: moving average) of the forecasts of the model on the test partition", new DoubleValue()));
    192189      horizon = 1;
    193190    }
    194191
    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     }
    226192
    227193    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       }
     194      string targetVariable = ProblemData.TargetVariable;
     195
     196      var trainingMseCalculators = new OnlineMeanSquaredErrorCalculator();
     197      var testMseCalculators = new OnlineMeanSquaredErrorCalculator();
     198      var trainingMaeCalculators = new OnlineMeanAbsoluteErrorCalculator();
     199      var testMaeCalculators = new OnlineMeanAbsoluteErrorCalculator();
     200      var trainingRSquaredCalculators = new OnlinePearsonsRSquaredCalculator();
     201      var testRSquaredCalculators = new OnlinePearsonsRSquaredCalculator();
     202      var trainingRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator();
     203      var testRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator();
     204      var trainingNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator();
     205      var testNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator();
     206
     207      var trainingDsCalculators = new OnlineDirectionalSymmetryCalculator();
     208      var testDsCalculators = new OnlineDirectionalSymmetryCalculator();
     209      var trainingWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator();
     210      var testWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator();
     211      var trainingTheilsULastCalculators = new OnlineTheilsUStatisticCalculator();
     212      var testTheilsULastCalculators = new OnlineTheilsUStatisticCalculator();
     213      var trainingTheilsUMeanCalculators = new OnlineTheilsUStatisticCalculator();
     214      var testTheilsUMeanCalculators = new OnlineTheilsUStatisticCalculator();
     215      var trainingTheilsUMovingAverageCalculators = new OnlineTheilsUStatisticCalculator();
     216      var testTheilsUMovingAverageCalculators = new OnlineTheilsUStatisticCalculator();
     217
     218      double mean = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TrainingIndizes).Average();
     219
    283220      foreach (var row in ProblemData.TrainingIndizes) {
    284221        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.");
     222          var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariable, Enumerable.Range(row, horizon)).ToList();
     223          var prognosedContinuation = GetPrognosedValues(new List<int> { row }, horizon).First().ToList();
     224
     225          int maWindow = 10 * horizon;
     226          var movingAverageContinuation = from h in Enumerable.Range(0, horizon)
     227                                          select (from r in Enumerable.Range(row + h - maWindow, maWindow - h)
     228                                                  where r > 0
     229                                                  select ProblemData.Dataset.GetDoubleValue(targetVariable, r)
     230                                                 ).Average();
     231
     232          double startValue = ProblemData.Dataset.GetDoubleValue(targetVariable, row - 1);
     233
     234          trainingDsCalculators.Add(startValue, actualContinuation, prognosedContinuation);
     235          trainingWdsCalculators.Add(startValue, actualContinuation, prognosedContinuation);
     236          trainingTheilsULastCalculators.Add(startValue, actualContinuation, prognosedContinuation);
     237          trainingTheilsUMeanCalculators.Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation);
     238          trainingTheilsUMovingAverageCalculators.Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
     239
     240          var actualContinuationEnumerator = actualContinuation.GetEnumerator();
     241          var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator();
     242
     243          while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) {
     244            trainingMseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     245            trainingMaeCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     246            trainingRelErrorCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     247            trainingRSquaredCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     248            trainingNmseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    316249          }
     250          if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext())
     251            throw new ArgumentException("Different number of elements in Actual continuation and prognosed continuation.");
    317252        }
    318253      }
    319       var allPrognosedTestValues = GetPrognosedValues(ProblemData.TestIndizes, horizon).ToArray().AsEnumerable().GetEnumerator();
     254
     255      mean = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TestIndizes).Average();
    320256      foreach (var row in ProblemData.TestIndizes) {
    321257        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.");
     258          var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariable, Enumerable.Range(row, horizon)).ToList();
     259          var prognosedContinuation = GetPrognosedValues(new List<int> { row }, horizon).First().ToList();
     260
     261          int maWindow = 10 * horizon;
     262          var movingAverageContinuation = from h in Enumerable.Range(0, horizon)
     263                                          select (from r in Enumerable.Range(row + h - maWindow, maWindow - h)
     264                                                  where r > 0
     265                                                  select ProblemData.Dataset.GetDoubleValue(targetVariable, r)
     266                                                 ).Average();
     267
     268          double startValue = ProblemData.Dataset.GetDoubleValue(targetVariable, row - 1);
     269          testDsCalculators.Add(startValue, actualContinuation, prognosedContinuation);
     270          testWdsCalculators.Add(startValue, actualContinuation, prognosedContinuation);
     271          testTheilsULastCalculators.Add(startValue, actualContinuation, prognosedContinuation);
     272          testTheilsUMeanCalculators.Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation);
     273          testTheilsUMovingAverageCalculators.Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
     274
     275          var actualContinuationEnumerator = actualContinuation.GetEnumerator();
     276          var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator();
     277          while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) {
     278            testMseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     279            testMaeCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     280            testRelErrorCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     281            testRSquaredCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     282            testNmseCalculators.Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
    353283          }
     284          if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext())
     285            throw new ArgumentException("Different number of elements in Actual continuation and prognosed continuation.");
    354286        }
    355287      }
    356288
    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();
     289      TrainingMeanSquaredError = trainingMseCalculators.ErrorState == OnlineCalculatorError.None ? trainingMseCalculators.Value : double.PositiveInfinity;
     290      TestMeanSquaredError = testMseCalculators.ErrorState == OnlineCalculatorError.None ? testMseCalculators.Value : double.PositiveInfinity;
     291      TrainingMeanAbsoluteError = trainingMaeCalculators.ErrorState == OnlineCalculatorError.None ? trainingMaeCalculators.Value : double.PositiveInfinity;
     292      TestMeanAbsoluteError = testMaeCalculators.ErrorState == OnlineCalculatorError.None ? testMaeCalculators.Value : double.PositiveInfinity;
     293      TrainingRelativeError = trainingRelErrorCalculators.ErrorState == OnlineCalculatorError.None ? trainingRelErrorCalculators.Value : double.PositiveInfinity;
     294      TestRelativeError = testRelErrorCalculators.ErrorState == OnlineCalculatorError.None ? testRelErrorCalculators.Value : double.PositiveInfinity;
     295      TrainingRSquared = trainingRSquaredCalculators.ErrorState == OnlineCalculatorError.None ? trainingRSquaredCalculators.Value : 0.0;
     296      TestRSquared = testRSquaredCalculators.ErrorState == OnlineCalculatorError.None ? testRSquaredCalculators.Value : 0.0;
     297      TrainingNormalizedMeanSquaredError = trainingNmseCalculators.ErrorState == OnlineCalculatorError.None ? trainingNmseCalculators.Value : double.PositiveInfinity;
     298      TestNormalizedMeanSquaredError = testNmseCalculators.ErrorState == OnlineCalculatorError.None ? testNmseCalculators.Value : double.PositiveInfinity;
     299
     300      TrainingDirectionalSymmetry = trainingDsCalculators.ErrorState == OnlineCalculatorError.None ? trainingDsCalculators.Value : 0.0;
     301      TestDirectionalSymmetry = testDsCalculators.ErrorState == OnlineCalculatorError.None ? testDsCalculators.Value : 0.0;
     302      TrainingWeightedDirectionalSymmetry = trainingWdsCalculators.ErrorState == OnlineCalculatorError.None ? trainingWdsCalculators.Value : double.PositiveInfinity;
     303      TestWeightedDirectionalSymmetry = testWdsCalculators.ErrorState == OnlineCalculatorError.None ? testWdsCalculators.Value : double.PositiveInfinity;
     304      TrainingTheilsUStatisticLast = trainingTheilsULastCalculators.ErrorState == OnlineCalculatorError.None ? trainingTheilsULastCalculators.Value : double.PositiveInfinity;
     305      TestTheilsUStatisticLast = testTheilsULastCalculators.ErrorState == OnlineCalculatorError.None ? testTheilsULastCalculators.Value : double.PositiveInfinity;
     306      TrainingTheilsUStatisticMean = trainingTheilsUMeanCalculators.ErrorState == OnlineCalculatorError.None ? trainingTheilsUMeanCalculators.Value : double.PositiveInfinity;
     307      TestTheilsUStatisticMean = testTheilsUMeanCalculators.ErrorState == OnlineCalculatorError.None ? testTheilsUMeanCalculators.Value : double.PositiveInfinity;
     308      TrainingTheilsUStatisticMovingAverage = trainingTheilsUMovingAverageCalculators.ErrorState == OnlineCalculatorError.None ? trainingTheilsUMovingAverageCalculators.Value : double.PositiveInfinity;
     309      TestTheilsUStatisticMovingAverage = testTheilsUMovingAverageCalculators.ErrorState == OnlineCalculatorError.None ? testTheilsUMovingAverageCalculators.Value : double.PositiveInfinity;
    405310    }
    406311  }
Note: See TracChangeset for help on using the changeset viewer.