Index: /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Grammar.cs
===================================================================
--- /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Grammar.cs	(revision 14310)
+++ /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Grammar.cs	(revision 14311)
@@ -19,8 +19,8 @@
 
     public void Initialize() {
-      var func = new SimpleSymbol("Func", "The root for the blood glucose forecasting model.", 3, 3);
+      // var func = new SimpleSymbol("Func", "The root for the blood glucose forecasting model.", 3, 3);
       var exprGluc = new SimpleSymbol("ExprGluc", string.Empty, 1, 1);
-      var exprIns = new SimpleSymbol("ExprIns", string.Empty, 1, 1);
-      var exprCh = new SimpleSymbol("ExprCh", string.Empty, 1, 1);
+      // var exprIns = new SimpleSymbol("ExprIns", string.Empty, 1, 1);
+      // var exprCh = new SimpleSymbol("ExprCh", string.Empty, 1, 1);
 
       // var predGlucData = new PredictedGlucoseVariableSymbol();
@@ -39,24 +39,24 @@
 
       // operators for exprCh
-      var plusCh = new SimpleSymbol("+Ch", "+", 2, 2);
-      var minusCh = new SimpleSymbol("-Ch", "-", 2, 2);
-      var prodCh = new SimpleSymbol("*Ch", "*", 2, 2);
-      var divCh = new SimpleSymbol("/Ch", "/", 2, 2);
-      var expCh = new SimpleSymbol("ExpCh", "Exp", 1, 1);
-      var sinCh = new SimpleSymbol("SinCh", "Sin", 1, 1);
-      var cosCh = new SimpleSymbol("CosCh", "Cos", 1, 1);
-      var logCh = new SimpleSymbol("LogCh", "Log", 1, 1);
+      // var plusCh = new SimpleSymbol("+Ch", "+", 2, 2);
+      // var minusCh = new SimpleSymbol("-Ch", "-", 2, 2);
+      // var prodCh = new SimpleSymbol("*Ch", "*", 2, 2);
+      // var divCh = new SimpleSymbol("/Ch", "/", 2, 2);
+      // var expCh = new SimpleSymbol("ExpCh", "Exp", 1, 1);
+      // var sinCh = new SimpleSymbol("SinCh", "Sin", 1, 1);
+      // var cosCh = new SimpleSymbol("CosCh", "Cos", 1, 1);
+      // var logCh = new SimpleSymbol("LogCh", "Log", 1, 1);
       var curvedCh = new CurvedChVariableSymbol("CurvedCh", "");
       // var cteCh = new CteSymbol();
 
       // operators for exprIns
-      var plusIns = new SimpleSymbol("+Ins", "+", 2, 2);
-      var minusIns = new SimpleSymbol("-Ins", "-", 2, 2);
-      var prodIns = new SimpleSymbol("*Ins", "*", 2, 2);
-      var divIns = new SimpleSymbol("/Ins", "/", 2, 2);
-      var expIns = new SimpleSymbol("ExpIns", "Exp", 1, 1);
-      var sinIns = new SimpleSymbol("SinIns", "Sin", 1, 1);
-      var cosIns = new SimpleSymbol("CosIns", "Cos", 1, 1);
-      var logIns = new SimpleSymbol("LogIns", "Log", 1, 1);
+      // var plusIns = new SimpleSymbol("+Ins", "+", 2, 2);
+      // var minusIns = new SimpleSymbol("-Ins", "-", 2, 2);
+      // var prodIns = new SimpleSymbol("*Ins", "*", 2, 2);
+      // var divIns = new SimpleSymbol("/Ins", "/", 2, 2);
+      // var expIns = new SimpleSymbol("ExpIns", "Exp", 1, 1);
+      // var sinIns = new SimpleSymbol("SinIns", "Sin", 1, 1);
+      // var cosIns = new SimpleSymbol("CosIns", "Cos", 1, 1);
+      // var logIns = new SimpleSymbol("LogIns", "Log", 1, 1);
       var curvedIns = new CurvedInsVariableSymbol("CurvedIns", "");
       // var realInsVar = new RealInsulineVariableSymbol();
@@ -65,8 +65,8 @@
       // var cteCh = new CteSymbol();
 
-      AddSymbol(func);
+      // AddSymbol(func);
       AddSymbol(exprGluc);
-      AddSymbol(exprIns);
-      AddSymbol(exprCh);
+      // AddSymbol(exprIns);
+      // AddSymbol(exprCh);
       // AddSymbol(predGlucData);
       AddSymbol(realGlucData);
@@ -82,29 +82,29 @@
       AddSymbol(curvedCh);
 
-      AddSymbol(plusCh);
-      AddSymbol(minusCh);
-      AddSymbol(prodCh);
-      AddSymbol(divCh);
-      AddSymbol(expCh);
-      AddSymbol(sinCh);
-      AddSymbol(cosCh);
-      AddSymbol(logCh);
+      // AddSymbol(plusCh);
+      // AddSymbol(minusCh);
+      // AddSymbol(prodCh);
+      // AddSymbol(divCh);
+      // AddSymbol(expCh);
+      // AddSymbol(sinCh);
+      // AddSymbol(cosCh);
+      // AddSymbol(logCh);
 
       AddSymbol(curvedIns);
-      AddSymbol(plusIns);
-      AddSymbol(minusIns);
-      AddSymbol(prodIns);
-      AddSymbol(divIns);
-      AddSymbol(expIns);
-      AddSymbol(sinIns);
-      AddSymbol(cosIns);
-      AddSymbol(logIns);
+      // AddSymbol(plusIns);
+      // AddSymbol(minusIns);
+      // AddSymbol(prodIns);
+      // AddSymbol(divIns);
+      // AddSymbol(expIns);
+      // AddSymbol(sinIns);
+      // AddSymbol(cosIns);
+      // AddSymbol(logIns);
       // AddSymbol(realInsVar);
       AddSymbol(constSy);
 
       // <func> ::= <exprgluc> + <exprch> - <exprins>
-      AddAllowedChildSymbol(func, exprGluc, 0);
-      AddAllowedChildSymbol(func, exprCh, 1);
-      AddAllowedChildSymbol(func, exprIns, 2);
+      // AddAllowedChildSymbol(func, exprGluc, 0);
+      // AddAllowedChildSymbol(func, exprCh, 1);
+      // AddAllowedChildSymbol(func, exprIns, 2);
 
       /* # Glucose
@@ -115,5 +115,5 @@
                     |realData(k-<idx2hOrMore>)
       */
-      var opGlucSet = new Symbol[] { plusGluc, minusGluc, prodGluc, divGluc, expGluc, sinGluc, cosGluc, logGluc, /*predGlucData, */ realGlucData, constSy };
+      var opGlucSet = new Symbol[] { plusGluc, minusGluc, prodGluc, divGluc, expGluc, sinGluc, cosGluc, logGluc, /*predGlucData, */ realGlucData, constSy, curvedCh, curvedIns };
       foreach (var opGluc in opGlucSet) {
         AddAllowedChildSymbol(exprGluc, opGluc);
@@ -152,21 +152,21 @@
               |beta(0.02*Math.min(48,getPrevDataDistance(1,k,1)),5,2) 
       */
-      var opChSet = new Symbol[] { plusCh, minusCh, prodCh, divCh, expCh, sinCh, cosCh, logCh, curvedCh, constSy };
-      foreach (var opCh in opChSet) {
-        AddAllowedChildSymbol(exprCh, opCh);
-      }
-
-      foreach (var parentOp in new Symbol[] { plusCh, minusCh, prodCh, divCh }) {
-        foreach (var childOp in opChSet) {
-          AddAllowedChildSymbol(parentOp, childOp, 0);
-          AddAllowedChildSymbol(parentOp, childOp, 1);
-        }
-      }
-      // <exprch> ::= <preop> (<exprch>)
-      foreach (var parentOp in new Symbol[] { expCh, sinCh, cosCh, logCh }) {
-        foreach (var childOp in opChSet) {
-          AddAllowedChildSymbol(parentOp, childOp, 0);
-        }
-      }
+      // var opChSet = new Symbol[] { plusCh, minusCh, prodCh, divCh, expCh, sinCh, cosCh, logCh, curvedCh, constSy };
+      // foreach (var opCh in opChSet) {
+      //   AddAllowedChildSymbol(exprCh, opCh);
+      // }
+      // 
+      // foreach (var parentOp in new Symbol[] { plusCh, minusCh, prodCh, divCh }) {
+      //   foreach (var childOp in opChSet) {
+      //     AddAllowedChildSymbol(parentOp, childOp, 0);
+      //     AddAllowedChildSymbol(parentOp, childOp, 1);
+      //   }
+      // }
+      // // <exprch> ::= <preop> (<exprch>)
+      // foreach (var parentOp in new Symbol[] { expCh, sinCh, cosCh, logCh }) {
+      //   foreach (var childOp in opChSet) {
+      //     AddAllowedChildSymbol(parentOp, childOp, 0);
+      //   }
+      // }
 
       /*
@@ -192,26 +192,26 @@
 
       */
-      var opInsSet = new Symbol[] { plusIns, minusIns, prodIns, divIns, expIns, sinIns, cosIns, logIns, /* realInsVar, */ curvedIns, constSy };
-      foreach (var opIns in opInsSet) {
-        AddAllowedChildSymbol(exprIns, opIns);
-      }
-
-      // <exprins> ::= (<exprins> <op> <exprins>)
-      // <exprins> ::= (<cte> <op> <exprins>)		
-      foreach (var parentOp in new Symbol[] { plusIns, minusIns, prodIns, divIns }) {
-        foreach (var childOp in opInsSet) {
-          AddAllowedChildSymbol(parentOp, childOp, 0);
-          AddAllowedChildSymbol(parentOp, childOp, 1);
-        }
-      }
-      // <exprins> ::= <preop> (<exprins>)
-      foreach (var op in new Symbol[] { expIns, sinIns, cosIns, logIns }) {
-        foreach (var childOp in opInsSet) {
-          AddAllowedChildSymbol(op, childOp, 0);
-        }
-      }
-
-      // root is func
-      AddAllowedChildSymbol(StartSymbol, func);
+      // var opInsSet = new Symbol[] { plusIns, minusIns, prodIns, divIns, expIns, sinIns, cosIns, logIns, /* realInsVar, */ curvedIns, constSy };
+      // foreach (var opIns in opInsSet) {
+      //   AddAllowedChildSymbol(exprIns, opIns);
+      // }
+      // 
+      // // <exprins> ::= (<exprins> <op> <exprins>)
+      // // <exprins> ::= (<cte> <op> <exprins>)		
+      // foreach (var parentOp in new Symbol[] { plusIns, minusIns, prodIns, divIns }) {
+      //   foreach (var childOp in opInsSet) {
+      //     AddAllowedChildSymbol(parentOp, childOp, 0);
+      //     AddAllowedChildSymbol(parentOp, childOp, 1);
+      //   }
+      // }
+      // // <exprins> ::= <preop> (<exprins>)
+      // foreach (var op in new Symbol[] { expIns, sinIns, cosIns, logIns }) {
+      //   foreach (var childOp in opInsSet) {
+      //     AddAllowedChildSymbol(op, childOp, 0);
+      //   }
+      // }
+
+      // root is exprGluc
+      AddAllowedChildSymbol(StartSymbol, exprGluc);
     }
 
Index: /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Interpreter.cs
===================================================================
--- /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Interpreter.cs	(revision 14310)
+++ /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Interpreter.cs	(revision 14311)
@@ -31,4 +31,5 @@
       var predictions = new double[targetGluc.Length];
       var rowsEnumerator = rows.GetEnumerator();
+      rowsEnumerator.MoveNext();
       for (int k = 0; k < predictions.Length; k++, rowsEnumerator.MoveNext()) {
         if (double.IsNaN(targetGluc[k])) {
@@ -36,5 +37,5 @@
         } else {
           var rawPred = InterpretRec(model, data, rowsEnumerator.Current);
-          predictions[k] = rawPred; 
+          predictions[k] = rawPred;
         }
       }
@@ -61,26 +62,27 @@
       // d Q1 / dt = ins(t) - alpha * Q1(t)
       // d Q2 / dt = alpha * (Q1(t) - Q2(t))
-      // S = Q1(t) + Q2(t)
+      // d Q3 / dt = alpha * Q2(t) - beta * Q3(t)
       var alpha = node.Alpha;
+      var beta = node.Beta;
 
       var ins = dataset.GetReadOnlyDoubleValues("Insuline");
       var time = dataset.GetReadOnlyDoubleValues("HourMin").ToArray();
 
-      // TODO reset for new time intervals
-
-      double q1, q2, q1_prev, q2_prev;
+      double q1, q2, q3, q1_prev, q2_prev, q3_prev;
       // starting values: zeros
-      q1 = q2 = q1_prev = q2_prev = 0;
+      q1 = q2 = q3 = q1_prev = q2_prev = q3_prev = 0;
       double[] s = new double[dataset.Rows];
 
       for (int t = 1; t < dataset.Rows; t++) {
         if (IsStartOfNewPeriod(time, t)) {
-          q1 = q2 = q1_prev = q2_prev = 0;
+          q1 = q2 = q3 = q1_prev = q2_prev = q3_prev = 0;
         }
         q1 = q1_prev + ins[t] - alpha * q1_prev;
         q2 = q2_prev + alpha * (q1_prev - q2_prev);
-        s[t] = q1 + q2;
+        q3 = q3_prev + alpha * q2_prev - beta * q3_prev;
+        s[t] = q3;
         q1_prev = q1;
         q2_prev = q2;
+        q3_prev = q3;
 
       }
@@ -97,26 +99,27 @@
       // d Q1 / dt = ins(t) - alpha * Q1(t)
       // d Q2 / dt = alpha * (Q1(t) - Q2(t))
-      // S = Q1(t) + Q2(t)
+      // d Q3 / dt = alpha * Q2(t) - beta * Q3(t)
       var alpha = node.Alpha;
-
-      var ch = dataset.GetReadOnlyDoubleValues("CH");
+      var beta = node.Beta;
+
+      var ins = dataset.GetReadOnlyDoubleValues("CH");
       var time = dataset.GetReadOnlyDoubleValues("HourMin").ToArray();
 
-      // TODO reset for new time intervals
-
-      double q1, q2, q1_prev, q2_prev;
+      double q1, q2, q3, q1_prev, q2_prev, q3_prev;
       // starting values: zeros
-      q1 = q2 = q1_prev = q2_prev = 0;
+      q1 = q2 = q3 = q1_prev = q2_prev = q3_prev = 0;
       double[] s = new double[dataset.Rows];
 
       for (int t = 1; t < dataset.Rows; t++) {
         if (IsStartOfNewPeriod(time, t)) {
-          q1 = q2 = q1_prev = q2_prev = 0;
-        }
-        q1 = q1_prev + ch[t] - alpha * q1_prev;
+          q1 = q2 = q3 = q1_prev = q2_prev = q3_prev = 0;
+        }
+        q1 = q1_prev + ins[t] - alpha * q1_prev;
         q2 = q2_prev + alpha * (q1_prev - q2_prev);
-        s[t] = q1 + q2;
+        q3 = q3_prev + alpha * q2_prev - beta * q3_prev;
+        s[t] = q3;
         q1_prev = q1;
         q2_prev = q2;
+        q3_prev = q3;
 
       }
