Index: branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.Designer.cs
===================================================================
--- branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.Designer.cs	(revision 16288)
+++ branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.Designer.cs	(revision 16295)
@@ -26,4 +26,5 @@
       this.components = new System.ComponentModel.Container();
       this.settingsGroupBox = new System.Windows.Forms.GroupBox();
+      this.impactThresholdLabel = new System.Windows.Forms.Label();
       this.impactThresholdTrackBar = new System.Windows.Forms.TrackBar();
       this.exportImpactsMatrixButton = new System.Windows.Forms.Button();
@@ -38,4 +39,5 @@
       this.label1 = new System.Windows.Forms.Label();
       this.layoutOptionsGroupBox = new System.Windows.Forms.GroupBox();
+      this.relayoutGraphButton = new System.Windows.Forms.Button();
       this.idealEdgeLengthTextBox = new System.Windows.Forms.TextBox();
       this.edgeRoutingComboBox = new System.Windows.Forms.ComboBox();
@@ -43,6 +45,4 @@
       this.label3 = new System.Windows.Forms.Label();
       this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
-      this.impactThresholdLabel = new System.Windows.Forms.Label();
-      this.relayoutGraphButton = new System.Windows.Forms.Button();
       this.graphChart = new HeuristicLab.VariableInteractionNetworks.Views.DirectedGraphChart();
       this.settingsGroupBox.SuspendLayout();
@@ -54,5 +54,5 @@
       // settingsGroupBox
       // 
-      this.settingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+      this.settingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
             | System.Windows.Forms.AnchorStyles.Left)));
       this.settingsGroupBox.Controls.Add(this.impactThresholdLabel);
@@ -75,4 +75,13 @@
       this.settingsGroupBox.Text = "Network Configuration";
       // 
+      // impactThresholdLabel
+      // 
+      this.impactThresholdLabel.Location = new System.Drawing.Point(118, 92);
+      this.impactThresholdLabel.Name = "impactThresholdLabel";
+      this.impactThresholdLabel.Size = new System.Drawing.Size(204, 23);
+      this.impactThresholdLabel.TabIndex = 8;
+      this.impactThresholdLabel.Text = "0";
+      this.impactThresholdLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
+      // 
       // impactThresholdTrackBar
       // 
@@ -186,6 +195,5 @@
       // layoutOptionsGroupBox
       // 
-      this.layoutOptionsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-            | System.Windows.Forms.AnchorStyles.Left)));
+      this.layoutOptionsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
       this.layoutOptionsGroupBox.Controls.Add(this.relayoutGraphButton);
       this.layoutOptionsGroupBox.Controls.Add(this.idealEdgeLengthTextBox);
@@ -193,10 +201,20 @@
       this.layoutOptionsGroupBox.Controls.Add(this.label4);
       this.layoutOptionsGroupBox.Controls.Add(this.label3);
-      this.layoutOptionsGroupBox.Location = new System.Drawing.Point(4, 245);
+      this.layoutOptionsGroupBox.Location = new System.Drawing.Point(4, 360);
       this.layoutOptionsGroupBox.Name = "layoutOptionsGroupBox";
-      this.layoutOptionsGroupBox.Size = new System.Drawing.Size(331, 217);
+      this.layoutOptionsGroupBox.Size = new System.Drawing.Size(331, 102);
       this.layoutOptionsGroupBox.TabIndex = 2;
       this.layoutOptionsGroupBox.TabStop = false;
       this.layoutOptionsGroupBox.Text = "Layout Options";
+      // 
+      // relayoutGraphButton
+      // 
+      this.relayoutGraphButton.Location = new System.Drawing.Point(10, 69);
+      this.relayoutGraphButton.Name = "relayoutGraphButton";
+      this.relayoutGraphButton.Size = new System.Drawing.Size(149, 23);
+      this.relayoutGraphButton.TabIndex = 4;
+      this.relayoutGraphButton.Text = "Recalculate Layout";
+      this.relayoutGraphButton.UseVisualStyleBackColor = true;
+      this.relayoutGraphButton.Click += new System.EventHandler(this.relayoutGraphButton_Click);
       // 
       // idealEdgeLengthTextBox
@@ -246,31 +264,12 @@
       this.errorProvider.ContainerControl = this;
       // 
