Index: /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/CoefficientOfDeterminationEvaluator.cs
===================================================================
--- /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/CoefficientOfDeterminationEvaluator.cs	(revision 1893)
+++ /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/CoefficientOfDeterminationEvaluator.cs	(revision 1894)
@@ -27,7 +27,15 @@
 using HeuristicLab.Data;
 using HeuristicLab.Operators;
+using HeuristicLab.Modeling;
 
 namespace HeuristicLab.GP.StructureIdentification {
-  public class CoefficientOfDeterminationEvaluator : GPEvaluatorBase {
+  public class CoefficientOfDeterminationEvaluator : SimpleGPEvaluatorBase {
+
+    public override string OutputVariableName {
+      get {
+        return "R2";
+      }
+    }
+    
     public override string Description {
       get {
@@ -37,54 +45,11 @@
     }
 
-    public CoefficientOfDeterminationEvaluator()
-      : base() {
-      AddVariableInfo(new VariableInfo("R2", "The coefficient of determination of the model", typeof(DoubleData), VariableKind.New));
-    }
+    public override double Evaluate(double[,] values) {
 
-    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, HeuristicLab.DataAnalysis.Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
-      double errorsSquaredSum = 0.0;
-      double originalDeviationTotalSumOfSquares = 0.0;
-      double targetMean = dataset.GetMean(targetVariable, start, end);
-
-      double originalSum = 0.0;
-      int n = 0;
-      for (int sample = start; sample < end; sample++) {
-        double estimated = evaluator.Evaluate(sample);
-        double original = dataset.GetValue(sample, targetVariable);
-        if (updateTargetValues) {
-          dataset.SetValue(sample, targetVariable, estimated);
-        }
-        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
-          double error = estimated - original;
-          errorsSquaredSum += error * error;
-
-          originalSum += original;
-          n++;
-        }
-      }
-
-      double originalMean = originalSum / n;
-      for(int sample = start; sample < end; sample++){
-        double original = dataset.GetValue(sample, targetVariable);
-        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
-          original = original - originalMean;
-          original = original * original;
-          originalDeviationTotalSumOfSquares += original;
-        }
-      }
-
-      double quality = 1 - errorsSquaredSum / originalDeviationTotalSumOfSquares;
-      if (quality > 1)
-        throw new InvalidProgramException();
+      double quality = SimpleR2Evaluator.Calculate(values);
       if (double.IsNaN(quality) || double.IsInfinity(quality))
         quality = double.MaxValue;
 
-      DoubleData r2 = GetVariableValue<DoubleData>("R2", scope, false, false);
-      if (r2 == null) {
-        r2 = new DoubleData();
-        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("R2"), r2));
-      }
-
-      r2.Data = quality;
+      return quality;
     }
   }
Index: /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanAbsolutePercentageErrorEvaluator.cs
===================================================================
--- /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanAbsolutePercentageErrorEvaluator.cs	(revision 1893)
+++ /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanAbsolutePercentageErrorEvaluator.cs	(revision 1894)
@@ -27,8 +27,15 @@
 using HeuristicLab.Data;
 using HeuristicLab.Operators;