@@ -206,7 +209,4 @@
     }
 
-    private static double Beta(double x, double alpha, double beta) {
-      return 1.0 / alglib.beta(alpha, beta) * Math.Pow(x, alpha - 1) * Math.Pow(1 - x, beta - 1);
-    }
   }
 }
Index: /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Model.cs
===================================================================
--- /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Model.cs	(revision 14310)
+++ /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Model.cs	(revision 14311)
@@ -18,6 +18,4 @@
   public sealed class Model : NamedItem, IRegressionModel {
     [Storable]
-    private readonly IRegressionProblemData problemData;
-    [Storable]
     private readonly ISymbolicExpressionTree tree;
     [Storable]
@@ -26,6 +24,9 @@
     private string[] variablesUsedForPrediction;
 
+    [StorableConstructor]
+    private Model(bool deserializing) : base(deserializing) {
+    }
+
     private Model(Model original, Cloner cloner) {
-      this.problemData = cloner.Clone(original.problemData);
       this.tree = cloner.Clone(original.tree);
       this.variablesUsedForPrediction = original.variablesUsedForPrediction;
@@ -33,6 +34,5 @@
     }
 
-    public Model(IRegressionProblemData problemData, ISymbolicExpressionTree tree, string targetVariable, string[] variablesUsedForPrediction) {
-      this.problemData = problemData;
+    public Model(ISymbolicExpressionTree tree, string targetVariable, string[] variablesUsedForPrediction) {
       this.tree = tree;
       this.variablesUsedForPrediction = variablesUsedForPrediction;
@@ -45,5 +45,5 @@
 
     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
-      return Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0), problemData.Dataset, rows);
+      return Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0), dataset, rows);
     }
 