-      // impactThresholdLabel
-      // 
-      this.impactThresholdLabel.Location = new System.Drawing.Point(118, 92);
-      this.impactThresholdLabel.Name = "impactThresholdLabel";
-      this.impactThresholdLabel.Size = new System.Drawing.Size(204, 23);
-      this.impactThresholdLabel.TabIndex = 8;
-      this.impactThresholdLabel.Text = "0";
-      this.impactThresholdLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
-      // 
-      // relayoutGraphButton
-      // 
-      this.relayoutGraphButton.Location = new System.Drawing.Point(10, 69);
-      this.relayoutGraphButton.Name = "relayoutGraphButton";
-      this.relayoutGraphButton.Size = new System.Drawing.Size(149, 23);
-      this.relayoutGraphButton.TabIndex = 4;
-      this.relayoutGraphButton.Text = "Recalculate Layout";
-      this.relayoutGraphButton.UseVisualStyleBackColor = true;
-      this.relayoutGraphButton.Click += new System.EventHandler(this.relayoutGraphButton_Click);
-      // 
       // graphChart
       // 
-      this.graphChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-            | System.Windows.Forms.AnchorStyles.Left)
+      this.graphChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
       this.graphChart.BackColor = System.Drawing.SystemColors.Control;
+      this.graphChart.DefaultEdgeLength = 50D;
       this.graphChart.Graph = null;
-      this.graphChart.DefaultEdgeLength = 50D;
       this.graphChart.Location = new System.Drawing.Point(341, 4);
       this.graphChart.Mode = null;
Index: branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.cs
===================================================================
--- branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.cs	(revision 16288)
+++ branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/RunCollectionVariableInteractionNetworkView.cs	(revision 16295)
@@ -111,12 +111,19 @@
       var targetImpacts = new Dictionary<string, Tuple<IEnumerable<IRun>, Dictionary<string, double>>>();
 
+      var groups = runs.GroupBy(run => {
+        var sol = (IRegressionSolution)run.Results.Values.Single(x => x is IRegressionSolution);
+        return Concatenate(sol.ProblemData.AllowedInputVariables) + sol.ProblemData.TargetVariable;
+      });
+
       if (useBest) {
         // build network using only the best run for each target
+        foreach (var group in groups) {
+          var solutions = group.Select(run => Tuple.Create(run, (IRegressionSolution)run.Results.Values.Single(sol => sol is IRegressionSolution)));
+          var best = solutions.OrderBy(x => x.Item2.TrainingRSquared).Last();
+          var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(best.Item2, RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.All, RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum.Shuffle).ToDictionary(x => x.Item1, x => x.Item2);
+
+          targetImpacts[best.Item2.ProblemData.TargetVariable] = Tuple.Create(new[] { best.Item1 }.AsEnumerable(), impacts);
+        }
       } else {
-        var groups = runs.GroupBy(run => {
-          var sol = (IRegressionSolution)run.Results.Values.Single(x => x is IRegressionSolution);
-          return Concatenate(sol.ProblemData.AllowedInputVariables) + sol.ProblemData.TargetVariable;
-        });
-
         foreach (var group in groups) {
           // calculate average impacts
@@ -131,74 +138,44 @@
             }
             var md = dataset.ToModifiable();
-            var impacts = CalculateImpacts(sol, md, originalValues, medians, estimationLimits);
-            foreach (var pair in impacts) {
-              if (averageImpacts.ContainsKey(pair.Key))
-                averageImpacts[pair.Key] += pair.Value;
+
+            var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(sol, RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.All, RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum.Shuffle);
+            foreach (var t in impacts) {
+              if (averageImpacts.ContainsKey(t.Item1))
+                averageImpacts[t.Item1] += t.Item2;
               else {
-                averageImpacts[pair.Key] = pair.Value;
+                averageImpacts[t.Item1] = t.Item2;
               }
             }
           }
+
           var count = group.Count();
-          var keys = averageImpacts.Keys.ToList();
-          foreach (var v in keys) {
+          foreach (var v in averageImpacts.Keys) {
             averageImpacts[v] /= count;
           }
 
-          targetImpacts[solution.ProblemData.TargetVariable] = new Tuple<IEnumerable<IRun>, Dictionary<string, double>>(group, averageImpacts);
+          targetImpacts[solution.ProblemData.TargetVariable] = Tuple.Create(group.AsEnumerable(), averageImpacts);
         }
       }
       return targetImpacts;
