Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs	(revision 7183)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs	(revision 7194)
@@ -50,6 +50,6 @@
     private const string TrainingTheilsUStatisticMeanResultName = "Average Theil's U (mean) (training)";
     private const string TestTheilsUStatisticMeanResultName = "Average Theil's U (mean) (test)";
-    private const string TrainingTheilsUStatisticMAResultName = "Average Theil's U (moving average) (training)";
-    private const string TestTheilsUStatisticMAResultName = "Average Theil's U (moving average) (test)";
+    private const string TrainingTheilsUStatisticMaResultName = "Average Theil's U (moving average) (training)";
+    private const string TestTheilsUStatisticMaResultName = "Average Theil's U (moving average) (test)";
 
     public new ITimeSeriesPrognosisModel Model {
@@ -153,10 +153,10 @@
     }
     public double[] TrainingTheilsUStatisticMovingAverage {
-      get { return ((DoubleArray)this[TrainingTheilsUStatisticMAResultName].Value).ToArray(); }
-      private set { this[TrainingTheilsUStatisticMAResultName].Value = new DoubleArray(value); }
+      get { return ((DoubleArray)this[TrainingTheilsUStatisticMaResultName].Value).ToArray(); }
+      private set { this[TrainingTheilsUStatisticMaResultName].Value = new DoubleArray(value); }
     }
     public double[] TestTheilsUStatisticMovingAverage {
-      get { return ((DoubleArray)this[TestTheilsUStatisticMAResultName].Value).ToArray(); }
-      private set { this[TestTheilsUStatisticMAResultName].Value = new DoubleArray(value); }
+      get { return ((DoubleArray)this[TestTheilsUStatisticMaResultName].Value).ToArray(); }
+      private set { this[TestTheilsUStatisticMaResultName].Value = new DoubleArray(value); }
     }
     #endregion
@@ -188,6 +188,6 @@
       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()));
       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()));
-      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()));
-      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()));
+      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()));
+      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()));
       horizon = 1;
     }
@@ -213,10 +213,10 @@
         anyNewResult = true;
       }
-      if (!ContainsKey(TrainingTheilsUStatisticMAResultName)) {
-        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()));
-        anyNewResult = true;
-      }
-      if (!ContainsKey(TestTheilsUStatisticMAResultName)) {
-        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()));
+      if (!ContainsKey(TrainingTheilsUStatisticMaResultName)) {
+        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()));
+        anyNewResult = true;
+      }
+      if (!ContainsKey(TestTheilsUStatisticMaResultName)) {
+        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()));
         anyNewResult = true;
       }
@@ -226,46 +226,5 @@
 
     protected void CalculateResults() {
-      OnlineCalculatorError errorState;
       string[] targetVariables = ProblemData.TargetVariables.ToArray();
-      /*
-      double[] estimatedTrainingValues = PrognosedTrainingValues.ToArray(); // cache values
-      double[] originalTrainingValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).ToArray();
-      double[] estimatedTestValues = PrognosedTestValues.ToArray(); // cache values
-      double[] originalTestValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndizes).ToArray();
-
-      double trainingMse = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
-      TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMse : double.NaN;
-      double testMse = OnlineMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
-      TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMse : double.NaN;
-
-      double trainingMae = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
-      TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMae : double.NaN;
-      double testMae = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
-      TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMae : double.NaN;
-
-      double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
-      TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN;
-      double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
-      TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN;
-
-      double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
-      TrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN;
-      double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
-      TestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN;
-
-      double trainingNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
-      TrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingNmse : double.NaN;
-      double testNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
-      TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNmse : double.NaN;
-              */
-
-      //double[] trainingDs = new double[targetVariables.Length];
-      //double[] testDs = new double[targetVariables.Length];
-
-      //double[] trainingWds = new double[targetVariables.Length];
-      //double[] testWds = new double[targetVariables.Length];
-
-      //double[] trainingTheilsU = new double[targetVariables.Length];
-      //double[] testTheilsU = new double[targetVariables.Length];
 
       var trainingMseCalculators = new OnlineMeanSquaredErrorCalculator[targetVariables.Length];
@@ -315,8 +274,15 @@
 
       var allPrognosedTrainingValues = GetPrognosedValues(ProblemData.TrainingIndizes, horizon).GetEnumerator();
+      double[] mean = new double[targetVariables.Length];
+      for (int t = 0; t < targetVariables.Length; t++) {
+        double variance;
+        OnlineCalculatorError meanErrorState, varErrorState;
+        OnlineMeanAndVarianceCalculator.Calculate(ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TrainingIndizes), out mean[t], out variance, out meanErrorState, out varErrorState);
+        if (meanErrorState != OnlineCalculatorError.None) mean[t] = 0.0;
+      }
       foreach (var row in ProblemData.TrainingIndizes) {
         if (row + horizon < ProblemData.Dataset.Rows) {
           allPrognosedTrainingValues.MoveNext();
-          var prognosedTrainingValues = allPrognosedTrainingValues.Current.SelectMany(x => x).ToArray();
+          var prognosedTrainingValues = allPrognosedTrainingValues.Current.SelectMany(x => x.ToArray()).ToArray();
           for (int t = 0; t < targetVariables.Length; t++) {
             var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariables[t],
@@ -328,5 +294,4 @@
                                                     select ProblemData.Dataset.GetDoubleValue(targetVariables[t], r)
                                                    ).Average();
-            var mean = ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TrainingIndizes).Median();
             double startValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], row - 1);
             var prognosedContinuation = prognosedTrainingValues.Skip(t).TakeEvery(targetVariables.Length);