Index: /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Problem.cs
===================================================================
--- /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Problem.cs	(revision 14310)
+++ /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Problem.cs	(revision 14311)
@@ -32,4 +32,5 @@
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
 using HeuristicLab.Problems.DataAnalysis;
+using HeuristicLab.Problems.DataAnalysis.Symbolic;
 using HeuristicLab.Problems.Instances;
 
@@ -98,14 +99,15 @@
     public override double Evaluate(ISymbolicExpressionTree tree, IRandom random) {
       var problemData = ProblemData;
-      var rows = problemData.TrainingIndices.ToArray();
-      var target = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
-      var predicted0 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(0), problemData.Dataset, rows);
-      var predicted1 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(1), problemData.Dataset, rows);
-      var predicted2 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(2), problemData.Dataset, rows);
-
-      var pred0_rsq = Rsq(predicted0, target);
-      var pred1_rsq = Rsq(predicted1, target);
-      var pred2_rsq = Rsq(predicted2, target);
-      return pred0_rsq + pred1_rsq + pred2_rsq;
+      var target = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices);
+      var allPredicted = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0), problemData.Dataset, problemData.AllIndices).ToArray();
+      var predicted = problemData.TrainingIndices.Select(r => allPredicted[r]);
+
+      // var predicted1 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(1), problemData.Dataset, rows);
+      // var predicted2 = Interpreter.Apply(tree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(2), problemData.Dataset, rows);
+
+      var pred0_rsq = Rsq(predicted, target);
+      // var pred1_rsq = Rsq(predicted1, target);
+      // var pred2_rsq = Rsq(predicted2, target);
+      return pred0_rsq; // + pred1_rsq + pred2_rsq;
     }
 