-    }
-
-    private static Dictionary<string, double> CalculateImpacts(IRegressionSolution solution, ModifiableDataset dataset,
-      Dictionary<string, List<double>> originalValues, Dictionary<string, List<double>> medianValues, DoubleLimit estimationLimits = null) {
-      var impacts = new Dictionary<string, double>();
-
-      var model = solution.Model;
-      var pd = solution.ProblemData;
-
-      var rows = pd.TrainingIndices.ToList();
-      var targetValues = pd.Dataset.GetDoubleValues(pd.TargetVariable, rows).ToList();
-
-
-      foreach (var v in pd.AllowedInputVariables) {
-        dataset.ReplaceVariable(v, medianValues[v]);
-
-        var estimatedValues = model.GetEstimatedValues(dataset, rows);
-        if (estimationLimits != null)
-          estimatedValues = estimatedValues.LimitToRange(estimationLimits.Lower, estimationLimits.Upper);
-
-        OnlineCalculatorError error;
-        var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out error);
-        var newQuality = error == OnlineCalculatorError.None ? r * r : double.NaN;
-        var originalQuality = solution.TrainingRSquared;
-        impacts[v] = originalQuality - newQuality;
-
-        dataset.ReplaceVariable(v, originalValues[v]);
-      }
-      return impacts;
     }
 
     public static Dictionary<string, Tuple<IEnumerable<IRun>, Dictionary<string, double>>> CalculateVariableImpactsFromRunResults(RunCollection runs,
       string qualityResultName, bool maximization, string impactsResultName, bool useBestRunsPerTarget = false) {
-      var targets = runs.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).ToList();
+
+      Func<IRun, double> getQuality = run => ((DoubleValue)run.Results[qualityResultName]).Value;
+      var targetGroups = runs.GroupBy(x => ((IRegressionProblemData)x.Parameters["ProblemData"]).TargetVariable).ToList();
       var targetImpacts = new Dictionary<string, Tuple<IEnumerable<IRun>, Dictionary<string, double>>>();
 
-      Func<IRun, double> getQualityValue = run => ((DoubleValue)run.Results[qualityResultName]).Value;
-
       if (useBestRunsPerTarget) {
-        var bestRunsPerTarget = maximization
-          ? targets.Select(x => x.OrderBy(getQualityValue).Last())
-          : targets.Select(x => x.OrderBy(getQualityValue).First());
-
-        foreach (var run in bestRunsPerTarget) {
-          var pd = (IRegressionProblemData)run.Parameters["ProblemData"];
-          var target = pd.TargetVariable;
-          var impacts = (DoubleMatrix)run.Results[impactsResultName];
-          targetImpacts[target] = new Tuple<IEnumerable<IRun>, Dictionary<string, double>>(new[] { run }, impacts.RowNames.Select((x, i) => new { Name = x, Index = i }).ToDictionary(x => x.Name, x => impacts[x.Index, 0]));
+        foreach (var group in targetGroups) {
+          var ordered = group.OrderBy(getQuality);
+          var best = maximization ? ordered.Last() : ordered.First();
+          var pd = (IRegressionProblemData)best.Parameters["ProblemData"];
+          var target = group.Key;
+          var impacts = (DoubleMatrix)best.Results[impactsResultName];
+          targetImpacts[target] = Tuple.Create((IEnumerable<IRun>)new[] { best }, impacts.RowNames.Select((x, i) => new { x, i }).ToDictionary(x => x.x, x => impacts[x.i, 0]));
         }
       } else {
-        foreach (var target in targets) {
+        foreach (var target in targetGroups) {
           var averageImpacts = CalculateAverageImpacts(new RunCollection(target), impactsResultName);
           targetImpacts[target.Key] = new Tuple<IEnumerable<IRun>, Dictionary<string, double>>(target, averageImpacts);
@@ -460,5 +437,5 @@
       worker.DoWork += (o, e) => {
         ControlsEnable(false);
-        var impacts = CalculateVariableImpactsOnline(Content, false);
+        var impacts = CalculateVariableImpactsOnline(Content, impactAggregationComboBox.SelectedIndex == 0);
         variableInteractionNetwork = CreateNetwork(impacts);
         var threshold = impactThresholdTrackBar.Minimum + (double)impactThresholdTrackBar.Value / impactThresholdTrackBar.Maximum;
Index: branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/HeuristicLab.VariableInteractionNetworks-3.3.csproj
===================================================================
--- branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/HeuristicLab.VariableInteractionNetworks-3.3.csproj	(revision 16288)
+++ branches/2288_HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/HeuristicLab.VariableInteractionNetworks-3.3.csproj	(revision 16295)
@@ -111,14 +111,4 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll</HintPath>
-      <Private>False</Private>
-    </Reference>
-    <Reference Include="HeuristicLab.MainForm-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.MainForm-3.3.dll</HintPath>
-      <Private>False</Private>
-    </Reference>
-    <Reference Include="HeuristicLab.MainForm.WindowsForms-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.MainForm.WindowsForms-3.3.dll</HintPath>
       <Private>False</Private>
     </Reference>
