Index: branches/HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator/SymbolicRegressionSingleObjectiveOSGAEvaluator.cs
===================================================================
--- branches/HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator/SymbolicRegressionSingleObjectiveOSGAEvaluator.cs	(revision 14301)
+++ branches/HeuristicLab.OSGAEvaluator/HeuristicLab.OSGAEvaluator/SymbolicRegressionSingleObjectiveOSGAEvaluator.cs	(revision 14302)
@@ -22,4 +22,5 @@
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using HeuristicLab.Common;
@@ -195,6 +196,6 @@
 
     private double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, DoubleLimit estimationLimits, IRegressionProblemData problemData, IEnumerable<int> rows) {
-      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows).LimitToRange(estimationLimits.Lower, estimationLimits.Upper);
-      var targetValues = problemData.Dataset.GetReadOnlyDoubleValues(problemData.TargetVariable);
+      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
+      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows).ToList();
 
       var parentQualities = ParentQualitiesParameter.ActualValue.Select(x => x.Value);
@@ -204,8 +205,9 @@
       var parentQuality = minQuality + (maxQuality - minQuality) * comparisonFactor;
 
-      var e = estimatedValues.GetEnumerator();
+
 
       #region fixed intervals
       if (UseFixedEvaluationIntervals) {
+        var e = estimatedValues.GetEnumerator();
         double threshold = parentQuality * RelativeParentChildQualityThreshold;
         if (UseAdaptiveQualityThreshold) {
@@ -290,49 +292,51 @@
           return actualQuality;
         }
-        #endregion
+      #endregion
       } else {
-        var trainingPartitionSize = problemData.TrainingPartition.Size;
-        var interval = (int)Math.Floor(trainingPartitionSize * RelativeFitnessEvaluationIntervalSize);
-        double quality = double.NaN;
-        var estimated = new List<double>(); // save estimated values in a list so we don't re-evaluate 
-        // use the actual estimated values for the first i * interval rows of the training partition and and assume the remaining rows are perfectly correlated
-        // if the quality of the individual still falls below the parent quality, then we can reject it sooner, otherwise as i increases the whole estimated series will be used
         var lsc = new OnlineLinearScalingParameterCalculator();
         var rcalc = new OnlinePearsonsRCalculator();
-        var actualQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, SymbolicExpressionTreeParameter.ActualValue, estimationLimits.Lower, estimationLimits.Upper, problemData, problemData.TrainingIndices, false);
-        for (int i = 0; i < trainingPartitionSize; i += interval) {
-          var start = problemData.TrainingPartition.Start;
-          int end = Math.Min(trainingPartitionSize, i + interval);
-          // cache estimated values 
-          // scale target values to the range of the estimated values
-          for (int j = i; j < end && e.MoveNext(); ++j) {
-            estimated.Add(e.Current);
-            var index = j + start;
-            // in the context of the linear scaling calculator, the target value becomes the "original" 
-            // while the estimated value becomes the "target" (because we want to scale the target in the range of the estimated)
-            lsc.Add(targetValues[index], e.Current);
-          }
-          var a = lsc.Alpha; // additive scaling term
-          var b = lsc.Beta;  // multiplicative scaling factor
-          // calculate the quality
-          for (int j = i; j < end; ++j) {
-            var index = j + start;
-            rcalc.Add(estimated[j], targetValues[index]);
-          }
-          var rcalc2 = (OnlinePearsonsRCalculator)rcalc.Clone();
-          for (int j = end; j < trainingPartitionSize; ++j) {
-            var index = j + start;
-            var v = targetValues[index] * b + a;
-            rcalc2.Add(v, targetValues[index]);
-          }
-          var r = rcalc2.ErrorState == OnlineCalculatorError.None ? rcalc2.R : double.NaN;
+        var actualQuality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, SymbolicExpressionTreeParameter.ActualValue, estimationLimits.Lower, estimationLimits.Upper, problemData, rows, true);
+
+        var values = estimatedValues.Zip(targetValues, (es, t) => new { Estimated = es, Target = t });
+        int calculatedRows = 0;
+        double quality = 0.0;
+
+        foreach (var value in values) {
+          lsc.Add(value.Estimated, value.Target);
+          rcalc.Add(value.Estimated, value.Target);
+          calculatedRows++;
+
+          if (calculatedRows % 5 == 0) {
+            var alpha = lsc.Alpha;
+            var beta = lsc.Beta;
+
+            OnlinePearsonsRCalculator calc = (OnlinePearsonsRCalculator)rcalc.Clone();
+            foreach (var t in targetValues.Skip(calculatedRows)) {
+              var scaledTarget = (t - alpha) / beta;
+              calc.Add(scaledTarget, t);
+            }
+
+            var r = calc.ErrorState == OnlineCalculatorError.None ? calc.R : double.NaN;
+            quality = r * r;
+
+            if (quality < parentQuality && actualQuality > parentQuality) {
+              Debugger.Break();
+            }
+            if (quality < parentQuality) return quality;
+          }
+        }
+
+        //calculate quality for all rows
+        {
+          var r = rcalc.ErrorState == OnlineCalculatorError.None ? rcalc.R : double.NaN;
           quality = r * r;
-          bool falseReject = false;
-          if (!(quality > parentQuality)) {
-            if (actualQuality > parentQuality)
-              falseReject = true;
-          }
-          //          if (!(quality > parentQuality))
-          //            break;
+          if (quality < parentQuality && actualQuality > parentQuality) {
+            Debugger.Break();
+          }
+          if (double.IsNaN(quality)) quality = 0.0;
+          if (quality != actualQuality) Debugger.Break();
+
+          //necessary due to rounding errors and diff in the range of 10E-8
+          quality = actualQuality;
         }
 
