Index: /branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs
===================================================================
--- /branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs	(revision 16034)
+++ /branches/2904_CalculateImpacts/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs	(revision 16035)
@@ -37,4 +37,5 @@
   [Item("RegressionSolution Impacts Calculator", "Calculation of the impacts of input variables for any regression solution")]
   public sealed class RegressionSolutionVariableImpactsCalculator : ParameterizedNamedItem {
+    #region Parameters/Properties
     public enum ReplacementMethodEnum {
       Median,
@@ -80,14 +81,11 @@
       set { DataPartitionParameter.Value.Value = value; }
     }
-
-
+    #endregion
+
+    #region Ctor/Cloner
     [StorableConstructor]
     private RegressionSolutionVariableImpactsCalculator(bool deserializing) : base(deserializing) { }
     private RegressionSolutionVariableImpactsCalculator(RegressionSolutionVariableImpactsCalculator original, Cloner cloner)
       : base(original, cloner) { }
-    public override IDeepCloneable Clone(Cloner cloner) {
-      return new RegressionSolutionVariableImpactsCalculator(this, cloner);
-    }
-
     public RegressionSolutionVariableImpactsCalculator()
       : base() {
@@ -97,4 +95,10 @@
     }
 
+    public override IDeepCloneable Clone(Cloner cloner) {
+      return new RegressionSolutionVariableImpactsCalculator(this, cloner);
+    }
+    #endregion
+
+    #region Public Methods/Wrappers
     //mkommend: annoying name clash with static method, open to better naming suggestions
     public IEnumerable<Tuple<string, double>> Calculate(IRegressionSolution solution) {
@@ -106,6 +110,6 @@
       ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
-      DataPartitionEnum data = DataPartitionEnum.Training) {
-      return CalculateImpacts(solution.Model, solution.ProblemData, solution.EstimatedValues, replacementMethod, factorReplacementMethod, data);
+      DataPartitionEnum dataPartition = DataPartitionEnum.Training) {
+      return CalculateImpacts(solution.Model, solution.ProblemData, solution.EstimatedValues, replacementMethod, factorReplacementMethod, dataPartition);
     }
 
@@ -116,60 +120,7 @@
       ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
-      DataPartitionEnum data = DataPartitionEnum.Training) {
-      IEnumerable<int> rows;
-
-      switch (data) {
-        case DataPartitionEnum.All:
-          rows = problemData.AllIndices;
-          break;
-        case DataPartitionEnum.Test:
-          rows = problemData.TestIndices;
-          break;
-        case DataPartitionEnum.Training:
-          rows = problemData.TrainingIndices;
-          break;
-        default:
-          throw new NotSupportedException("DataPartition not supported");
-      }
-
+      DataPartitionEnum dataPartition = DataPartitionEnum.Training) {
+      IEnumerable<int> rows = GetPartitionRows(dataPartition, problemData);
       return CalculateImpacts(model, problemData, estimatedValues, rows, replacementMethod, factorReplacementMethod);
-    }
-
-    public static double CalculateImpact(string variableName, IRegressionModel model, IRegressionProblemData problemData, IEnumerable<double> estimatedValues, DataPartitionEnum dataPartition, ReplacementMethodEnum replMethod, FactorReplacementMethodEnum factorReplMethod) {
-      double impact = 0;
-
-      IEnumerable<int> rows;
-      switch (dataPartition) {
-        case DataPartitionEnum.All:
-          rows = problemData.AllIndices;
-          break;
-        case DataPartitionEnum.Test:
-          rows = problemData.TestIndices;
-          break;
-        case DataPartitionEnum.Training:
-          rows = problemData.TrainingIndices;
-          break;
-        default:
-          throw new NotSupportedException("DataPartition not supported");
-      }
-
-      OnlineCalculatorError error;
-      IEnumerable<double> targetValuesPartition = rows.Select(v => problemData.TargetVariableValues.ElementAt(v));
-      IEnumerable<double> estimatedValuesPartition = rows.Select(v => estimatedValues.ElementAt(v));
-      var originalCalculatorValue = CalculateVariableImpact(targetValuesPartition, estimatedValuesPartition, out error);
-      if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation.");
-
-
-      var modifiableDataset = ((Dataset)(problemData.Dataset).Clone()).ToModifiable();
-
-      // calculate impacts for double variables
-      if (problemData.Dataset.VariableHasType<double>(variableName)) {
-        impact = CalculateImpactForNumericalVariables(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod);
-      } else if (problemData.Dataset.VariableHasType<string>(variableName)) {
-        impact = CalculateImpactForFactorVariables(variableName, model, problemData.Dataset, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, factorReplMethod);
-      } else {
-        throw new NotSupportedException("Variable not supported");
-      }
-      return impact;
     }
 
