Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj	(revision 7120)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis-3.4.csproj	(revision 7129)
@@ -117,6 +117,7 @@
     <Compile Include="Plugin.cs" />
     <Compile Include="SingleObjective\SymbolicTimeSeriesPrognosisSingleObjectiveEvaluator.cs" />
-    <Compile Include="SingleObjective\SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs" />
-    <Compile Include="SingleObjective\SymbolicTimeSeriesPrognosisSingleObjectivePearsonRSquaredEvaluator.cs" />
+    <Compile Include="SingleObjective\SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="SingleObjective\SymbolicTimeSeriesPrognosisSingleObjectiveProblem.cs" />
     <Compile Include="SingleObjective\SymbolicTimeSeriesPrognosisSingleObjectiveTrainingBestSolutionAnalyzer.cs" />
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/Interfaces/ISymbolicTimeSeriesPrognosisModel.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/Interfaces/ISymbolicTimeSeriesPrognosisModel.cs	(revision 7120)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/Interfaces/ISymbolicTimeSeriesPrognosisModel.cs	(revision 7129)
@@ -22,6 +22,5 @@
 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis {
-  public interface ISymbolicTimeSeriesPrognosisModel : ITimeSeriesPrognosisModel {
-    ISymbolicExpressionTree SymbolicExpressionTree { get; }
+  public interface ISymbolicTimeSeriesPrognosisModel : ITimeSeriesPrognosisModel, ISymbolicDataAnalysisModel {
     ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter Interpreter { get; }
   }
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs	(revision 7120)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs	(revision 7129)
@@ -61,21 +61,109 @@
 
     public static double Calculate(ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows, int horizon) {
-      var allPredictedContinuations = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, problemData.TargetVariables.ToArray(), rows, horizon);
-      var meanCalculator = new OnlineMeanAndVarianceCalculator();
-      var allPredictedContinuationsEnumerator = allPredictedContinuations.GetEnumerator();
-      foreach (var targetVariable in problemData.TargetVariables) {
-        if (!allPredictedContinuationsEnumerator.MoveNext()) throw new InvalidOperationException();
-        var actualContinuations = from r in rows
-                                  select problemData.Dataset.GetDoubleValues(targetVariable, Enumerable.Range(r, horizon));
-        var actualContinuationsEnumerator = actualContinuations.GetEnumerator();
-        var predictedContinuationsEnumerator = allPredictedContinuationsEnumerator.Current.GetEnumerator();
-        while (actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) {
-          OnlineCalculatorError errorState;
-          meanCalculator.Add(OnlineMeanSquaredErrorCalculator.Calculate(predictedContinuationsEnumerator.Current.LimitToRange(lowerEstimationLimit, upperEstimationLimit),
-                                                                        actualContinuationsEnumerator.Current, out errorState));
-          if (errorState != OnlineCalculatorError.None) return double.NaN;
+      double[] alpha;
+      double[] beta;
+      DetermineScalingFactors(solution, problemData, interpreter, rows, out alpha, out beta);
+      var scaledSolution = Scale(solution, alpha, beta);
+
+      var meanSquaredErrorCalculators = Enumerable.Range(0, problemData.TargetVariables.Count())
+        .Select(i => new OnlineMeanSquaredErrorCalculator()).ToArray();
+
+      var allPredictedContinuations = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset,
+                                                                                  problemData.TargetVariables.ToArray(),
+                                                                                  rows, horizon);
+      var allContinuationsEnumerator = allPredictedContinuations.GetEnumerator();
+      var rowsEnumerator = rows.GetEnumerator();
+      while (allContinuationsEnumerator.MoveNext() & rowsEnumerator.MoveNext()) {
+        var componentEnumerator = allContinuationsEnumerator.Current.GetEnumerator();
+        var mseCalculatorsEnumerator = meanSquaredErrorCalculators.AsEnumerable().GetEnumerator();
+        var targetVarEnumerator = problemData.TargetVariables.GetEnumerator();
+        while (componentEnumerator.MoveNext() & mseCalculatorsEnumerator.MoveNext() & targetVarEnumerator.MoveNext()) {
+          var stepEnumerator = componentEnumerator.Current.GetEnumerator();
+          var actualContinuationEnumerator = problemData.Dataset.GetDoubleValues(targetVarEnumerator.Current,
+                                                                       Enumerable.Range(rowsEnumerator.Current, horizon)).GetEnumerator();
+          while (stepEnumerator.MoveNext() & actualContinuationEnumerator.MoveNext()) {
+            double e = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, stepEnumerator.Current));
+            mseCalculatorsEnumerator.Current.Add(actualContinuationEnumerator.Current, e);
+            if (mseCalculatorsEnumerator.Current.ErrorState == OnlineCalculatorError.InvalidValueAdded)
+              return double.NaN;
+          }
         }
       }
-      return meanCalculator.Mean;
+      var meanCalculator = new OnlineMeanAndVarianceCalculator();
+      foreach (var calc in meanSquaredErrorCalculators) {
+        if (calc.ErrorState != OnlineCalculatorError.None) return double.NaN;
+        meanCalculator.Add(calc.MeanSquaredError);
+      }
+      //int i = 0;
+      //foreach (var targetVariable in problemData.TargetVariables) {
+      //  var predictedContinuations = allPredictedContinuations.Select(v => v.ElementAt(i));
+      //  for (int h = 0; h < horizon; h++) {
+      //    OnlineCalculatorError errorState;
+      //    meanCalculator.Add(OnlineMeanSquaredErrorCalculator.Calculate(predictedContinuations
+      //                                                                    .Select(x => x.ElementAt(h))
+      //                                                                    .LimitToRange(lowerEstimationLimit,
+      //                                                                                  upperEstimationLimit),
+      //                                                                  actualContinuations.Select(x => x.ElementAt(h)),
+      //                                                                  out errorState));
+      //    if (errorState != OnlineCalculatorError.None) return double.NaN;
+      //  }
+      //}
+      return meanCalculator.MeanErrorState == OnlineCalculatorError.None ? meanCalculator.Mean : double.NaN;
+    }
+
+    private static ISymbolicExpressionTree Scale(ISymbolicExpressionTree solution, double[] alpha, double[] beta) {
+      var clone = (ISymbolicExpressionTree)solution.Clone();
+      int n = alpha.Length;
+      for (int i = 0; i < n; i++) {
+        var parent = clone.Root.GetSubtree(0);
+        var rpb = clone.Root.GetSubtree(0).GetSubtree(i);
+        var scaledRpb = MakeSum(
+          MakeProduct(rpb,
+            MakeConstant(beta[i], clone.Root.Grammar), clone.Root.Grammar),
+            MakeConstant(alpha[i], clone.Root.Grammar), clone.Root.Grammar);
+        parent.RemoveSubtree(i);
+        parent.InsertSubtree(i, scaledRpb);
+      }
+      return clone;
+    }
+
+    private static ISymbolicExpressionTreeNode MakeSum(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, ISymbolicExpressionTreeGrammar grammar) {
+      var sum = grammar.Symbols.Where(s => s is Addition).First().CreateTreeNode();
+      sum.AddSubtree(a);
+      sum.AddSubtree(b);
+      return sum;
+    }
+
+    private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, ISymbolicExpressionTreeGrammar grammar) {
+      var prod = grammar.Symbols.Where(s => s is Multiplication).First().CreateTreeNode();
+      prod.AddSubtree(a);
+      prod.AddSubtree(b);
+      return prod;
+    }
+
+    private static ISymbolicExpressionTreeNode MakeConstant(double c, ISymbolicExpressionTreeGrammar grammar) {
+      var node = (ConstantTreeNode)grammar.Symbols.Where(s => s is Constant).First().CreateTreeNode();
+      node.Value = c;
+      return node;
+    }
+
+    private static void DetermineScalingFactors(ISymbolicExpressionTree solution, ITimeSeriesPrognosisProblemData problemData, ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, IEnumerable<int> rows, out double[] alpha, out double[] beta) {
+      string[] targetVariables = problemData.TargetVariables.ToArray();
+      int nComponents = targetVariables.Length;
+      alpha = new double[nComponents];
+      beta = new double[nComponents];
+      var oneStepPredictions = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset,
+                                                                     targetVariables, rows,
+                                                                     1);
+      for (int i = 0; i < nComponents; i++) {
+        var target = problemData.Dataset.GetDoubleValues(targetVariables[i], rows);
+        var prediction = oneStepPredictions.Select(v => v.ElementAt(i).First());
+        OnlineCalculatorError errorState;
+        OnlineLinearScalingParameterCalculator.Calculate(prediction, target, out alpha[i], out beta[i], out errorState);
+        if (errorState != OnlineCalculatorError.None) {
+          alpha[i] = 0;
+          beta[i] = 1;
+        }
+      }
     }
 
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveProblem.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveProblem.cs	(revision 7120)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveProblem.cs	(revision 7129)
@@ -52,5 +52,5 @@
 
     public SymbolicTimeSeriesPrognosisSingleObjectiveProblem()