+using HeuristicLab.Modeling;
 using HeuristicLab.DataAnalysis;
 
 namespace HeuristicLab.GP.StructureIdentification {
-  public class MeanAbsolutePercentageErrorEvaluator : GPEvaluatorBase {
+  public class MeanAbsolutePercentageErrorEvaluator : SimpleGPEvaluatorBase {
+    public override string OutputVariableName {
+      get {
+        return "MAPE";
+      }
+    }
+
     public override string Description {
       get {
@@ -38,38 +45,10 @@
     }
 
-    public MeanAbsolutePercentageErrorEvaluator()
-      : base() {
-      AddVariableInfo(new VariableInfo("MAPE", "The mean absolute percentage error of the model", typeof(DoubleData), VariableKind.New));
-    }
-
-    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
-      double errorsSum = 0.0;
-      int n = 0;
-      for (int sample = start; sample < end; sample++) {
-        double estimated = evaluator.Evaluate(sample);
-        double original = dataset.GetValue(sample, targetVariable);
-
-        if (updateTargetValues) {
-          dataset.SetValue(sample, targetVariable, estimated);
-        }
-
-        if (!double.IsNaN(original) && !double.IsInfinity(original) && original != 0.0) {
-          double percent_error = Math.Abs((estimated - original) / original);
-          errorsSum += percent_error;
-          n++;
-        }
-      }
-      double quality = errorsSum / n;
+    public override double Evaluate(double[,] values) {
+      double quality = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(values);
       if (double.IsNaN(quality) || double.IsInfinity(quality))
         quality = double.MaxValue;
 
-      // create a variable for the MAPE
-      DoubleData mape = GetVariableValue<DoubleData>("MAPE", scope, false, false);
-      if (mape == null) {
-        mape = new DoubleData();
-        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MAPE"), mape));
-      }
-
-      mape.Data = quality;
+      return quality;
     }
   }
Index: /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanAbsolutePercentageOfRangeErrorEvaluator.cs
===================================================================
--- /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanAbsolutePercentageOfRangeErrorEvaluator.cs	(revision 1893)
+++ /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanAbsolutePercentageOfRangeErrorEvaluator.cs	(revision 1894)
@@ -27,8 +27,14 @@
 using HeuristicLab.Data;
 using HeuristicLab.Operators;
+using HeuristicLab.Modeling;
 using HeuristicLab.DataAnalysis;
 
 namespace HeuristicLab.GP.StructureIdentification {
-  public class MeanAbsolutePercentageOfRangeErrorEvaluator : GPEvaluatorBase {
+  public class MeanAbsolutePercentageOfRangeErrorEvaluator : SimpleGPEvaluatorBase {
+    public override string OutputVariableName {
+      get {
+        return "MAPRE";
+      }
+    }
     public override string Description {
       get {
@@ -38,39 +44,10 @@
     }
 
-    public MeanAbsolutePercentageOfRangeErrorEvaluator()
-      : base() {
-      AddVariableInfo(new VariableInfo("MAPRE", "The mean absolute percentage range error of the model", typeof(DoubleData), VariableKind.New));
-    }
-
-    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
-      double errorsSum = 0.0;
-      int n = 0;
-      double range = dataset.GetRange(targetVariable, start, end);
-      for (int sample = start; sample < end; sample++) {
-        double estimated = evaluator.Evaluate(sample);
-        double original = dataset.GetValue(sample, targetVariable);
-
-        if (updateTargetValues) {
-          dataset.SetValue(sample, targetVariable, estimated);
-        }
-
-        if (!double.IsNaN(original) && !double.IsInfinity(original) && original != 0.0) {
-          double percent_error = Math.Abs((estimated - original) / range);
-          errorsSum += percent_error;
-          n++;
-        }
-      }
-      double quality = errorsSum / n;
+    public override double Evaluate(double[,] values) {
+      double quality = SimpleMeanAbsolutePercentageOfRangeErrorEvaluator.Calculate(values);
       if (double.IsNaN(quality) || double.IsInfinity(quality))
         quality = double.MaxValue;
 
-      // create a variable for the MAPRE
-      DoubleData mapre = GetVariableValue<DoubleData>("MAPRE", scope, false, false);
-      if (mapre == null) {
-        mapre = new DoubleData();
-        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MAPRE"), mapre));
-      }
-
-      mapre.Data = quality;
+      return quality;
     }
   }
Index: /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanSquaredErrorEvaluator.cs
===================================================================
--- /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanSquaredErrorEvaluator.cs	(revision 1893)
+++ /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/MeanSquaredErrorEvaluator.cs	(revision 1894)
@@ -28,7 +28,13 @@
 using HeuristicLab.Operators;
 using HeuristicLab.DataAnalysis;
+using HeuristicLab.Modeling;
 
 namespace HeuristicLab.GP.StructureIdentification {
-  public class MeanSquaredErrorEvaluator : GPEvaluatorBase {
+  public class MeanSquaredErrorEvaluator : SimpleGPEvaluatorBase {
+    public override string OutputVariableName {
+      get {
+        return "MSE";
+      }
+    }
     public override string Description {
       get {
@@ -38,37 +44,12 @@
     }
 
-    public MeanSquaredErrorEvaluator()
-      : base() {
-      AddVariableInfo(new VariableInfo("MSE", "The mean squared error of the model", typeof(DoubleData), VariableKind.New));
-    }
+    public override double Evaluate(double[,] values) {
+      double quality = SimpleMSEEvaluator.Calculate(values);
 
-    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
-      double errorsSquaredSum = 0;
-      int n = 0;
-      for (int sample = start; sample < end; sample++) {
-        double original = dataset.GetValue(sample, targetVariable);
-        double estimated = evaluator.Evaluate(sample);
-        if (updateTargetValues) {
-          dataset.SetValue(sample, targetVariable, estimated);
-        }
-        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
-          double error = estimated - original;
-          errorsSquaredSum += error * error;
-          n++;
-        }
+      if (double.IsNaN(quality) || double.IsInfinity(quality)) {
+        quality = double.MaxValue;
       }
 
-      errorsSquaredSum /= n;
-      if (double.IsNaN(errorsSquaredSum) || double.IsInfinity(errorsSquaredSum)) {
-        errorsSquaredSum = double.MaxValue;
-      }
-
-      DoubleData mse = GetVariableValue<DoubleData>("MSE", scope, false, false);
-      if (mse == null) {
-        mse = new DoubleData();
-        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("MSE"), mse));
-      }
-
-      mse.Data = errorsSquaredSum;
+      return quality;
     }
   }
Index: /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/SimpleGPEvaluatorBase.cs
===================================================================
--- /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/SimpleGPEvaluatorBase.cs	(revision 1894)
+++ /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/SimpleGPEvaluatorBase.cs	(revision 1894)
@@ -0,0 +1,67 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Operators;
+using HeuristicLab.DataAnalysis;
+
+namespace HeuristicLab.GP.StructureIdentification {
+  public abstract class SimpleGPEvaluatorBase : GPEvaluatorBase {
+    public virtual string OutputVariableName { get { return "Quality"; } }
+
+    public SimpleGPEvaluatorBase()
+      : base() {
+      AddVariableInfo(new VariableInfo(OutputVariableName, OutputVariableName, typeof(DoubleData), VariableKind.New | VariableKind.Out));
+    }
+
+    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
+      // store original and estimated values in a double array
+      double[,] values = new double[end - start, 2];
+      for (int sample = start; sample < end; sample++) {
+        double original = dataset.GetValue(sample, targetVariable);
+        double estimated = evaluator.Evaluate(sample);
+        if (updateTargetValues) {
+          dataset.SetValue(sample, targetVariable, estimated);
+        }
+        values[sample - start, 0] = estimated;
+        values[sample - start, 1] = original;
+      }
+
+      double quality = Evaluate(values);
+
+      DoubleData qualityData = GetVariableValue<DoubleData>(OutputVariableName, scope, false, false);
+      if (qualityData == null) {
+        qualityData = new DoubleData();
+        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(OutputVariableName), qualityData));
+      }
+
+      qualityData.Data = quality;
+
+    }
+
+    public abstract double Evaluate(double[,] values);
+  }
+}
Index: /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VarianceAccountedForEvaluator.cs
===================================================================
--- /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VarianceAccountedForEvaluator.cs	(revision 1893)
+++ /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/Evaluators/VarianceAccountedForEvaluator.cs	(revision 1894)
@@ -28,7 +28,18 @@
 using HeuristicLab.Operators;
 using HeuristicLab.DataAnalysis;
+using HeuristicLab.Modeling;
 
 namespace HeuristicLab.GP.StructureIdentification {
-  public class VarianceAccountedForEvaluator : GPEvaluatorBase {
+  /// <summary>
+  /// The Variance Accounted For (VAF) function calculates is computed as
+  /// VAF(y,y') = ( 1 - var(y-y')/var(y) )
+  /// where y' denotes the predicted / modelled values for y and var(x) the variance of a signal x.
+  /// </summary>
+  public class VarianceAccountedForEvaluator : SimpleGPEvaluatorBase {
+    public override string OutputVariableName {
+      get {
+        return "VAF";
+      }
+    }
     public override string Description {
       get {
@@ -42,47 +53,11 @@
     }
 
-    /// <summary>
-    /// The Variance Accounted For (VAF) function calculates is computed as
-    /// VAF(y,y') = ( 1 - var(y-y')/var(y) )
-    /// where y' denotes the predicted / modelled values for y and var(x) the variance of a signal x.
-    /// </summary>
-    public VarianceAccountedForEvaluator()
-      : base() {
-      AddVariableInfo(new VariableInfo("VAF", "The variance-accounted-for quality of the model", typeof(DoubleData), VariableKind.New));
-
-    }
-
-    public override void Evaluate(IScope scope, ITreeEvaluator evaluator, Dataset dataset, int targetVariable, int start, int end, bool updateTargetValues) {
-      int nSamples = end - start;
-      double[] errors = new double[nSamples];
-      double[] originalTargetVariableValues = new double[nSamples];
-      for (int sample = start; sample < end; sample++) {
-        double estimated = evaluator.Evaluate(sample);
-        double original = dataset.GetValue(sample, targetVariable);
-        if (updateTargetValues) {
-          dataset.SetValue(sample, targetVariable, estimated);
-        }
-        if (!double.IsNaN(original) && !double.IsInfinity(original)) {
-          errors[sample - start] = original - estimated;
-          originalTargetVariableValues[sample - start] = original;
-        } else {
-          errors[sample - start] = double.NaN;
-          originalTargetVariableValues[sample - start] = double.NaN;
-        }
-      }
-      double errorsVariance = Statistics.Variance(errors);
-      double originalsVariance = Statistics.Variance(originalTargetVariableValues);
-      double quality = 1 - errorsVariance / originalsVariance;
+    public override double Evaluate(double[,] values) {
+      double quality = SimpleVarianceAccountedForEvaluator.Calculate(values);
 
       if (double.IsNaN(quality) || double.IsInfinity(quality)) {
         quality = double.MaxValue;
       }
-      DoubleData vaf = GetVariableValue<DoubleData>("VAF", scope, false, false);
-      if (vaf == null) {
-        vaf = new DoubleData();
-        scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("VAF"), vaf));
-      }
-
-      vaf.Data = quality;
+      return quality;
     }
   }
Index: /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj
===================================================================
--- /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj	(revision 1893)
+++ /trunk/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj	(revision 1894)
@@ -89,4 +89,5 @@
     <Compile Include="Constant.cs" />
     <Compile Include="AlgorithmBase.cs" />
+    <Compile Include="Evaluators\SimpleGPEvaluatorBase.cs" />
     <Compile Include="TreeEvaluatorBase.cs" />
     <Compile Include="HL2TreeEvaluator.cs" />
