Index: /branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.cs
===================================================================
--- /branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.cs	(revision 11643)
+++ /branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.cs	(revision 11644)
@@ -34,4 +34,7 @@
   [Content(typeof(RunCollection), false)]
   public sealed partial class CorrelationView : ItemView {
+    private const string PearsonName = "Pearson product-moment correlation coefficient";
+    private const string SpearmanName = "Spearman's rank correlation coefficient";
+
     private enum ResultParameterType {
       Result,
@@ -39,4 +42,6 @@
     }
 
+    private bool suppressUpdates = false;
+
     public new RunCollection Content {
       get { return (RunCollection)base.Content; }
@@ -48,7 +53,4 @@
       set { /*not needed because results are always readonly */}
     }
-
-    private Dictionary<string, ResultParameterType> resultsParameters;
-    private bool suppressUpdates = false;
 
     public CorrelationView() {
@@ -56,12 +58,15 @@
       stringConvertibleMatrixView.Minimum = -1.0;
       stringConvertibleMatrixView.Maximum = 1.0;
+
+      methodComboBox.Items.Add(PearsonName);
+      methodComboBox.Items.Add(SpearmanName);
+      methodComboBox.SelectedIndex = 0;
     }
 
     protected override void OnContentChanged() {
       base.OnContentChanged();
-      resultComboBox.Items.Clear();
 
       if (Content != null) {
-        UpdateResultComboBox();
+        RebuildCorrelationTable();
       }
       UpdateCaption();
@@ -174,19 +179,5 @@
     private void UpdateUI() {
       if (!suppressUpdates) {
-        UpdateResultComboBox();
         RebuildCorrelationTable();
-      }
-    }
-
-    private void UpdateResultComboBox() {
-      resultsParameters = GetRowNames();
-      string selectedResult = (string)this.resultComboBox.SelectedItem;
-      resultComboBox.Items.Clear();
-      resultComboBox.Items.AddRange(resultsParameters.Keys.ToArray());
-
-      if (selectedResult != null && resultComboBox.Items.Contains(selectedResult)) {
-        resultComboBox.SelectedItem = selectedResult;
-      } else if (resultComboBox.Items.Count > 0) {
-        resultComboBox.SelectedItem = resultComboBox.Items[0];
       }
     }
@@ -197,5 +188,5 @@
                      from result in run.Results
                      where result.Value is DoubleValue || result.Value is IntValue
-                     select result.Key).Distinct().ToList();
+                     select result.Key).Distinct().OrderBy(x => x).ToList();
 
       return results;
@@ -207,5 +198,5 @@
                         from parameter in run.Parameters
                         where parameter.Value is DoubleValue || parameter.Value is IntValue
-                        select parameter.Key).Distinct().ToList();
+                        select parameter.Key).Distinct().OrderBy(x => x).ToList();
 
       return parameters;
@@ -256,38 +247,48 @@
     }
 