@@ -334,5 +299,5 @@
             trainingWdsCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
             trainingTheilsULastCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
-            trainingTheilsUMeanCalculators[t].Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation);
+            trainingTheilsUMeanCalculators[t].Add(startValue, actualContinuation.Select(x => mean[t]), actualContinuation, prognosedContinuation);
             trainingTheilsUMovingAverageCalculators[t].Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
 
@@ -352,9 +317,9 @@
         }
       }
-      var allPrognosedTestValues = GetPrognosedValues(ProblemData.TestIndizes, horizon).GetEnumerator();
+      var allPrognosedTestValues = GetPrognosedValues(ProblemData.TestIndizes, horizon).ToArray().AsEnumerable().GetEnumerator();
       foreach (var row in ProblemData.TestIndizes) {
         if (row + horizon < ProblemData.Dataset.Rows) {
           allPrognosedTestValues.MoveNext();
-          var prognosedTestValues = allPrognosedTestValues.Current.SelectMany(x => x).ToArray();
+          var prognosedTestValues = allPrognosedTestValues.Current.SelectMany(x => x);
           for (int t = 0; t < targetVariables.Length; t++) {
             var actualContinuation = ProblemData.Dataset.GetDoubleValues(targetVariables[t],
@@ -366,16 +331,14 @@
                                                     select ProblemData.Dataset.GetDoubleValue(targetVariables[t], r)
                                                    ).Average();
-            // mean must be calculated on the training set!
-            var mean = ProblemData.Dataset.GetDoubleValues(targetVariables[t], ProblemData.TrainingIndizes).Median();
             double startValue = ProblemData.Dataset.GetDoubleValue(targetVariables[t], row - 1);
-            var prognosedContinuation = prognosedTestValues.Skip(t).TakeEvery(targetVariables.Length);
+            var prognosedContinuation = prognosedTestValues.Skip(t).TakeEvery(targetVariables.Length).ToArray();
             testDsCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
             testWdsCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
             testTheilsULastCalculators[t].Add(startValue, actualContinuation, prognosedContinuation);
-            testTheilsUMeanCalculators[t].Add(startValue, actualContinuation.Select(x => mean), actualContinuation, prognosedContinuation);
+            testTheilsUMeanCalculators[t].Add(startValue, actualContinuation.Select(x => mean[t]), actualContinuation, prognosedContinuation);
             testTheilsUMovingAverageCalculators[t].Add(startValue, movingAverageContinuation, actualContinuation, prognosedContinuation);
 
             var actualContinuationEnumerator = actualContinuation.GetEnumerator();
-            var prognosedContinuationEnumerator = prognosedContinuation.GetEnumerator();
+            var prognosedContinuationEnumerator = prognosedContinuation.AsEnumerable().GetEnumerator();
             while (actualContinuationEnumerator.MoveNext() & prognosedContinuationEnumerator.MoveNext()) {
               testMseCalculators[t].Add(actualContinuationEnumerator.Current, prognosedContinuationEnumerator.Current);
