Index: /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/ClassificationVariableImpactCalculationTest.cs
===================================================================
--- /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/ClassificationVariableImpactCalculationTest.cs	(revision 16061)
+++ /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/ClassificationVariableImpactCalculationTest.cs	(revision 16061)
@@ -0,0 +1,110 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Algorithms.DataAnalysis;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using HeuristicLab.Problems.DataAnalysis.Symbolic;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Problems.DataAnalysis.Tests {
+
+  [TestClass()]
+  public class ClassificationVariableImpactCalculationTest {
+    private static readonly double epsilon = 0.00001;
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "short")]
+    public void ConstantModelVariableImpactTest() {
+      IClassificationProblemData problemData = LoadIrisProblem();
+      IClassificationModel model = new ConstantModel(5, "y");
+      IClassificationSolution solution = new ClassificationSolution(model, problemData);
+      Dictionary<string, double> expectedImpacts = GetExpectedValuesForConstantModel();
+
+      CheckDefaultAsserts(solution, expectedImpacts);
+    }
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "short")]
+    public void KNNIrisVariableImpactTest() {
+      IClassificationProblemData problemData = LoadIrisProblem();
+      IClassificationSolution solution = NearestNeighbourClassification.CreateNearestNeighbourClassificationSolution(problemData, 3);
+      ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(solution);
+      Dictionary<string, double> expectedImpacts = GetExpectedValuesForIrisKNNModel();
+
+      CheckDefaultAsserts(solution, expectedImpacts);
+    }
+
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "short")]
+    [ExpectedException(typeof(ArgumentException))]
+    public void WrongDataSetTest() {
+      IClassificationProblemData problemData = LoadIrisProblem();
+      IClassificationSolution solution = NearestNeighbourClassification.CreateNearestNeighbourClassificationSolution(problemData, 3);
+      ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(solution);
+      Dictionary<string, double> expectedImpacts = GetExpectedValuesForIrisKNNModel();
+
+      solution.ProblemData = LoadMammographyProblem();
+      ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(solution);
+    }
+
+    #region Load ClassificationProblemData
+    private IClassificationProblemData LoadIrisProblem() {
+      UCIInstanceProvider provider = new UCIInstanceProvider();
+      var instance = provider.GetDataDescriptors().Where(x => x.Name.Equals("Iris, M. Marshall, 1988")).Single();
+      return provider.LoadData(instance);
+    }
+    private IClassificationProblemData LoadMammographyProblem() {
+      UCIInstanceProvider provider = new UCIInstanceProvider();
+      var instance = provider.GetDataDescriptors().Where(x => x.Name.Equals("Mammography, M. Elter, 2007")).Single();
+      return provider.LoadData(instance);
+    }
+    #endregion
+
+    #region Create SymbolicExpressionTree
+    private ISymbolicExpressionTree CreateCustomExpressionTreeNoInfluenceX1() {
+      return new InfixExpressionParser().Parse("x1/x1*x2 - x2*x2 + x3*x3 + x4*x4 - x5*x5 + 14/12");
+    }
+    #endregion
+
+    #region Get Expected Values      
+    private Dictionary<string, double> GetExpectedValuesForConstantModel() {
+      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
+      expectedImpacts.Add("petal_length", 0);
+      expectedImpacts.Add("petal_width", 0);
+      expectedImpacts.Add("sepal_length", 0);
+      expectedImpacts.Add("sepal_width", 0);
+
+      return expectedImpacts;
+    }
+    private Dictionary<string, double> GetExpectedValuesForIrisKNNModel() {
+      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
+      expectedImpacts.Add("petal_length", 0.21);
+      expectedImpacts.Add("petal_width", 0.25);
+      expectedImpacts.Add("sepal_length", 0.05);
+      expectedImpacts.Add("sepal_width", 0.05);
+
+      return expectedImpacts;
+    }
+    #endregion
+
+    private void CheckDefaultAsserts(IClassificationSolution solution, Dictionary<string, double> expectedImpacts) {
+      IClassificationProblemData problemData = solution.ProblemData;
+      IEnumerable<double> estimatedValues = solution.GetEstimatedClassValues(solution.ProblemData.TrainingIndices);
+
+      var solutionImpacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(solution);
+      var modelImpacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(solution.Model, problemData, estimatedValues, problemData.TrainingIndices);
+
+      //Both ways should return equal results
+      Assert.IsTrue(solutionImpacts.SequenceEqual(modelImpacts));
+
+      //Check if impacts are as expected
+      Assert.AreEqual(modelImpacts.Count(), expectedImpacts.Count);
+      Assert.IsTrue(modelImpacts.All(v => Math.Abs(expectedImpacts[v.Item1] - v.Item2) < epsilon));
+    }
+  }
+}
Index: /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/RegressionVariableImpactCalculationTest.cs
===================================================================
--- /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/RegressionVariableImpactCalculationTest.cs	(revision 16061)
+++ /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/RegressionVariableImpactCalculationTest.cs	(revision 16061)
@@ -0,0 +1,320 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using HeuristicLab.Common;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using HeuristicLab.Problems.DataAnalysis.Symbolic;
+using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
+using HeuristicLab.Problems.Instances.DataAnalysis;
+using HeuristicLab.Random;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace HeuristicLab.Problems.DataAnalysis.Tests {
+
+  [TestClass()]
+  public class RegressionVariableImpactCalculationTest {
+    private TestContext testContextInstance;
+    /// <summary>
+    ///Gets or sets the test context which provides
+    ///information about and functionality for the current test run.
+    ///</summary>
+    public TestContext TestContext {
+      get { return testContextInstance; }
+      set { testContextInstance = value; }
+    }
+
+    private static readonly double epsilon = 0.00001;
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "short")]
+    public void ConstantModelVariableImpactTest() {
+      IRegressionProblemData problemData = LoadDefaultTowerProblem();
+      IRegressionModel model = new ConstantModel(5, "y");
+      IRegressionSolution solution = new RegressionSolution(model, problemData);
+      Dictionary<string, double> expectedImpacts = GetExpectedValuesForConstantModel();
+
+      CheckDefaultAsserts(solution, expectedImpacts);
+    }
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "short")]
+    public void LinearRegressionModelVariableImpactTowerTest() {
+      IRegressionProblemData problemData = LoadDefaultTowerProblem();
+      ISymbolicExpressionTree tree = CreateLRExpressionTree(problemData);
+      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
+      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
+      Dictionary<string, double> expectedImpacts = GetExpectedValuesForLRTower();
+
+      CheckDefaultAsserts(solution, expectedImpacts);
+    }
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "short")]
+    public void LinearRegressionModelVariableImpactMibaTest() {
+      IRegressionProblemData problemData = LoadDefaultMibaProblem();
+      ISymbolicExpressionTree tree = CreateLRExpressionTree(problemData);
+      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
+      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
+      Dictionary<string, double> expectedImpacts = GetExpectedValuesForLRMiba();
+
+      CheckDefaultAsserts(solution, expectedImpacts);
+    }
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "short")]
+    public void CustomModelVariableImpactTest() {
+      IRegressionProblemData problemData = CreateDefaultProblem();
+      ISymbolicExpressionTree tree = CreateCustomExpressionTree();
+      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
+      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
+      Dictionary<string, double> expectedImpacts = GetExpectedValuesForCustomProblem();
+
+      CheckDefaultAsserts(solution, expectedImpacts);
+    }
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "short")]
+    public void CustomModelVariableImpactNoInfluenceTest() {
+      IRegressionProblemData problemData = CreateDefaultProblem();
+      ISymbolicExpressionTree tree = CreateCustomExpressionTreeNoInfluenceX1();
+      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
+      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
+      Dictionary<string, double> expectedImpacts = GetExpectedValuesForCustomProblemNoInfluence();
+
+      CheckDefaultAsserts(solution, expectedImpacts);
+    }
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "short")]
+    [ExpectedException(typeof(ArgumentException))]
+    public void WrongDataSetTest() {
+      IRegressionProblemData problemData = LoadDefaultTowerProblem();
+      ISymbolicExpressionTree tree = CreateLRExpressionTree(problemData);
+      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
+      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
+
+      solution.ProblemData = LoadDefaultMibaProblem();
+      RegressionSolutionVariableImpactsCalculator.CalculateImpacts(solution);
+
+    }
+
+    [TestMethod]
+    [TestCategory("Problems.DataAnalysis")]
+    [TestProperty("Time", "medium")]
+    public void PerformanceTest() {
+      int rows = 20000;
+      int columns = 77;
+      var dataSet = OnlineCalculatorPerformanceTest.CreateRandomDataset(new MersenneTwister(1234), rows, columns);
+      IRegressionProblemData problemData = new RegressionProblemData(dataSet, dataSet.VariableNames.Except("y".ToEnumerable()), "y");
+      ISymbolicExpressionTree tree = CreateLRExpressionTree(problemData);
+      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
+      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
+
+      Stopwatch watch = new Stopwatch();
+      watch.Start();
+      var results = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(solution);
+      watch.Stop();
+
+      TestContext.WriteLine("");
+      TestContext.WriteLine("Calculated cells per millisecond: {0}.", rows * columns / watch.ElapsedMilliseconds);
+
+    }
+
+    #region Load RegressionProblemData
+    private IRegressionProblemData LoadDefaultTowerProblem() {
+      RegressionRealWorldInstanceProvider provider = new RegressionRealWorldInstanceProvider();
+      var instance = provider.GetDataDescriptors().Where(x => x.Name.Equals("Tower")).Single();
+      return provider.LoadData(instance);
+    }
+    private IRegressionProblemData LoadDefaultMibaProblem() {
+      MibaFrictionRegressionInstanceProvider provider = new MibaFrictionRegressionInstanceProvider();
+      var instance = provider.GetDataDescriptors().Where(x => x.Name.Equals("CF1")).Single();
+      return provider.LoadData(instance);
+    }
+    private IRegressionProblemData CreateDefaultProblem() {
+      List<string> allowedInputVariables = new List<string>() { "x1", "x2", "x3", "x4", "x5" };
+      string targetVariable = "y";
+      var variableNames = allowedInputVariables.Union(targetVariable.ToEnumerable());
+      double[,] variableValues = new double[100, variableNames.Count()];
+
+      FastRandom random = new FastRandom(12345);
+      for (int i = 0; i < variableValues.GetLength(0); i++) {
+        for (int j = 0; j < variableValues.GetLength(1); j++) {
+          variableValues[i, j] = random.Next(1, 100);
+        }
+      }
+
+      Dataset dataset = new Dataset(variableNames, variableValues);
+      return new RegressionProblemData(dataset, allowedInputVariables, targetVariable);
+    }
+    #endregion
+
+    #region Create SymbolicExpressionTree
+    private ISymbolicExpressionTree CreateLRExpressionTree(IRegressionProblemData problemData) {
+      IEnumerable<int> rows = problemData.TrainingIndices;
+      var doubleVariables = problemData.AllowedInputVariables.Where(problemData.Dataset.VariableHasType<double>);
+      var factorVariableNames = problemData.AllowedInputVariables.Where(problemData.Dataset.VariableHasType<string>);
+      var factorVariables = problemData.Dataset.GetFactorVariableValues(factorVariableNames, rows);
+      double[,] binaryMatrix = problemData.Dataset.ToArray(factorVariables, rows);
+      double[,] doubleVarMatrix = problemData.Dataset.ToArray(doubleVariables.Concat(new string[] { problemData.TargetVariable }), rows);
+      var inputMatrix = binaryMatrix.HorzCat(doubleVarMatrix);
+
+      alglib.linearmodel lm = new alglib.linearmodel();
+      alglib.lrreport ar = new alglib.lrreport();
+      int nRows = inputMatrix.GetLength(0);
+      int nFeatures = inputMatrix.GetLength(1) - 1;
+      double[] coefficients = new double[nFeatures + 1]; // last coefficient is for the constant
+
+      int retVal = 1;
+      alglib.lrbuild(inputMatrix, nRows, nFeatures, out retVal, out lm, out ar);
+      if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression solution");
+
+      alglib.lrunpack(lm, out coefficients, out nFeatures);
+
+      int nFactorCoeff = binaryMatrix.GetLength(1);
+      int nVarCoeff = doubleVariables.Count();
+      return LinearModelToTreeConverter.CreateTree(factorVariables, coefficients.Take(nFactorCoeff).ToArray(),
+        doubleVariables.ToArray(), coefficients.Skip(nFactorCoeff).Take(nVarCoeff).ToArray(),
+        @const: coefficients[nFeatures]);
+    }
+    private ISymbolicExpressionTree CreateCustomExpressionTree() {
+      return new InfixExpressionParser().Parse("x1*x2 - x2*x2 + x3*x3 + x4*x4 - x5*x5 + 14/12");
+    }
+    private ISymbolicExpressionTree CreateCustomExpressionTreeNoInfluenceX1() {
+      return new InfixExpressionParser().Parse("x1/x1*x2 - x2*x2 + x3*x3 + x4*x4 - x5*x5 + 14/12");
+    }
+    #endregion
+
+    #region Get Expected Values
+    private Dictionary<string, double> GetExpectedValuesForConstantModel() {
+      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
+      expectedImpacts.Add("x1", 0);
+      expectedImpacts.Add("x10", 0);
+      expectedImpacts.Add("x11", 0);
+      expectedImpacts.Add("x12", 0);
+      expectedImpacts.Add("x13", 0);
+      expectedImpacts.Add("x14", 0);
+      expectedImpacts.Add("x15", 0);
+      expectedImpacts.Add("x16", 0);
+      expectedImpacts.Add("x17", 0);
+      expectedImpacts.Add("x18", 0);
+      expectedImpacts.Add("x19", 0);
+      expectedImpacts.Add("x2", 0);
+      expectedImpacts.Add("x20", 0);
+      expectedImpacts.Add("x21", 0);
+      expectedImpacts.Add("x22", 0);
+      expectedImpacts.Add("x23", 0);
+      expectedImpacts.Add("x24", 0);
+      expectedImpacts.Add("x25", 0);
+      expectedImpacts.Add("x3", 0);
+      expectedImpacts.Add("x4", 0);
+      expectedImpacts.Add("x5", 0);
+      expectedImpacts.Add("x6", 0);
+      expectedImpacts.Add("x7", 0);
+      expectedImpacts.Add("x8", 0);
+      expectedImpacts.Add("x9", 0);
+
+      return expectedImpacts;
+    }
+    private Dictionary<string, double> GetExpectedValuesForLRTower() {
+      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
+      expectedImpacts.Add("x1", 0.639933657675427);
+      expectedImpacts.Add("x10", 0.0127006885259798);
+      expectedImpacts.Add("x11", 0.648236047877475);
+      expectedImpacts.Add("x12", 0.248350173524562);
+      expectedImpacts.Add("x13", 0.550889987109547);
+      expectedImpacts.Add("x14", 0.0882824237877192);
+      expectedImpacts.Add("x15", 0.0391276799061169);
+      expectedImpacts.Add("x16", 0.743632451088798);
+      expectedImpacts.Add("x17", 0.00254276857715308);
+      expectedImpacts.Add("x18", 0.0021548147614302);
+      expectedImpacts.Add("x19", 0.00513473927463037);
+      expectedImpacts.Add("x2", 0.0107583487931443);
+      expectedImpacts.Add("x20", 0.18085069746933);
+      expectedImpacts.Add("x21", 0.138053600700762);
+      expectedImpacts.Add("x22", 0.000339539790460086);
+      expectedImpacts.Add("x23", 0.362111965467117);
+      expectedImpacts.Add("x24", 0.0320167935572304);
+      expectedImpacts.Add("x25", 0.57460423230969);
+      expectedImpacts.Add("x3", 0.688142635515862);
+      expectedImpacts.Add("x4", 0.000176632348454664);
+      expectedImpacts.Add("x5", 0.0213915503114581);
+      expectedImpacts.Add("x6", 0.807976486909701);
+      expectedImpacts.Add("x7", 0.716217843319252);
+      expectedImpacts.Add("x8", 0.772701841392564);
+      expectedImpacts.Add("x9", 0.178418730050997);
+
+      return expectedImpacts;
+    }
+    private Dictionary<string, double> GetExpectedValuesForLRMiba() {
+      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
+      expectedImpacts.Add("Grooving", 0.0380558091030508);
+      expectedImpacts.Add("Material", 0.02195836766156);
+      expectedImpacts.Add("Material_Cat", 0.000338687689067418);
+      expectedImpacts.Add("Oil", 0.363464994447857);
+      expectedImpacts.Add("x10", 0.0015309669014415);
+      expectedImpacts.Add("x11", -3.60432578908609E-05);
+      expectedImpacts.Add("x12", 0.00118953859087612);
+      expectedImpacts.Add("x13", 0.00164240977191832);
+      expectedImpacts.Add("x14", 0.000688363685380056);
+      expectedImpacts.Add("x15", -4.75067203969948E-05);
+      expectedImpacts.Add("x16", 0.00130388206125076);
+      expectedImpacts.Add("x17", 0.132351838646134);
+      expectedImpacts.Add("x2", -2.47981401556574E-05);
+      expectedImpacts.Add("x20", 0.716541716605016);
+      expectedImpacts.Add("x22", 0.174959377282835);
+      expectedImpacts.Add("x3", -2.65979754026091E-05);
+      expectedImpacts.Add("x4", -1.24764212947603E-05);
+      expectedImpacts.Add("x5", 0.001184959455798);
+      expectedImpacts.Add("x6", 0.000743336665237626);
+      expectedImpacts.Add("x7", 0.00188965927889773);
+      expectedImpacts.Add("x8", 0.00415201581536351);
+      expectedImpacts.Add("x9", 0.00365653880518491);
+
+      return expectedImpacts;
+    }
+    private Dictionary<string, double> GetExpectedValuesForCustomProblem() {
+      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
+      expectedImpacts.Add("x1", -0.000573340275115796);
+      expectedImpacts.Add("x2", 0.000781819784095592);
+      expectedImpacts.Add("x3", -0.000390473234921058);
+      expectedImpacts.Add("x4", -0.00116083274627995);
+      expectedImpacts.Add("x5", -0.00036161186207545);
+
+      return expectedImpacts;
+    }
+    private Dictionary<string, double> GetExpectedValuesForCustomProblemNoInfluence() {
+      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
+      expectedImpacts.Add("x1", 0);
+      expectedImpacts.Add("x2", 0.00263393690342982);
+      expectedImpacts.Add("x3", -0.00053248037514929);
+      expectedImpacts.Add("x4", 0.00450365819257568);
+      expectedImpacts.Add("x5", -0.000550911612888904);
+
+      return expectedImpacts;
+    }
+    #endregion
+
+    private void CheckDefaultAsserts(IRegressionSolution solution, Dictionary<string, double> expectedImpacts) {
+      IRegressionProblemData problemData = solution.ProblemData;
+      IEnumerable<double> estimatedValues = solution.GetEstimatedValues(solution.ProblemData.TrainingIndices);
+
+      var solutionImpacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(solution);
+      var modelImpacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(solution.Model, problemData, estimatedValues, problemData.TrainingIndices);
+
+      //Both ways should return equal results
+      Assert.IsTrue(solutionImpacts.SequenceEqual(modelImpacts));
+
+      //Check if impacts are as expected
+      Assert.AreEqual(modelImpacts.Count(), expectedImpacts.Count);
+      Assert.IsTrue(modelImpacts.All(v => Math.Abs(expectedImpacts[v.Item1] - v.Item2) < epsilon));
+    }
+  }
+}
Index: anches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/VariableImpactCalculationTest.cs
===================================================================
--- /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/VariableImpactCalculationTest.cs	(revision 16060)
+++ 	(revision )
@@ -1,273 +1,0 @@
-﻿using System;
-using System.Collections.Generic;
-using System.Linq;
-using HeuristicLab.Common;
-using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
-using HeuristicLab.Problems.DataAnalysis.Symbolic;
-using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
-using HeuristicLab.Problems.Instances.DataAnalysis;
-using HeuristicLab.Random;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace HeuristicLab.Problems.DataAnalysis.Tests {
-
-  [TestClass()]
-  public class VariableImpactCalculationTest {
-    private static readonly double epsilon = 0.00001;
-
-    [TestMethod]
-    [TestCategory("Problems.DataAnalysis")]
-    [TestProperty("Time", "short")]
-    public void ConstantModelVariableImpactTest() {
-      IRegressionProblemData problemData = LoadDefaultTowerProblem();
-      IRegressionModel model = new ConstantModel(5, "y");
-      IRegressionSolution solution = new RegressionSolution(model, problemData);
-      Dictionary<string, double> expectedImpacts = GetExpectedValuesForConstantModel();
-
-      CheckDefaultAsserts(solution, expectedImpacts);
-    }
-
-    [TestMethod]
-    [TestCategory("Problems.DataAnalysis")]
-    [TestProperty("Time", "short")]
-    public void LinearRegressionModelVariableImpactTowerTest() {
-      IRegressionProblemData problemData = LoadDefaultTowerProblem();
-      ISymbolicExpressionTree tree = CreateLRExpressionTree(problemData);
-      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
-      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
-      Dictionary<string, double> expectedImpacts = GetExpectedValuesForLRTower();
-
-      CheckDefaultAsserts(solution, expectedImpacts);
-    }
-
-    [TestMethod]
-    [TestCategory("Problems.DataAnalysis")]
-    [TestProperty("Time", "short")]
-    public void LinearRegressionModelVariableImpactMibaTest() {
-      IRegressionProblemData problemData = LoadDefaultMibaProblem();
-      ISymbolicExpressionTree tree = CreateLRExpressionTree(problemData);
-      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
-      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
-      Dictionary<string, double> expectedImpacts = GetExpectedValuesForLRMiba();
-
-      CheckDefaultAsserts(solution, expectedImpacts);
-    }
-
-    [TestMethod]
-    [TestCategory("Problems.DataAnalysis")]
-    [TestProperty("Time", "short")]
-    public void CustomModelVariableImpactTest() {
-      IRegressionProblemData problemData = CreateDefaultProblem();
-      ISymbolicExpressionTree tree = CreateCustomExpressionTree();
-      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
-      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
-      Dictionary<string, double> expectedImpacts = GetExpectedValuesForCustomProblem();
-
-      CheckDefaultAsserts(solution, expectedImpacts);
-    }
-
-    [TestMethod]
-    [TestCategory("Problems.DataAnalysis")]
-    [TestProperty("Time", "short")]
-    public void CustomModelVariableImpactNoInfluenceTest() {
-      IRegressionProblemData problemData = CreateDefaultProblem();
-      ISymbolicExpressionTree tree = CreateCustomExpressionTreeNoInfluenceX1();
-      IRegressionModel model = new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeInterpreter());
-      IRegressionSolution solution = new RegressionSolution(model, (IRegressionProblemData)problemData.Clone());
-      Dictionary<string, double> expectedImpacts = GetExpectedValuesForCustomProblemNoInfluence();
-
-      CheckDefaultAsserts(solution, expectedImpacts);
-    }
-
-    #region Load RegressionProblemData
-    private IRegressionProblemData LoadDefaultTowerProblem() {
-      RegressionRealWorldInstanceProvider provider = new RegressionRealWorldInstanceProvider();
-      var instance = provider.GetDataDescriptors().Where(x => x.Name.Equals("Tower")).Single();
-      return provider.LoadData(instance);
-    }
-    private IRegressionProblemData LoadDefaultMibaProblem() {
-      MibaFrictionRegressionInstanceProvider provider = new MibaFrictionRegressionInstanceProvider();
-      var instance = provider.GetDataDescriptors().Where(x => x.Name.Equals("CF1")).Single();
-      return provider.LoadData(instance);
-    }
-    private IRegressionProblemData CreateDefaultProblem() {
-      List<string> allowedInputVariables = new List<string>() { "x1", "x2", "x3", "x4", "x5" };
-      string targetVariable = "y";
-      var variableNames = allowedInputVariables.Union(targetVariable.ToEnumerable());
-      double[,] variableValues = new double[100, variableNames.Count()];
-
-      FastRandom random = new FastRandom(12345);
-      for (int i = 0; i < variableValues.GetLength(0); i++) {
-        for (int j = 0; j < variableValues.GetLength(1); j++) {
-          variableValues[i, j] = random.Next(1, 100);
-        }
-      }
-
-      Dataset dataset = new Dataset(variableNames, variableValues);
-      return new RegressionProblemData(dataset, allowedInputVariables, targetVariable);
-    }
-    #endregion
-
-    #region Create SymbolicExpressionTree
-    private ISymbolicExpressionTree CreateLRExpressionTree(IRegressionProblemData problemData) {
-      IEnumerable<int> rows = problemData.TrainingIndices;
-      var doubleVariables = problemData.AllowedInputVariables.Where(problemData.Dataset.VariableHasType<double>);
-      var factorVariableNames = problemData.AllowedInputVariables.Where(problemData.Dataset.VariableHasType<string>);
-      var factorVariables = problemData.Dataset.GetFactorVariableValues(factorVariableNames, rows);
-      double[,] binaryMatrix = problemData.Dataset.ToArray(factorVariables, rows);
-      double[,] doubleVarMatrix = problemData.Dataset.ToArray(doubleVariables.Concat(new string[] { problemData.TargetVariable }), rows);
-      var inputMatrix = binaryMatrix.HorzCat(doubleVarMatrix);
-
-      alglib.linearmodel lm = new alglib.linearmodel();
-      alglib.lrreport ar = new alglib.lrreport();
-      int nRows = inputMatrix.GetLength(0);
-      int nFeatures = inputMatrix.GetLength(1) - 1;
-      double[] coefficients = new double[nFeatures + 1]; // last coefficient is for the constant
-
-      int retVal = 1;
-      alglib.lrbuild(inputMatrix, nRows, nFeatures, out retVal, out lm, out ar);
-      if (retVal != 1) throw new ArgumentException("Error in calculation of linear regression solution");
-
-      alglib.lrunpack(lm, out coefficients, out nFeatures);
-
-      int nFactorCoeff = binaryMatrix.GetLength(1);
-      int nVarCoeff = doubleVariables.Count();
-      return LinearModelToTreeConverter.CreateTree(factorVariables, coefficients.Take(nFactorCoeff).ToArray(),
-        doubleVariables.ToArray(), coefficients.Skip(nFactorCoeff).Take(nVarCoeff).ToArray(),
-        @const: coefficients[nFeatures]);
-    }
-    private ISymbolicExpressionTree CreateCustomExpressionTree() {
-      return new InfixExpressionParser().Parse("x1*x2 - x2*x2 + x3*x3 + x4*x4 - x5*x5 + 14/12");
-    }
-    private ISymbolicExpressionTree CreateCustomExpressionTreeNoInfluenceX1() {
-      return new InfixExpressionParser().Parse("x1/x1*x2 - x2*x2 + x3*x3 + x4*x4 - x5*x5 + 14/12");
-    }
-    #endregion
-
-    #region Get Expected Values
-    private Dictionary<string, double> GetExpectedValuesForConstantModel() {
-      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
-      expectedImpacts.Add("x1", 0);
-      expectedImpacts.Add("x10", 0);
-      expectedImpacts.Add("x11", 0);
-      expectedImpacts.Add("x12", 0);
-      expectedImpacts.Add("x13", 0);
-      expectedImpacts.Add("x14", 0);
-      expectedImpacts.Add("x15", 0);
-      expectedImpacts.Add("x16", 0);
-      expectedImpacts.Add("x17", 0);
-      expectedImpacts.Add("x18", 0);
-      expectedImpacts.Add("x19", 0);
-      expectedImpacts.Add("x2", 0);
-      expectedImpacts.Add("x20", 0);
-      expectedImpacts.Add("x21", 0);
-      expectedImpacts.Add("x22", 0);
-      expectedImpacts.Add("x23", 0);
-      expectedImpacts.Add("x24", 0);
-      expectedImpacts.Add("x25", 0);
-      expectedImpacts.Add("x3", 0);
-      expectedImpacts.Add("x4", 0);
-      expectedImpacts.Add("x5", 0);
-      expectedImpacts.Add("x6", 0);
-      expectedImpacts.Add("x7", 0);
-      expectedImpacts.Add("x8", 0);
-      expectedImpacts.Add("x9", 0);
-
-      return expectedImpacts;
-    }
-    private Dictionary<string, double> GetExpectedValuesForLRTower() {
-      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
-      expectedImpacts.Add("x1", 0.639933657675427);
-      expectedImpacts.Add("x10", 0.0127006885259798);
-      expectedImpacts.Add("x11", 0.648236047877475);
-      expectedImpacts.Add("x12", 0.248350173524562);
-      expectedImpacts.Add("x13", 0.550889987109547);
-      expectedImpacts.Add("x14", 0.0882824237877192);
-      expectedImpacts.Add("x15", 0.0391276799061169);
-      expectedImpacts.Add("x16", 0.743632451088798);
-      expectedImpacts.Add("x17", 0.00254276857715308);
-      expectedImpacts.Add("x18", 0.0021548147614302);
-      expectedImpacts.Add("x19", 0.00513473927463037);
-      expectedImpacts.Add("x2", 0.0107583487931443);
-      expectedImpacts.Add("x20", 0.18085069746933);
-      expectedImpacts.Add("x21", 0.138053600700762);
-      expectedImpacts.Add("x22", 0.000339539790460086);
-      expectedImpacts.Add("x23", 0.362111965467117);
-      expectedImpacts.Add("x24", 0.0320167935572304);
-      expectedImpacts.Add("x25", 0.57460423230969);
-      expectedImpacts.Add("x3", 0.688142635515862);
-      expectedImpacts.Add("x4", 0.000176632348454664);
-      expectedImpacts.Add("x5", 0.0213915503114581);
-      expectedImpacts.Add("x6", 0.807976486909701);
-      expectedImpacts.Add("x7", 0.716217843319252);
-      expectedImpacts.Add("x8", 0.772701841392564);
-      expectedImpacts.Add("x9", 0.178418730050997);
-
-      return expectedImpacts;
-    }
-    private Dictionary<string, double> GetExpectedValuesForLRMiba() {
-      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
-      expectedImpacts.Add("Grooving", 0.0380558091030508);
-      expectedImpacts.Add("Material", 0.02195836766156);
-      expectedImpacts.Add("Material_Cat", 0.000338687689067418);
-      expectedImpacts.Add("Oil", 0.363464994447857);
-      expectedImpacts.Add("x10", 0.0015309669014415);
-      expectedImpacts.Add("x11", -3.60432578908609E-05);
-      expectedImpacts.Add("x12", 0.00118953859087612);
-      expectedImpacts.Add("x13", 0.00164240977191832);
-      expectedImpacts.Add("x14", 0.000688363685380056);
-      expectedImpacts.Add("x15", -4.75067203969948E-05);
-      expectedImpacts.Add("x16", 0.00130388206125076);
-      expectedImpacts.Add("x17", 0.132351838646134);
-      expectedImpacts.Add("x2", -2.47981401556574E-05);
-      expectedImpacts.Add("x20", 0.716541716605016);
-      expectedImpacts.Add("x22", 0.174959377282835);
-      expectedImpacts.Add("x3", -2.65979754026091E-05);
-      expectedImpacts.Add("x4", -1.24764212947603E-05);
-      expectedImpacts.Add("x5", 0.001184959455798);
-      expectedImpacts.Add("x6", 0.000743336665237626);
-      expectedImpacts.Add("x7", 0.00188965927889773);
-      expectedImpacts.Add("x8", 0.00415201581536351);
-      expectedImpacts.Add("x9", 0.00365653880518491);
-
-      return expectedImpacts;
-    }
-    private Dictionary<string, double> GetExpectedValuesForCustomProblem() {
-      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
-      expectedImpacts.Add("x1", -0.000573340275115796);
-      expectedImpacts.Add("x2", 0.000781819784095592);
-      expectedImpacts.Add("x3", -0.000390473234921058);
-      expectedImpacts.Add("x4", -0.00116083274627995);
-      expectedImpacts.Add("x5", -0.00036161186207545);
-
-      return expectedImpacts;
-    }
-    private Dictionary<string, double> GetExpectedValuesForCustomProblemNoInfluence() {
-      Dictionary<string, double> expectedImpacts = new Dictionary<string, double>();
-      expectedImpacts.Add("x1", 0);
-      expectedImpacts.Add("x2", 0.00263393690342982);
-      expectedImpacts.Add("x3", -0.00053248037514929);
-      expectedImpacts.Add("x4", 0.00450365819257568);
-      expectedImpacts.Add("x5", -0.000550911612888904);
-
-      return expectedImpacts;
-    }
-    #endregion
-
-    private void CheckDefaultAsserts(IRegressionSolution solution, Dictionary<string, double> expectedImpacts) {
-      IRegressionProblemData problemData = solution.ProblemData;
-      IEnumerable<double> estimatedValues = solution.GetEstimatedValues(solution.ProblemData.TrainingIndices);
-
-      var solutionImpacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(solution);
-      var modelImpacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(solution.Model, problemData, estimatedValues, problemData.TrainingIndices);
-      //Both ways should return equal results
-      Assert.IsTrue(solutionImpacts.SequenceEqual(modelImpacts));
-
-      //Check if impacts are as expected
-      Assert.AreEqual(modelImpacts.Count(), expectedImpacts.Count);
-      foreach (var entry in modelImpacts.OrderBy(v => v.Item1)) {
-        Assert.IsTrue(Math.Abs(expectedImpacts[entry.Item1] - entry.Item2) < epsilon);
-      }
-    }
-  }
-}
Index: /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Tests.csproj
===================================================================
--- /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Tests.csproj	(revision 16060)
+++ /branches/2904_CalculateImpacts/HeuristicLab.Tests/HeuristicLab.Tests.csproj	(revision 16061)
@@ -583,8 +583,9 @@
     <Compile Include="HeuristicLab.Persistence-3.3\UseCases.cs" />
     <Compile Include="HeuristicLab.PluginInfraStructure-3.3\TypeExtensionsTest.cs" />
+    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\ClassificationVariableImpactCalculationTest.cs" />
     <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\ThresholdCalculatorsTest.cs" />
     <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\OnlineCalculatorPerformanceTest.cs" />
     <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\StatisticCalculatorsTest.cs" />
-    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\VariableImpactCalculationTest.cs" />
+    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\RegressionVariableImpactCalculationTest.cs" />
     <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\InfixExpressionParserTest.cs" />
     <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs" />
