Index: branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs
===================================================================
--- branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs	(revision 15831)
+++ branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs	(revision 16001)
@@ -54,4 +54,13 @@
     }
 
+    //The PerasonsR²-Calculator is the default, but can be overwritten to any other IOnlineCalculator
+    //Just remember to reset it after you're done
+    private static IOnlineCalculator calculator = new OnlinePearsonsRSquaredCalculator();
+    public IOnlineCalculator Calculator
+    {
+      get { return calculator; }
+      set { calculator = value; }
+    }
+
     private const string ReplacementParameterName = "Replacement Method";
     private const string DataPartitionParameterName = "DataPartition";
@@ -113,8 +122,5 @@
       ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
-      Func<double, string, bool> progressCallback = null,
-      IOnlineCalculator calculator = null) {
-      //PearsonsRSquared is the default calculator
-      if (calculator == null) { calculator = new OnlinePearsonsRSquaredCalculator(); }
+      Func<double, string, bool> progressCallback = null) {
       IEnumerable<int> rows;
 
@@ -133,5 +139,5 @@
       }
 
-      return CalculateImpacts(model, problemData, estimatedValues, rows, calculator, replacementMethod, factorReplacementMethod, progressCallback);
+      return CalculateImpacts(model, problemData, estimatedValues, rows, replacementMethod, factorReplacementMethod, progressCallback);
     }
 
@@ -141,5 +147,4 @@
      IEnumerable<double> estimatedValues,
      IEnumerable<int> rows,
-     IOnlineCalculator calculator,
      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
      FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
@@ -149,5 +154,5 @@
       double originalValue = -1;
 
-      PrepareData(rows, problemData, estimatedValues, out targetValues, out originalValue, calculator);
+      PrepareData(rows, problemData, estimatedValues, out targetValues, out originalValue);
 
       var impacts = new Dictionary<string, double>();
@@ -166,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, calculator, replacementMethod, factorReplacementMethod);
+        impacts[inputVariable] = CalculateImpact(inputVariable, model, problemData.Dataset, rows, targetValues, originalValue, replacementMethod, factorReplacementMethod);
       }
 
@@ -177,9 +182,8 @@
       IEnumerable<double> targetValues,
       double originalValue,
-      IOnlineCalculator calculator,
       DataPartitionEnum data = DataPartitionEnum.Training,
       ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best) {
-      return CalculateImpact(variableName, solution.Model, solution.ProblemData.Dataset, rows, targetValues, originalValue, calculator, replacementMethod, factorReplacementMethod);
+      return CalculateImpact(variableName, solution.Model, solution.ProblemData.Dataset, rows, targetValues, originalValue, replacementMethod, factorReplacementMethod);
     }
 
@@ -190,5 +194,4 @@
       IEnumerable<double> targetValues,
       double originalValue,
-      IOnlineCalculator calculator,
       ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best) {
@@ -199,7 +202,7 @@
       // calculate impacts for double variables
       if (dataset.VariableHasType<double>(variableName)) {
-        impact = CalculateImpactForDouble(variableName, model, modifiableDataset, rows, targetValues, originalValue, replacementMethod, calculator);
+        impact = CalculateImpactForDouble(variableName, model, modifiableDataset, rows, targetValues, originalValue, replacementMethod);
       } else if (dataset.VariableHasType<string>(variableName)) {
-        impact = CalculateImpactForString(variableName, model, dataset, modifiableDataset, rows, targetValues, originalValue, factorReplacementMethod, calculator);
+        impact = CalculateImpactForString(variableName, model, dataset, modifiableDataset, rows, targetValues, originalValue, factorReplacementMethod);
       } else {
         throw new NotSupportedException("Variable not supported");
@@ -212,6 +215,5 @@
       IEnumerable<double> estimatedValues,
       out IEnumerable<double> targetValues,
-      out double originalValue,
-      IOnlineCalculator calculator) {
+      out double originalValue) {
       OnlineCalculatorError error;
 
@@ -219,5 +221,5 @@
       targetValues = rows.Select(v => targetVariableValueList.ElementAt(v));
       var estimatedValuesPartition = rows.Select(v => estimatedValues.ElementAt(v));
-      originalValue = calculator.CalculateValue(targetValues, estimatedValuesPartition, out error);
+      originalValue = CalculateValue(targetValues, estimatedValuesPartition, out error);
 
       if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation.");
@@ -230,9 +232,8 @@
       IEnumerable<double> targetValues,
       double originalValue,
-      ReplacementMethodEnum replacementMethod,
-      IOnlineCalculator calculator) {
+      ReplacementMethodEnum replacementMethod) {
       OnlineCalculatorError error;
       var newEstimates = EvaluateModelWithReplacedVariable(model, variableName, modifiableDataset, rows, replacementMethod);
-      var newValue = calculator.CalculateValue(targetValues, newEstimates, out error);
+      var newValue = CalculateValue(targetValues, newEstimates, out error);
       if (error != OnlineCalculatorError.None) { throw new InvalidOperationException("Error during calculation with replaced inputs."); }
       return originalValue - newValue;
@@ -246,6 +247,5 @@
       IEnumerable<double> targetValues,
       double originalValue,
-      FactorReplacementMethodEnum factorReplacementMethod,
-      IOnlineCalculator calculator) {
+      FactorReplacementMethodEnum factorReplacementMethod) {
 
       OnlineCalculatorError error;
@@ -256,5 +256,5 @@
           var originalValues = modifiableDataset.GetReadOnlyStringValues(variableName).ToList();
           var newEstimates = EvaluateModelWithReplacedVariable(originalValues, model, variableName, modifiableDataset, rows, Enumerable.Repeat(repl, problemData.Rows).ToList());
-          var newValue = calculator.CalculateValue(targetValues, newEstimates, out error);
+          var newValue = CalculateValue(targetValues, newEstimates, out error);
           if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation with replaced inputs.");
 
@@ -267,5 +267,5 @@
         // calculate impacts for factor variables
         var newEstimates = EvaluateModelWithReplacedVariable(model, variableName, modifiableDataset, rows, factorReplacementMethod);
-        var newValue = calculator.CalculateValue(targetValues, newEstimates, out error);
+        var newValue = CalculateValue(targetValues, newEstimates, out error);
         if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation with replaced inputs.");
 
@@ -366,4 +366,16 @@
       return estimates;
     }
+
+    private static double CalculateValue(IEnumerable<double> targets, IEnumerable<double> estimates, out OnlineCalculatorError error) {
+      calculator.Reset();
+      if (targets.Count() != estimates.Count()) {
+        throw new ArgumentException(string.Format("Targets and Estimates must be of equal length ({0},{1})", targets.Count(), estimates.Count()));
+      }
+      foreach (var entry in targets.Zip(estimates, (target, estimate) => new { target, estimate })) {
+        calculator.Add(entry.target, entry.estimate);
+      }
+      error = calculator.ErrorState;
+      return calculator.Value;
+    }
   }
 }
