Free cookie consent management tool by TermsFeed Policy Generator

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

#1081: worked on multi-variate time series prognosis

File:
1 edited

Legend:

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

    r7100 r7154  
    161161    protected void CalculateResults() {
    162162      OnlineCalculatorError errorState;
     163      string[] targetVariables = ProblemData.TargetVariables.ToArray();
    163164      /*
    164165      double[] estimatedTrainingValues = PrognosedTrainingValues.ToArray(); // cache values
     
    193194              */
    194195
    195       double[] trainingDs = new double[ProblemData.TargetVariables.Count()];
    196       double[] testDs = new double[ProblemData.TargetVariables.Count()];
    197 
    198       double[] trainingWds = new double[ProblemData.TargetVariables.Count()];
    199       double[] testWds = new double[ProblemData.TargetVariables.Count()];
    200 
    201       double[] trainingTheilsU = new double[ProblemData.TargetVariables.Count()];
    202       double[] testTheilsU = new double[ProblemData.TargetVariables.Count()];
    203       int i = 0;
    204       var predictedContinuationTraining = PrognosedTrainingValues.ToArray();
    205       var predictedContinuationTest = PrognosedTestValues.ToArray();
    206 
    207       foreach (var targetVariable in ProblemData.TargetVariables) {
    208         var actualTrainingValues = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TrainingIndizes).ToArray();
    209         var startTrainingValues = actualTrainingValues.Take(1);
    210         // only one continuation (but the full training set)
    211         var actualContinuationTraining = actualTrainingValues.Skip(1);
    212 
    213         var actualTestValues = ProblemData.Dataset.GetDoubleValues(targetVariable, ProblemData.TestIndizes).ToArray();
    214         var startTestValues = actualTestValues.Take(1);
    215         // only one continuation (but the full training set)
    216         var actualContinuationTest = actualTestValues.Skip(1);
    217 
    218 
    219         trainingDs[i] = OnlineDirectionalSymmetryCalculator.Calculate(startTrainingValues,
    220           Enumerable.Repeat(actualContinuationTraining, 1),
    221           Enumerable.Repeat(predictedContinuationTraining[i], 1), out errorState);
    222         if (errorState != OnlineCalculatorError.None) trainingDs[i] = double.NaN;
    223 
    224         testDs[i] = OnlineDirectionalSymmetryCalculator.Calculate(startTestValues,
    225           Enumerable.Repeat(actualContinuationTest, 1),
    226           Enumerable.Repeat(predictedContinuationTest[i], 1), out errorState);
    227         if (errorState != OnlineCalculatorError.None) testDs[i] = double.NaN;
    228 
    229         trainingWds[i] =
    230           OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTrainingValues,
    231           Enumerable.Repeat(actualContinuationTraining, 1),
    232           Enumerable.Repeat(predictedContinuationTraining[i], 1), out errorState);
    233         if (errorState != OnlineCalculatorError.None) trainingWds[i] = double.NaN;
    234 
    235         testWds[i] = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTestValues,
    236           Enumerable.Repeat(actualContinuationTest, 1),
    237           Enumerable.Repeat(predictedContinuationTest[i], 1), out errorState);
    238         if (errorState != OnlineCalculatorError.None) testWds[i] = double.NaN;
    239 
    240         trainingTheilsU[i] = OnlineTheilsUStatisticCalculator.Calculate(startTrainingValues,
    241           Enumerable.Repeat(actualContinuationTraining, 1),
    242           Enumerable.Repeat(predictedContinuationTraining[i], 1), out errorState);
    243         if (errorState != OnlineCalculatorError.None) trainingTheilsU[i] = double.NaN;
    244 
    245         testTheilsU[i] = OnlineTheilsUStatisticCalculator.Calculate(startTestValues,
    246           Enumerable.Repeat(actualContinuationTest, 1),
    247           Enumerable.Repeat(predictedContinuationTest[i], 1), out errorState);
    248         if (errorState != OnlineCalculatorError.None) testTheilsU[i] = double.NaN;
    249         i++;
     196      //double[] trainingDs = new double[targetVariables.Length];
     197      //double[] testDs = new double[targetVariables.Length];
     198
     199      //double[] trainingWds = new double[targetVariables.Length];
     200      //double[] testWds = new double[targetVariables.Length];
     201
     202      //double[] trainingTheilsU = new double[targetVariables.Length];
     203      //double[] testTheilsU = new double[targetVariables.Length];
     204
     205      var trainingDsCalculators = new OnlineDirectionalSymmetryCalculator[targetVariables.Length];
     206      var testDsCalculators = new OnlineDirectionalSymmetryCalculator[targetVariables.Length];
     207      var trainingWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator[targetVariables.Length];
     208      var testWdsCalculators = new OnlineWeightedDirectionalSymmetryCalculator[targetVariables.Length];
     209      var trainingTheilsUCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
     210      var testTheilsUCalculators = new OnlineTheilsUStatisticCalculator[targetVariables.Length];
     211      for (int i = 0; i < targetVariables.Length; i++) {
     212        trainingDsCalculators[i] = new OnlineDirectionalSymmetryCalculator();
     213        testDsCalculators[i] = new OnlineDirectionalSymmetryCalculator();
     214        trainingWdsCalculators[i] = new OnlineWeightedDirectionalSymmetryCalculator();
     215        testWdsCalculators[i] = new OnlineWeightedDirectionalSymmetryCalculator();
     216        trainingTheilsUCalculators[i] = new OnlineTheilsUStatisticCalculator();
     217        testTheilsUCalculators[i] = new OnlineTheilsUStatisticCalculator();
    250218      }
    251219
    252       TrainingDirectionalSymmetry = trainingDs;
    253       TestDirectionalSymmetry = testDs;
    254       TrainingWeightedDirectionalSymmetry = trainingWds;
    255       TestWeightedDirectionalSymmetry = testWds;
    256       TrainingTheilsUStatistic = trainingTheilsU;
    257       TestTheilsUStatistic = testTheilsU;
     220      var allPrognosedTrainingValues = PrognosedTrainingValues.SelectMany(x => x).ToArray();
     221      var allPrognosedTestValues = PrognosedTestValues.SelectMany(x => x).ToArray();
     222      for (int t = 0; t < targetVariables.Length; t++) {
     223        var actualTrainingValues = ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TrainingIndizes);
     224        double startTrainingValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], ProblemData.TrainingIndizes.First() - 1);
     225        var prognosedTrainingValues = allPrognosedTrainingValues.Skip(t).TakeEvery(targetVariables.Length);
     226        trainingDsCalculators[t].Add(startTrainingValue, actualTrainingValues, prognosedTrainingValues);
     227        trainingWdsCalculators[t].Add(startTrainingValue, actualTrainingValues, prognosedTrainingValues);
     228        trainingTheilsUCalculators[t].Add(startTrainingValue, actualTrainingValues, prognosedTrainingValues);
     229
     230        var actualTestValues = ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TestIndizes);
     231        double startTestValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], ProblemData.TestIndizes.First() - 1);
     232        var prognosedTestValues = allPrognosedTestValues.Skip(t).TakeEvery(targetVariables.Length);
     233        testDsCalculators[t].Add(startTestValue, actualTestValues, prognosedTestValues);
     234        testWdsCalculators[t].Add(startTestValue, actualTestValues, prognosedTestValues);
     235        testTheilsUCalculators[t].Add(startTestValue, actualTestValues, prognosedTestValues);
     236      }
     237
     238      TrainingDirectionalSymmetry = trainingDsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
     239        .ToArray();
     240      TestDirectionalSymmetry = testDsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : 0.0)
     241        .ToArray();
     242      TrainingWeightedDirectionalSymmetry = trainingWdsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     243        .ToArray();
     244      TestWeightedDirectionalSymmetry = testWdsCalculators.Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     245        .ToArray();
     246      TrainingTheilsUStatistic = trainingDsCalculators
     247        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     248        .ToArray();
     249      TestTheilsUStatistic = testTheilsUCalculators
     250        .Select(c => c.ErrorState == OnlineCalculatorError.None ? c.Value : double.PositiveInfinity)
     251        .ToArray();
    258252    }
    259253  }
Note: See TracChangeset for help on using the changeset viewer.