@@ -129,7 +131,10 @@
         results.Add(new Result("Solution", typeof(IRegressionSolution)));
       }
-      if (!results.ContainsKey("Terms")) {
-        results.Add(new Result("Terms", typeof(DataTable)));
+      if (!results.ContainsKey("ScaledTree")) {
+        results.Add(new Result("ScaledTree", typeof(ISymbolicExpressionTree)));
       }
+      // if (!results.ContainsKey("Terms")) {
+      //   results.Add(new Result("Terms", typeof(DataTable)));
+      // }
 
       var bestTree = trees.First();
@@ -142,60 +147,43 @@
       }
 
-
-      var clonedProblemData = (IRegressionProblemData)ProblemData.Clone();
-      var rows = clonedProblemData.TrainingIndices.ToArray();
-      var target = clonedProblemData.Dataset.GetDoubleValues(clonedProblemData.TargetVariable, rows).ToArray();
-      var predicted0 =
-        Interpreter.Apply(bestTree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(0), clonedProblemData.Dataset, rows)
+      bestTree = (ISymbolicExpressionTree)bestTree.Clone();
+      var expressionNode = bestTree.Root.GetSubtree(0).GetSubtree(0);
+      // scale
+
+      var problemData = ProblemData;
+      var rows = problemData.AllIndices.ToArray();
+      var target = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows).ToArray();
+      var predicted =
+        Interpreter.Apply(expressionNode.GetSubtree(0), problemData.Dataset, rows)
           .ToArray();
