Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11644


Ignore:
Timestamp:
12/04/14 10:59:47 (10 years ago)
Author:
ascheibe
Message:

#2031 implemented review comments for correlations view

Location:
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.cs

    r11379 r11644  
    3434  [Content(typeof(RunCollection), false)]
    3535  public sealed partial class CorrelationView : ItemView {
     36    private const string PearsonName = "Pearson product-moment correlation coefficient";
     37    private const string SpearmanName = "Spearman's rank correlation coefficient";
     38
    3639    private enum ResultParameterType {
    3740      Result,
     
    3942    }
    4043
     44    private bool suppressUpdates = false;
     45
    4146    public new RunCollection Content {
    4247      get { return (RunCollection)base.Content; }
     
    4853      set { /*not needed because results are always readonly */}
    4954    }
    50 
    51     private Dictionary<string, ResultParameterType> resultsParameters;
    52     private bool suppressUpdates = false;
    5355
    5456    public CorrelationView() {
     
    5658      stringConvertibleMatrixView.Minimum = -1.0;
    5759      stringConvertibleMatrixView.Maximum = 1.0;
     60
     61      methodComboBox.Items.Add(PearsonName);
     62      methodComboBox.Items.Add(SpearmanName);
     63      methodComboBox.SelectedIndex = 0;
    5864    }
    5965
    6066    protected override void OnContentChanged() {
    6167      base.OnContentChanged();
    62       resultComboBox.Items.Clear();
    6368
    6469      if (Content != null) {
    65         UpdateResultComboBox();
     70        RebuildCorrelationTable();
    6671      }
    6772      UpdateCaption();
     
    174179    private void UpdateUI() {
    175180      if (!suppressUpdates) {
    176         UpdateResultComboBox();
    177181        RebuildCorrelationTable();
    178       }
    179     }
    180 
    181     private void UpdateResultComboBox() {
    182       resultsParameters = GetRowNames();
    183       string selectedResult = (string)this.resultComboBox.SelectedItem;
    184       resultComboBox.Items.Clear();
    185       resultComboBox.Items.AddRange(resultsParameters.Keys.ToArray());
    186 
    187       if (selectedResult != null && resultComboBox.Items.Contains(selectedResult)) {
    188         resultComboBox.SelectedItem = selectedResult;
    189       } else if (resultComboBox.Items.Count > 0) {
    190         resultComboBox.SelectedItem = resultComboBox.Items[0];
    191182      }
    192183    }
     
    197188                     from result in run.Results
    198189                     where result.Value is DoubleValue || result.Value is IntValue
    199                      select result.Key).Distinct().ToList();
     190                     select result.Key).Distinct().OrderBy(x => x).ToList();
    200191
    201192      return results;
     
    207198                        from parameter in run.Parameters
    208199                        where parameter.Value is DoubleValue || parameter.Value is IntValue
    209                         select parameter.Key).Distinct().ToList();
     200                        select parameter.Key).Distinct().OrderBy(x => x).ToList();
    210201
    211202      return parameters;
     
    256247    }
    257248
     249    private List<double> GetValuesFromResultsParameters(IEnumerable<IRun> runs, string name, ResultParameterType type) {
     250      if (type == ResultParameterType.Parameter) {
     251        return GetDoublesFromParameters(runs.Where(x => x.Parameters.ContainsKey(name)).ToList(), name);
     252      } else if (type == ResultParameterType.Result) {
     253        return GetDoublesFromResults(runs.Where(x => x.Results.ContainsKey(name)).ToList(), name);
     254      } else {
     255        return null;
     256      }
     257    }
     258
    258259    private void RebuildCorrelationTable() {
    259       string resultName = (string)resultComboBox.SelectedItem;
    260 
    261       var columnNames = new string[2];
    262       columnNames[0] = "Pearson product-moment correlation coefficient";
    263       columnNames[1] = "Spearman's rank correlation coefficient";
    264 
    265       var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
     260      Dictionary<string, ResultParameterType> resultsParameters = GetRowNames();
     261      string methodName = (string)methodComboBox.SelectedItem;
     262      var columnNames = resultsParameters.Keys.ToArray();
     263
     264      var runs = Content.Where(x => x.Visible);
    266265
    267266      DoubleMatrix dt = new DoubleMatrix(resultsParameters.Count(), columnNames.Count());
    268       dt.RowNames = resultsParameters.Keys.ToArray();
     267      dt.RowNames = columnNames;
    269268      dt.ColumnNames = columnNames;
    270269
    271       int j = 0;
    272       foreach (var rowName in resultsParameters) {
    273         var resultVals = GetDoublesFromResults(runs.Where(x => x.Results.ContainsKey(resultName)).Where(x => x.Results[resultName] is DoubleValue || x.Results[resultName] is IntValue).ToList(), resultName);
    274 
    275         List<double> resultRowVals;
    276         if (rowName.Value == ResultParameterType.Result) {
    277           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);
    278         } else {
    279           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);
     270      int i = 0;
     271      foreach (var res in resultsParameters) {
     272        var rowValues =
     273          GetValuesFromResultsParameters(runs, res.Key, res.Value)
     274            .Where(x => !double.IsNaN(x) && !double.IsNegativeInfinity(x) && !double.IsPositiveInfinity(x));
     275
     276        int j = 0;
     277        foreach (var cres in resultsParameters) {
     278          var columnValues = GetValuesFromResultsParameters(runs, cres.Key, cres.Value)
     279                .Where(x => !double.IsNaN(x) && !double.IsNegativeInfinity(x) && !double.IsPositiveInfinity(x));
     280
     281          if (!rowValues.Any() || !columnValues.Any() || i == j || rowValues.Count() != columnValues.Count()) {
     282            dt[i, j] = double.NaN;
     283          } else {
     284            if (methodName == PearsonName) {
     285              dt[i, j] = alglib.pearsoncorr2(rowValues.ToArray(), columnValues.ToArray());
     286            } else {
     287              dt[i, j] = alglib.spearmancorr2(rowValues.ToArray(), columnValues.ToArray());
     288            }
     289          }
     290          j++;
    280291        }
    281 
    282         resultVals = resultVals.Where(x => !double.IsNaN(x) && !double.IsNegativeInfinity(x) && !double.IsPositiveInfinity(x)).ToList();
    283         resultRowVals = resultRowVals.Where(x => !double.IsNaN(x) && !double.IsNegativeInfinity(x) && !double.IsPositiveInfinity(x)).ToList();
    284 
    285         if (resultRowVals.Count == 0 || resultVals.Count == 0 || resultRowVals.Count != resultVals.Count) {
    286           dt[j, 0] = double.NaN;
    287           dt[j++, 1] = double.NaN;
    288         } else {
    289           dt[j, 0] = alglib.pearsoncorr2(resultVals.ToArray(), resultRowVals.ToArray());
    290           dt[j++, 1] = alglib.spearmancorr2(resultVals.ToArray(), resultRowVals.ToArray());
    291         }
     292        i++;
    292293      }
    293294
     
    296297    }
    297298
    298     private void resultComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    299       RebuildCorrelationTable();
     299    private void methodComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     300      if (Content != null) {
     301        RebuildCorrelationTable();
     302      }
    300303    }
    301304  }
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.designer.cs

    r11375 r11644  
    4747      this.stringConvertibleMatrixView = new HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView();
    4848      this.label1 = new System.Windows.Forms.Label();
    49       this.resultComboBox = new System.Windows.Forms.ComboBox();
     49      this.methodComboBox = new System.Windows.Forms.ComboBox();
    5050      this.SuspendLayout();
    5151      //
    5252      // stringConvertibleMatrixView
    5353      //
    54       this.stringConvertibleMatrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    55             | System.Windows.Forms.AnchorStyles.Left)
     54      this.stringConvertibleMatrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     55            | System.Windows.Forms.AnchorStyles.Left) 
    5656            | System.Windows.Forms.AnchorStyles.Right)));
    5757      this.stringConvertibleMatrixView.Caption = "StringConvertibleMatrix View";
    5858      this.stringConvertibleMatrixView.Content = null;
    5959      this.stringConvertibleMatrixView.Location = new System.Drawing.Point(3, 30);
     60      this.stringConvertibleMatrixView.Maximum = 0D;
     61      this.stringConvertibleMatrixView.Minimum = 0D;
    6062      this.stringConvertibleMatrixView.Name = "stringConvertibleMatrixView";
    6163      this.stringConvertibleMatrixView.ReadOnly = true;
     
    7072      this.label1.Location = new System.Drawing.Point(5, 6);
    7173      this.label1.Name = "label1";
    72       this.label1.Size = new System.Drawing.Size(37, 13);
     74      this.label1.Size = new System.Drawing.Size(46, 13);
    7375      this.label1.TabIndex = 6;
    74       this.label1.Text = "Value:";
     76      this.label1.Text = "Method:";
    7577      //
    76       // resultComboBox
     78      // methodComboBox
    7779      //
    78       this.resultComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     80      this.methodComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    7981            | System.Windows.Forms.AnchorStyles.Right)));
    80       this.resultComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    81       this.resultComboBox.FormattingEnabled = true;
    82       this.resultComboBox.Location = new System.Drawing.Point(71, 3);
    83       this.resultComboBox.Name = "resultComboBox";
    84       this.resultComboBox.Size = new System.Drawing.Size(424, 21);
    85       this.resultComboBox.TabIndex = 5;
    86       this.resultComboBox.SelectedIndexChanged += new System.EventHandler(this.resultComboBox_SelectedIndexChanged);
     82      this.methodComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     83      this.methodComboBox.FormattingEnabled = true;
     84      this.methodComboBox.Location = new System.Drawing.Point(71, 3);
     85      this.methodComboBox.Name = "methodComboBox";
     86      this.methodComboBox.Size = new System.Drawing.Size(424, 21);
     87      this.methodComboBox.TabIndex = 5;
     88      this.methodComboBox.SelectedIndexChanged += new System.EventHandler(this.methodComboBox_SelectedIndexChanged);
    8789      //
    8890      // CorrelationView
    8991      //
    9092      this.Controls.Add(this.label1);
    91       this.Controls.Add(this.resultComboBox);
     93      this.Controls.Add(this.methodComboBox);
    9294      this.Controls.Add(this.stringConvertibleMatrixView);
    9395      this.Name = "CorrelationView";
     
    101103    private HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView stringConvertibleMatrixView;
    102104    private System.Windows.Forms.Label label1;
    103     private System.Windows.Forms.ComboBox resultComboBox;
     105    private System.Windows.Forms.ComboBox methodComboBox;
    104106  }
    105107}
Note: See TracChangeset for help on using the changeset viewer.