Index: branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs
===================================================================
--- branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs	(revision 16018)
+++ branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs	(revision 16020)
@@ -37,6 +37,4 @@
   [Item("RegressionSolution Impacts Calculator", "Calculation of the impacts of input variables for any regression solution")]
   public sealed class RegressionSolutionVariableImpactsCalculator : ParameterizedNamedItem {
-    private static IOnlineCalculator calculator = new OnlinePearsonsRSquaredCalculator();
-
     public enum ReplacementMethodEnum {
       Median,
@@ -112,5 +110,5 @@
     public static IEnumerable<Tuple<string, double>> CalculateImpacts(
       IRegressionSolution solution,
-      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
+      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
       DataPartitionEnum data = DataPartitionEnum.Training,
@@ -123,5 +121,5 @@
       IRegressionProblemData problemData,
       IEnumerable<double> estimatedValues,
-      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
+      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
       DataPartitionEnum data = DataPartitionEnum.Training,
@@ -151,12 +149,12 @@
      IEnumerable<double> estimatedValues,
      IEnumerable<int> rows,
-     ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
+     ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
      FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
      Func<double, string, bool> progressCallback = null) {
 
       IEnumerable<double> targetValues;
-      double originalValue = -1;
-
-      PrepareData(rows, problemData, estimatedValues, out targetValues, out originalValue);
+      double originalCalculatorValue = -1;
+
+      PrepareData(rows, problemData, estimatedValues, out targetValues, out originalCalculatorValue);
 
       var impacts = new Dictionary<string, double>();
@@ -165,5 +163,5 @@
 
       int curIdx = 0;
-      int count = allowedInputVariables.Count();
+      int count = allowedInputVariables.Count(v => problemData.Dataset.VariableHasType<double>(v) || problemData.Dataset.VariableHasType<string>(v));
 
       foreach (var inputVariable in allowedInputVariables) {
@@ -173,5 +171,5 @@
           if (progressCallback((double)curIdx / count, string.Format("Calculating impact for variable {0} ({1} of {2})", inputVariable, curIdx, count))) { return null; }
         }
-        impacts[inputVariable] = CalculateImpact(inputVariable, model, problemData.Dataset, rows, targetValues, originalValue, replacementMethod, factorReplacementMethod);
+        impacts[inputVariable] = CalculateImpact(inputVariable, model, problemData.Dataset, rows, targetValues, originalCalculatorValue, replacementMethod, factorReplacementMethod);
       }
 
@@ -184,5 +182,5 @@
       IEnumerable<double> targetValues,
       double originalValue,
-      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
+      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
       DataPartitionEnum data = DataPartitionEnum.Training) {
@@ -196,5 +194,5 @@
       IEnumerable<double> targetValues,
       double originalValue,
-      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
+      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best) {
 
@@ -276,5 +274,5 @@
     }
 
-    private static IEnumerable<double> EvaluateModelWithReplacedVariable(IRegressionModel model, string variable, ModifiableDataset dataset, IEnumerable<int> rows, ReplacementMethodEnum replacement = ReplacementMethodEnum.Median) {
+    private static IEnumerable<double> EvaluateModelWithReplacedVariable(IRegressionModel model, string variable, ModifiableDataset dataset, IEnumerable<int> rows, ReplacementMethodEnum replacement = ReplacementMethodEnum.Shuffle) {
       var originalValues = dataset.GetReadOnlyDoubleValues(variable).ToList();
       double replacementValue;
@@ -369,27 +367,25 @@
     }
 
-    private static double CalculateValue(IEnumerable<double> targets, IEnumerable<double> estimates, out OnlineCalculatorError error) {
-      calculator.Reset();
-
-      var targetsEnumerator = targets.GetEnumerator();
-      var estimatesEnumerator = estimates.GetEnumerator();
-
-      bool targetsHasNextValue = targetsEnumerator.MoveNext();
-      bool estimatesHasNextValue = estimatesEnumerator.MoveNext();
-
-      while (targetsHasNextValue && estimatesHasNextValue) {
-        calculator.Add(targetsEnumerator.Current, estimatesEnumerator.Current);
-        targetsHasNextValue = targetsEnumerator.MoveNext();
-        estimatesHasNextValue = estimatesEnumerator.MoveNext();
-      }
-
-      //Check if there is an equal quantity of targets and estimates
-      if (targetsHasNextValue != estimatesHasNextValue) {
-        throw new ArgumentException(string.Format("Targets and Estimates must be of equal length ({0},{1})", targets.Count(), estimates.Count()));
-
-      }
-
-      error = calculator.ErrorState;
-      return calculator.Value;
+    private static double CalculateValue(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
+      IEnumerator<double> firstEnumerator = originalValues.GetEnumerator();
+      IEnumerator<double> secondEnumerator = estimatedValues.GetEnumerator();
+      var calculator = new OnlinePearsonsRSquaredCalculator();
+
+      // always move forward both enumerators (do not use short-circuit evaluation!)
+      while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
+        double original = firstEnumerator.Current;
+        double estimated = secondEnumerator.Current;
+        calculator.Add(original, estimated);
+        if (calculator.ErrorState != OnlineCalculatorError.None) break;
+      }
+
+      // check if both enumerators are at the end to make sure both enumerations have the same length
+      if (calculator.ErrorState == OnlineCalculatorError.None &&
+           (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
+        throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
+      } else {
+        errorState = calculator.ErrorState;
+        return calculator.Value;
+      }
     }
   }