-      var predicted1 =
-        Interpreter.Apply(bestTree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(1), clonedProblemData.Dataset, rows)
-          .ToArray();
-      var predicted2 =
-        Interpreter.Apply(bestTree.Root.GetSubtree(0).GetSubtree(0).GetSubtree(2), clonedProblemData.Dataset, rows)
-          .ToArray();
-
-      var termsTable = new HeuristicLab.Analysis.DataTable("Terms");
-      var r0 = new DataRow("GlucTerm", "GlucTerm", predicted0);
-      var r1 = new DataRow("InsTerm", "InsTerm", predicted1);
-      r1.VisualProperties.SecondYAxis = true;
-      var r2 = new DataRow("ChTerm", "ChTerm", predicted2);
-      r2.VisualProperties.SecondYAxis = true;
-      var r3 = new DataRow("Target", "Target", target);
-      termsTable.Rows.Add(r0);
-      termsTable.Rows.Add(r1);
-      termsTable.Rows.Add(r2);
-      termsTable.Rows.Add(r3);
-      results["Terms"].Value = termsTable;
-
-
-      var filteredPredicted0 = rows.Where(r => !double.IsNaN(target[r])).Select(r => predicted0[r]).ToArray();
-      var filteredPredicted1 = rows.Where(r => !double.IsNaN(target[r])).Select(r => predicted1[r]).ToArray();
-      var filteredPredicted2 = rows.Where(r => !double.IsNaN(target[r])).Select(r => predicted2[r]).ToArray();
+
+      var filteredPredicted = rows.Where(r => !double.IsNaN(target[r])).Select(r => predicted[r]).ToArray();
       var filteredTarget = target.Where(t => !double.IsNaN(t)).ToArray();