@@ -191,7 +142,8 @@
       var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(model.VariablesUsedForPrediction));
       var allowedInputVariables = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).ToList();
+      var modifiableDataset = ((Dataset)(problemData.Dataset).Clone()).ToModifiable();
 
       foreach (var inputVariable in allowedInputVariables) {
-        impacts[inputVariable] = CalculateImpact(inputVariable, model, problemData.Dataset, rows, targetValuesPartition, originalCalculatorValue, replacementMethod, factorReplacementMethod);
+        impacts[inputVariable] = CalculateImpact(inputVariable, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replacementMethod, factorReplacementMethod);
       }
 
@@ -200,17 +152,6 @@
 
     public static double CalculateImpact(string variableName,
-      IRegressionSolution solution,
-      IEnumerable<int> rows,
-      IEnumerable<double> targetValues,
-      double originalValue,
-      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Shuffle,
-      FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
-      DataPartitionEnum data = DataPartitionEnum.Training) {
-      return CalculateImpact(variableName, solution.Model, solution.ProblemData.Dataset, rows, targetValues, originalValue, replacementMethod, factorReplacementMethod);
-    }
-
-    public static double CalculateImpact(string variableName,
-      IRegressionModel model,
-      IDataset dataset,
+      IRegressionModel model,
+      ModifiableDataset modifiableDataset,
       IEnumerable<int> rows,
       IEnumerable<double> targetValues,
@@ -220,11 +161,10 @@
 
       double impact = 0;
-      var modifiableDataset = ((Dataset)(dataset).Clone()).ToModifiable();
 
       // calculate impacts for double variables
-      if (dataset.VariableHasType<double>(variableName)) {
+      if (modifiableDataset.VariableHasType<double>(variableName)) {
         impact = CalculateImpactForNumericalVariables(variableName, model, modifiableDataset, rows, targetValues, originalValue, replacementMethod);
-      } else if (dataset.VariableHasType<string>(variableName)) {
-        impact = CalculateImpactForFactorVariables(variableName, model, dataset, modifiableDataset, rows, targetValues, originalValue, factorReplacementMethod);
+      } else if (modifiableDataset.VariableHasType<string>(variableName)) {
+        impact = CalculateImpactForFactorVariables(variableName, model, modifiableDataset, rows, targetValues, originalValue, factorReplacementMethod);
       } else {
         throw new NotSupportedException("Variable not supported");
@@ -232,4 +172,5 @@
       return impact;
     }
+    #endregion
 
     private static double CalculateImpactForNumericalVariables(string variableName,
@@ -249,5 +190,4 @@
     private static double CalculateImpactForFactorVariables(string variableName,
       IRegressionModel model,
-      IDataset problemData,
       ModifiableDataset modifiableDataset,
       IEnumerable<int> rows,
@@ -260,7 +200,7 @@
         // try replacing with all possible values and find the best replacement value
         var smallestImpact = double.PositiveInfinity;
-        foreach (var repl in problemData.GetStringValues(variableName, rows).Distinct()) {
+        foreach (var repl in modifiableDataset.GetStringValues(variableName, rows).Distinct()) {
           var originalValues = modifiableDataset.GetReadOnlyStringValues(variableName).ToList();
-          var newEstimates = GetReplacedValues(originalValues, model, variableName, modifiableDataset, rows, Enumerable.Repeat(repl, problemData.Rows).ToList());
+          var newEstimates = GetReplacedEstimates(originalValues, model, variableName, modifiableDataset, rows, Enumerable.Repeat(repl, modifiableDataset.Rows).ToList());
           var newValue = CalculateVariableImpact(targetValues, newEstimates, out error);
           if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation with replaced inputs.");
@@ -330,5 +270,5 @@
       }
 
-      return GetReplacedValues(originalValues, model, variable, dataset, rows, replacementValues);
+      return GetReplacedEstimates(originalValues, model, variable, dataset, rows, replacementValues);
     }
 
@@ -368,8 +308,8 @@
       }
 
-      return GetReplacedValues(originalValues, model, variable, dataset, rows, replacementValues);
-    }
-
-    private static IEnumerable<double> GetReplacedValues(
+      return GetReplacedEstimates(originalValues, model, variable, dataset, rows, replacementValues);
+    }
+
+    private static IEnumerable<double> GetReplacedEstimates(
       IList originalValues,
       IRegressionModel model,
@@ -386,5 +326,5 @@
     }
 
-    private static double CalculateVariableImpact(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
+    public static double CalculateVariableImpact(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
       IEnumerator<double> firstEnumerator = originalValues.GetEnumerator();
       IEnumerator<double> secondEnumerator = estimatedValues.GetEnumerator();
@@ -408,4 +348,24 @@
       }
     }
+
+    public static IEnumerable<int> GetPartitionRows(DataPartitionEnum dataPartition, IRegressionProblemData problemData) {
+      IEnumerable<int> rows;
+
+      switch (dataPartition) {
+        case DataPartitionEnum.All:
+          rows = problemData.AllIndices;
+          break;
+        case DataPartitionEnum.Test:
+          rows = problemData.TestIndices;
+          break;
+        case DataPartitionEnum.Training:
+          rows = problemData.TrainingIndices;
+          break;
+        default:
+          throw new NotSupportedException("DataPartition not supported");
+      }
+
+      return rows;
+    }
   }
 }