-      : base(new TimeSeriesPrognosisProblemData(), new SymbolicTimeSeriesPrognosisSingleObjectivePearsonRSquaredEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
+      : base(new TimeSeriesPrognosisProblemData(), new SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
       Parameters.Add(new FixedValueParameter<DoubleLimit>(EstimationLimitsParameterName, EstimationLimitsParameterDescription));
 
Index: branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs
===================================================================
--- branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs	(revision 7120)
+++ branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisModel.cs	(revision 7129)
@@ -53,4 +53,8 @@
     }
 
+    ISymbolicDataAnalysisExpressionTreeInterpreter ISymbolicDataAnalysisModel.Interpreter {
+      get { return (ISymbolicDataAnalysisExpressionTreeInterpreter)interpreter; }
+    }
+
     #endregion
 
@@ -102,7 +106,7 @@
         double beta;
         OnlineCalculatorError errorState;
-        OnlineLinearScalingParameterCalculator.Calculate(estimatedValues[i].Select(x => x.First()), targetValues,
+        OnlineLinearScalingParameterCalculator.Calculate(estimatedValues.Select(x => x.ElementAt(i).First()), targetValues,
           out alpha, out beta, out errorState);
-        if (errorState != OnlineCalculatorError.None) return;
+        if (errorState != OnlineCalculatorError.None) continue;
 
         ConstantTreeNode alphaTreeNode = null;
