Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/13/11 13:52:22 (13 years ago)
Author:
gkronber
Message:

#1081 implemented remaining metrics for time series prognosis solutions, added estimation limits fixed training and validation best solution analyzers, implemented overfitting analyzer.

File:
1 edited

Legend:

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

    r7160 r7183  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Concurrent;
    2324using System.Collections.Generic;
     
    195196    private void AfterDeserialization() {
    196197      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();
    197225    }
    198226
     
    240268      //double[] trainingTheilsU = new double[targetVariables.Length];
    241269      //double[] testTheilsU = new double[targetVariables.Length];
     270
     271      var trainingMseCalculators = new OnlineMeanSquaredErrorCalculator[targetVariables.Length];
     272      var testMseCalculators = new OnlineMeanSquaredErrorCalculator[targetVariables.Length];
     273      var trainingMaeCalculators = new OnlineMeanAbsoluteErrorCalculator[targetVariables.Length];
     274      var testMaeCalculators = new OnlineMeanAbsoluteErrorCalculator[targetVariables.Length];
     275      var trainingRSquaredCalculators = new OnlinePearsonsRSquaredCalculator[targetVariables.Length];
     276      var testRSquaredCalculators = new OnlinePearsonsRSquaredCalculator[targetVariables.Length];
     277      var trainingRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator[targetVariables.Length];
     278      var testRelErrorCalculators = new OnlineMeanAbsolutePercentageErrorCalculator[targetVariables.Length];
     279      var trainingNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator[targetVariables.Length];
     280      var testNmseCalculators = new OnlineNormalizedMeanSquaredErrorCalculator[targetVariables.Length];
    242281
    243282      var trainingDsCalculators = new OnlineDirectionalSymmetryCalculator[targetVariables.Length];
     
    252291      var testTheilsUMovingAverageCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
    253292      for (int i = 0; i < targetVariables.Length; i++) {
     293        trainingMseCalculators[i] = new OnlineMeanSquaredErrorCalculator();
     294        testMseCalculators[i] = new OnlineMeanSquaredErrorCalculator();
     295        trainingMaeCalculators[i] = new OnlineMeanAbsoluteErrorCalculator();
     296        testMaeCalculators[i] = new OnlineMeanAbsoluteErrorCalculator();
     297        trainingRSquaredCalculators[i] = new OnlinePearsonsRSquaredCalculator();
     298        testRSquaredCalculators[i] = new OnlinePearsonsRSquaredCalculator();
     299        trainingRelErrorCalculators[i] = new OnlineMeanAbsolutePercentageErrorCalculator();
     300        testRelErrorCalculators[i] = new OnlineMeanAbsolutePercentageErrorCalculator();
     301        trainingNmseCalculators[i] = new OnlineNormalizedMeanSquaredErrorCalculator();
     302        testNmseCalculators[i] = new OnlineNormalizedMeanSquaredErrorCalculator();
     303
    254304        trainingDsCalculators[i] = new OnlineDirectionalSymmetryCalculator();
    255305        testDsCalculators[i] = new OnlineDirectionalSymmetryCalculator();
     
    286336            trainingTheilsUMeanCalculators[t].Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation);
    287337            trainingTheilsUMovingAverageCalculators[t].Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
     338
     339            var actualContinuationEnumerator = actualContinuation.GetEnumerator();
     340            var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator();
     341            while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) {
     342              trainingMseCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     343              trainingMaeCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     344              trainingRelErrorCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     345              trainingRSquaredCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     346              trainingNmseCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     347            }
     348            if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext())
     349              throw new ArgumentException(
     350                "Different number of elements in Actual continuation and prognosed continuation.");
    288351          }
    289352        }
     
    312375            testTheilsUMeanCalculators[t].Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation);
    313376            testTheilsUMovingAverageCalculators[t].Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
     377
     378            var actualContinuationEnumerator = actualContinuation.GetEnumerator();
     379            var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator();
     380            while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) {
     381              testMseCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     382              testMaeCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     383              testRelErrorCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     384              testRSquaredCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     385              testNmseCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
     386            }
     387            if (actualContinuationEnumerator.MoveNext() | prognosedContinuationEnumerator.MoveNext())
     388              throw new ArgumentException(
     389                "Different number of elements in Actual continuation and prognosed continuation.");
    314390          }
    315391        }
    316392      }
    317393
     394
     395      TrainingMeanSquaredError = trainingMseCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     396        .ToArray();
     397      TestMeanSquaredError = testMseCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     398        .ToArray();
     399      TrainingMeanAbsoluteError = trainingMaeCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     400        .ToArray();
     401      TestMeanAbsoluteError = testMaeCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     402        .ToArray();
     403      TrainingRelativeError = trainingRelErrorCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     404        .ToArray();
     405      TestRelativeError = testRelErrorCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     406        .ToArray();
     407      TrainingRSquared = trainingRSquaredCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
     408        .ToArray();
     409      TestRSquared = testRSquaredCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
     410        .ToArray();
     411      TrainingNormalizedMeanSquaredError = trainingNmseCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     412        .ToArray();
     413      TestNormalizedMeanSquaredError = testNmseCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     414        .ToArray();
     415
    318416      TrainingDirectionalSymmetry = trainingDsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
    319417        .ToArray();
Note: See TracChangeset for help on using the changeset viewer.