-
-
-      var ds = new ModifiableDataset(new string[] { "pred0", "pred1", "pred2", "target" },
-        new List<IList>
-        {
-          filteredPredicted0.ToList(),
-          filteredPredicted1.ToList(),
-          filteredPredicted2.ToList(),
-          filteredTarget.ToList()
-        });
-      var lrProbData = new RegressionProblemData(ds, new string[] { "pred0", "pred1", "pred2" }, "target");
-      lrProbData.TrainingPartition.Start = clonedProblemData.TrainingPartition.Start;
-      lrProbData.TrainingPartition.End = clonedProblemData.TrainingPartition.End;
-      lrProbData.TestPartition.Start = clonedProblemData.TestPartition.Start;
-      lrProbData.TestPartition.End = clonedProblemData.TestPartition.End;
-
-      try {
-        double rmsError, cvRmsError;
-        var lrSolution = HeuristicLab.Algorithms.DataAnalysis.LinearRegression.CreateLinearRegressionSolution(
-          lrProbData, out rmsError, out cvRmsError);
-        results["Solution"].Value = lrSolution;
-      } catch (Exception) {
-        // ignore
-      }
+      OnlineCalculatorError error;
+      double alpha;
+      double beta;
+      OnlineLinearScalingParameterCalculator.Calculate(filteredPredicted, filteredTarget, out alpha, out beta, out error);
+
+      var prod = new SimpleSymbol("*", "*", 2, 2).CreateTreeNode();
+      var sum = new SimpleSymbol("+", "+", 2, 2).CreateTreeNode();
+      var constAlpha = (ConstantTreeNode)(new Constant()).CreateTreeNode();
+      constAlpha.Value = alpha;
+      var constBeta = (ConstantTreeNode)(new Constant()).CreateTreeNode();
+      constBeta.Value = beta;
+
+      var originalTree = expressionNode.GetSubtree(0);
+      expressionNode.RemoveSubtree(0);
+      expressionNode.AddSubtree(sum);
+      sum.AddSubtree(prod);
+      sum.AddSubtree(constAlpha);
+      prod.AddSubtree(originalTree);
+      prod.AddSubtree(constBeta);
+
+      var model = new Model(bestTree, problemData.TargetVariable, problemData.AllowedInputVariables.ToArray());
+      model.Name = "Scaled Model";
+      model.Description = "Scaled Model";
+      results["Solution"].Value = model.CreateRegressionSolution(problemData);
+      results["ScaledTree"].Value = bestTree;
+
     }
 
Index: /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Solution.cs
===================================================================
--- /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Solution.cs	(revision 14310)
+++ /branches/HeuristicLab.Problems.GeneticProgramming.BloodGlucosePrediction/Solution.cs	(revision 14311)
@@ -132,12 +132,19 @@
     }
     public IEnumerable<double> EstimatedTrainingValues {
-      get { return GetEstimatedValues(ProblemData.TrainingIndices); }
+      get {
+        var all = EstimatedValues.ToArray();
+        return ProblemData.TrainingIndices.Select(r => all[r]);
+      }
     }
     public IEnumerable<double> EstimatedTestValues {
-      get { return GetEstimatedValues(ProblemData.TestIndices); }
+      get {
+        var all = EstimatedValues.ToArray();
+        return ProblemData.TestIndices.Select(r => all[r]);
+      }
     }
 
     public IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) {
-      return Model.GetEstimatedValues(ProblemData.Dataset, rows);
+      var all = Model.GetEstimatedValues(ProblemData.Dataset, ProblemData.AllIndices).ToArray();
+      return rows.Select(r => all[r]);
     }
 