+    private List<double> GetValuesFromResultsParameters(IEnumerable<IRun> runs, string name, ResultParameterType type) {
+      if (type == ResultParameterType.Parameter) {
+        return GetDoublesFromParameters(runs.Where(x => x.Parameters.ContainsKey(name)).ToList(), name);
+      } else if (type == ResultParameterType.Result) {
+        return GetDoublesFromResults(runs.Where(x => x.Results.ContainsKey(name)).ToList(), name);
+      } else {
+        return null;
+      }
+    }
+
     private void RebuildCorrelationTable() {
-      string resultName = (string)resultComboBox.SelectedItem;
-
-      var columnNames = new string[2];
-      columnNames[0] = "Pearson product-moment correlation coefficient";
-      columnNames[1] = "Spearman's rank correlation coefficient";
-
-      var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
+      Dictionary<string, ResultParameterType> resultsParameters = GetRowNames();
+      string methodName = (string)methodComboBox.SelectedItem;
+      var columnNames = resultsParameters.Keys.ToArray();
+
+      var runs = Content.Where(x => x.Visible);
 
       DoubleMatrix dt = new DoubleMatrix(resultsParameters.Count(), columnNames.Count());
-      dt.RowNames = resultsParameters.Keys.ToArray();
+      dt.RowNames = columnNames;
       dt.ColumnNames = columnNames;
 
-      int j = 0;
-      foreach (var rowName in resultsParameters) {
-        var resultVals = GetDoublesFromResults(runs.Where(x => x.Results.ContainsKey(resultName)).Where(x => x.Results[resultName] is DoubleValue || x.Results[resultName] is IntValue).ToList(), resultName);
-
-        List<double> resultRowVals;
-        if (rowName.Value == ResultParameterType.Result) {
-          resultRowVals = GetDoublesFromResults(runs.Where(x => x.Results.ContainsKey(rowName.Key)).Where(x => x.Results[rowName.Key] is DoubleValue || x.Results[rowName.Key] is IntValue).ToList(), rowName.Key);
-        } else {
-          resultRowVals = GetDoublesFromParameters(runs.Where(x => x.Parameters.ContainsKey(rowName.Key)).Where(x => x.Parameters[rowName.Key] is DoubleValue || x.Parameters[rowName.Key] is IntValue).ToList(), rowName.Key);
+      int i = 0;
+      foreach (var res in resultsParameters) {
+        var rowValues =
+          GetValuesFromResultsParameters(runs, res.Key, res.Value)
+            .Where(x => !double.IsNaN(x) && !double.IsNegativeInfinity(x) && !double.IsPositiveInfinity(x));
+
+        int j = 0;
+        foreach (var cres in resultsParameters) {
+          var columnValues = GetValuesFromResultsParameters(runs, cres.Key, cres.Value)
+                .Where(x => !double.IsNaN(x) && !double.IsNegativeInfinity(x) && !double.IsPositiveInfinity(x));
+
+          if (!rowValues.Any() || !columnValues.Any() || i == j || rowValues.Count() != columnValues.Count()) {
+            dt[i, j] = double.NaN;
+          } else {
+            if (methodName == PearsonName) {
+              dt[i, j] = alglib.pearsoncorr2(rowValues.ToArray(), columnValues.ToArray());
+            } else {
+              dt[i, j] = alglib.spearmancorr2(rowValues.ToArray(), columnValues.ToArray());
+            }
+          }
+          j++;
         }
-
-        resultVals = resultVals.Where(x => !double.IsNaN(x) && !double.IsNegativeInfinity(x) && !double.IsPositiveInfinity(x)).ToList();
-        resultRowVals = resultRowVals.Where(x => !double.IsNaN(x) && !double.IsNegativeInfinity(x) && !double.IsPositiveInfinity(x)).ToList();
-
-        if (resultRowVals.Count == 0 || resultVals.Count == 0 || resultRowVals.Count != resultVals.Count) {
-          dt[j, 0] = double.NaN;
-          dt[j++, 1] = double.NaN;
-        } else {
-          dt[j, 0] = alglib.pearsoncorr2(resultVals.ToArray(), resultRowVals.ToArray());
-          dt[j++, 1] = alglib.spearmancorr2(resultVals.ToArray(), resultRowVals.ToArray());
-        }
+        i++;
       }
 
@@ -296,6 +297,8 @@
     }
 
-    private void resultComboBox_SelectedIndexChanged(object sender, EventArgs e) {
-      RebuildCorrelationTable();
+    private void methodComboBox_SelectedIndexChanged(object sender, EventArgs e) {
+      if (Content != null) {
+        RebuildCorrelationTable();
+      }
     }
   }
Index: /branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.designer.cs
===================================================================
--- /branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.designer.cs	(revision 11643)
+++ /branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.designer.cs	(revision 11644)
@@ -47,15 +47,17 @@
       this.stringConvertibleMatrixView = new HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView();
       this.label1 = new System.Windows.Forms.Label();
-      this.resultComboBox = new System.Windows.Forms.ComboBox();
+      this.methodComboBox = new System.Windows.Forms.ComboBox();
       this.SuspendLayout();
       // 
       // stringConvertibleMatrixView
       // 
-      this.stringConvertibleMatrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-            | System.Windows.Forms.AnchorStyles.Left)
+      this.stringConvertibleMatrixView.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.stringConvertibleMatrixView.Caption = "StringConvertibleMatrix View";
       this.stringConvertibleMatrixView.Content = null;
       this.stringConvertibleMatrixView.Location = new System.Drawing.Point(3, 30);
+      this.stringConvertibleMatrixView.Maximum = 0D;
+      this.stringConvertibleMatrixView.Minimum = 0D;
       this.stringConvertibleMatrixView.Name = "stringConvertibleMatrixView";
       this.stringConvertibleMatrixView.ReadOnly = true;
@@ -70,24 +72,24 @@
       this.label1.Location = new System.Drawing.Point(5, 6);
       this.label1.Name = "label1";
-      this.label1.Size = new System.Drawing.Size(37, 13);
+      this.label1.Size = new System.Drawing.Size(46, 13);
       this.label1.TabIndex = 6;
-      this.label1.Text = "Value:";
+      this.label1.Text = "Method:";
       // 
-      // resultComboBox
+      // methodComboBox
       // 
-      this.resultComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+      this.methodComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
-      this.resultComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
-      this.resultComboBox.FormattingEnabled = true;
-      this.resultComboBox.Location = new System.Drawing.Point(71, 3);
-      this.resultComboBox.Name = "resultComboBox";
-      this.resultComboBox.Size = new System.Drawing.Size(424, 21);
-      this.resultComboBox.TabIndex = 5;
-      this.resultComboBox.SelectedIndexChanged += new System.EventHandler(this.resultComboBox_SelectedIndexChanged);
+      this.methodComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+      this.methodComboBox.FormattingEnabled = true;
+      this.methodComboBox.Location = new System.Drawing.Point(71, 3);
+      this.methodComboBox.Name = "methodComboBox";
+      this.methodComboBox.Size = new System.Drawing.Size(424, 21);
+      this.methodComboBox.TabIndex = 5;
+      this.methodComboBox.SelectedIndexChanged += new System.EventHandler(this.methodComboBox_SelectedIndexChanged);
       // 
       // CorrelationView
       // 
       this.Controls.Add(this.label1);
-      this.Controls.Add(this.resultComboBox);
+      this.Controls.Add(this.methodComboBox);
       this.Controls.Add(this.stringConvertibleMatrixView);
       this.Name = "CorrelationView";
@@ -101,5 +103,5 @@
     private HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView stringConvertibleMatrixView;
     private System.Windows.Forms.Label label1;
-    private System.Windows.Forms.ComboBox resultComboBox;
+    private System.Windows.Forms.ComboBox methodComboBox;
   }
 }
