Index: /branches/2904_CalculateImpacts/3.4/Implementation/Classification/ClassificationSolutionVariableImpactsCalculator.cs
===================================================================
--- /branches/2904_CalculateImpacts/3.4/Implementation/Classification/ClassificationSolutionVariableImpactsCalculator.cs	(revision 16036)
+++ /branches/2904_CalculateImpacts/3.4/Implementation/Classification/ClassificationSolutionVariableImpactsCalculator.cs	(revision 16037)
@@ -90,5 +90,6 @@
     public ClassificationSolutionVariableImpactsCalculator()
       : base() {
-      Parameters.Add(new FixedValueParameter<EnumValue<ReplacementMethodEnum>>(ReplacementParameterName, "The replacement method for variables during impact calculation.", new EnumValue<ReplacementMethodEnum>(ReplacementMethodEnum.Shuffle)));
+      Parameters.Add(new FixedValueParameter<EnumValue<ReplacementMethodEnum>>(ReplacementParameterName, "The replacement method for variables during impact calculation.", new EnumValue<ReplacementMethodEnum>(ReplacementMethodEnum.Median)));
+      Parameters.Add(new FixedValueParameter<EnumValue<FactorReplacementMethodEnum>>(FactorReplacementParameterName, "The replacement method for factor variables during impact calculation.", new EnumValue<FactorReplacementMethodEnum>(FactorReplacementMethodEnum.Best)));
       Parameters.Add(new FixedValueParameter<EnumValue<DataPartitionEnum>>(DataPartitionParameterName, "The data partition on which the impacts are calculated.", new EnumValue<DataPartitionEnum>(DataPartitionEnum.Training)));
     }
@@ -122,5 +123,4 @@
       return CalculateImpacts(model, problemData, estimatedValues, rows, replacementMethod, factorReplacementMethod);
     }
-
 
     public static IEnumerable<Tuple<string, double>> CalculateImpacts(
@@ -149,5 +149,4 @@
       return impacts.OrderByDescending(i => i.Value).Select(i => Tuple.Create(i.Key, i.Value));
     }
-
 
     public static double CalculateImpact(string variableName,
@@ -170,5 +169,4 @@
         var originalValues = modifiableDataset.GetReadOnlyDoubleValues(variableName).ToList();
         List<double> replacementValues;
-        IRandom rand;
 
         switch (replacementMethod) {
@@ -183,9 +181,9 @@
           case ReplacementMethodEnum.Shuffle:
             // new var has same empirical distribution but the relation to y is broken
-            rand = new FastRandom(31415);
+            random = new FastRandom(31415);
             // prepare a complete column for the dataset
             replacementValues = Enumerable.Repeat(double.NaN, modifiableDataset.Rows).ToList();
             // shuffle only the selected rows
-            var shuffledValues = rows.Select(r => originalValues[r]).Shuffle(rand).ToList();
+            var shuffledValues = rows.Select(r => originalValues[r]).Shuffle(random).ToList();
             int i = 0;
             // update column values 
@@ -197,10 +195,10 @@
             var avg = rows.Select(r => originalValues[r]).Average();
             var stdDev = rows.Select(r => originalValues[r]).StandardDeviation();
-            rand = new FastRandom(31415);
+            random = new FastRandom(31415);
             // prepare a complete column for the dataset
             replacementValues = Enumerable.Repeat(double.NaN, modifiableDataset.Rows).ToList();
             // update column values 
             foreach (var r in rows) {
-              replacementValues[r] = NormalDistributedRandom.NextDouble(rand, avg, stdDev);
+              replacementValues[r] = NormalDistributedRandom.NextDouble(random, avg, stdDev);
             }
             break;
@@ -276,4 +274,37 @@
 
       return impact;
+    }
+
+    /// <summary>
+    /// Replaces the values of the original model-variables with the replacement variables, calculates the new estimated values 
+    /// and changes the value of the model-variables back to the original ones.
+    /// </summary>
+    /// <param name="originalValues"></param>
+    /// <param name="model"></param>
+    /// <param name="variableName"></param>
+    /// <param name="modifiableDataset"></param>
+    /// <param name="rows"></param>
+    /// <param name="replacementValues"></param>
+    /// <returns></returns>
+    private static IEnumerable<double> GetReplacedEstimates(
+      IList originalValues,
+      IClassificationModel model,
+      string variableName,
+      ModifiableDataset modifiableDataset,
+      IEnumerable<int> rows,
+      IList replacementValues) {
+      modifiableDataset.ReplaceVariable(variableName, replacementValues);
+
+      var discModel = model as IDiscriminantFunctionClassificationModel;
+      if (discModel != null) {
+        var problemData = new ClassificationProblemData(modifiableDataset, modifiableDataset.VariableNames, model.TargetVariable);
+        discModel.RecalculateModelParameters(problemData, rows);
+      }
+
+      //mkommend: ToList is used on purpose to avoid lazy evaluation that could result in wrong estimates due to variable replacements
+      var estimates = model.GetEstimatedClassValues(modifiableDataset, rows).ToList();
+      modifiableDataset.ReplaceVariable(variableName, originalValues);
+
+      return estimates;
     }
 
@@ -312,38 +343,4 @@
 
     /// <summary>
-    /// Replaces the values of the original model-variables with the replacement variables, calculates the new estimated values 
-    /// and changes the value of the model-variables back to the original ones.
-    /// </summary>
-    /// <param name="originalValues"></param>
-    /// <param name="model"></param>
-    /// <param name="variableName"></param>
-    /// <param name="modifiableDataset"></param>
-    /// <param name="rows"></param>
-    /// <param name="replacementValues"></param>
-    /// <returns></returns>
-    private static IEnumerable<double> GetReplacedEstimates(
-     IList originalValues,
-     IClassificationModel model,
-     string variableName,
-     ModifiableDataset modifiableDataset,
-     IEnumerable<int> rows,
-     IList replacementValues) {
-      modifiableDataset.ReplaceVariable(variableName, replacementValues);
-
-      var discModel = model as IDiscriminantFunctionClassificationModel;
-      if (discModel != null) {
-        var problemData = new ClassificationProblemData(modifiableDataset, modifiableDataset.VariableNames, model.TargetVariable);
-        discModel.RecalculateModelParameters(problemData, rows);
-      }
-
-      //mkommend: ToList is used on purpose to avoid lazy evaluation that could result in wrong estimates due to variable replacements
-      var estimates = model.GetEstimatedClassValues(modifiableDataset, rows).ToList();
-      modifiableDataset.ReplaceVariable(variableName, originalValues);
-
-      return estimates;
-    }
-
-
-    /// <summary>
     /// Returns a collection of the row-indices for a given DataPartition (training or test)
     /// </summary>
@@ -370,5 +367,4 @@
       return rows;
     }
-
   }
 }