Index: /branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
===================================================================
--- /branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs	(revision 16034)
+++ /branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs	(revision 16035)
@@ -160,12 +160,21 @@
       int count = originalVariableOrdering.Count;
       int i = 0;
-
-      foreach (var variable in originalVariableOrdering) {
+      var modifiableDataset = ((Dataset)(problemData.Dataset).Clone()).ToModifiable();
+      IEnumerable<int> rows = RegressionSolutionVariableImpactsCalculator.GetPartitionRows(dataPartition, problemData);
+
+      //Calculate original quality-values (via calculator, default is R²)
+      OnlineCalculatorError error;
+      IEnumerable<double> targetValuesPartition = rows.Select(v => problemData.TargetVariableValues.ElementAt(v));
+      IEnumerable<double> estimatedValuesPartition = rows.Select(v => estimatedValues.ElementAt(v));
+      var originalCalculatorValue = RegressionSolutionVariableImpactsCalculator.CalculateVariableImpact(targetValuesPartition, estimatedValuesPartition, out error);
+      if (error != OnlineCalculatorError.None) throw new InvalidOperationException("Error during calculation.");
+
+      foreach (var variableName in originalVariableOrdering) {
         if (cancellationToken.Token.IsCancellationRequested) { return null; }
         progress.ProgressValue = (double)++i / count;
-        progress.Status = string.Format("Calculating impact for variable {0} ({1} of {2})", variable, i, count);
-
-        double impact = RegressionSolutionVariableImpactsCalculator.CalculateImpact(variable, model, problemData, Content.EstimatedValues, dataPartition, replMethod, factorReplMethod);
-        impacts.Add(new Tuple<string, double>(variable, impact));
+        progress.Status = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
+
+        double impact = RegressionSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, modifiableDataset, rows, targetValuesPartition, originalCalculatorValue, replMethod, factorReplMethod);
+        impacts.Add(new Tuple<string, double>(variableName, impact));
       }
 
