Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/19/13 12:02:44 (12 years ago)
Author:
ascheibe
Message:

#2031 the ResultCorrelationView can now also handle parameters and IntValues

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

Legend:

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

    r9380 r9382  
    4949    }
    5050
     51    private Dictionary<string, ResultParameterType> resultsParameters;
     52
    5153    protected override void OnContentChanged() {
    5254      base.OnContentChanged();
     
    5456
    5557      if (Content != null) {
     58        resultsParameters = GetRowNames();
    5659        UpdateResultComboBox();
    5760      }
     
    6467      Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    6568      Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    66 
    67       RegisterRunEvents(Content);
    68     }
    69 
    70     private void RegisterRunEvents(IEnumerable<IRun> runs) {
    71       foreach (IRun run in runs)
    72         run.Changed += new EventHandler(run_Changed);
     69      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
    7370    }
    7471
     
    7875      Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    7976      Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    80 
    81       DeregisterRunEvents(Content);
    82     }
    83 
    84     private void DeregisterRunEvents(IEnumerable<IRun> runs) {
    85       foreach (IRun run in runs)
    86         run.Changed -= new EventHandler(run_Changed);
     77      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
    8778    }
    8879
    8980    private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    90       DeregisterRunEvents(e.OldItems);
    91       RegisterRunEvents(e.Items);
    92       //RebuildInfluenceDataTable();
     81      RebuildCorrelationTable();
    9382    }
    9483
    9584    private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    96       DeregisterRunEvents(e.Items);
    97       //RebuildInfluenceDataTable();
     85      RebuildCorrelationTable();
    9886    }
    9987
    10088    private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    101       RegisterRunEvents(e.Items);
    102       //RebuildInfluenceDataTable();
    103     }
    104 
    105     private void run_Changed(object sender, EventArgs e) {
    106       if (InvokeRequired)
    107         this.Invoke(new EventHandler(run_Changed), sender, e);
    108       else {
    109         IRun run = (IRun)sender;
    110         UpdateRun(run);
     89      RebuildCorrelationTable();
     90    }
     91
     92    void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
     93      if (!Content.UpdateOfRunsInProgress) {
     94        RebuildCorrelationTable();
    11195      }
    11296    }
    11397    #endregion
    114 
    115     private void UpdateRun(IRun run) {
    116       //TODO: hacky di hack... this is baaaadddd
    117       RebuildCorrelationTable();
    118     }
    11998
    12099    private void UpdateResultComboBox() {
    121100      resultComboBox.Items.Clear();
     101
     102      resultComboBox.Items.AddRange(resultsParameters.Keys.ToArray());
     103      if (resultComboBox.Items.Count > 0) resultComboBox.SelectedItem = resultComboBox.Items[0];
     104    }
     105
     106    private List<string> GetResultRowNames() {
    122107      var results = (from run in Content
     108                     where run.Visible
    123109                     from result in run.Results
    124                      select result.Key).Distinct().ToArray();
    125 
    126       resultComboBox.Items.AddRange(results);
    127       if (resultComboBox.Items.Count > 0) resultComboBox.SelectedItem = resultComboBox.Items[0];
    128     }
    129 
    130 
    131     private List<string> GetRowNames() {
    132       string resultName = (string)resultComboBox.SelectedItem;
    133       var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
    134       List<string> ret = new List<string>();
     110                     where result.Value is DoubleValue || result.Value is IntValue
     111                     select result.Key).Distinct().ToList();
     112
     113      return results;
     114    }
     115
     116    private List<string> GetParameterRowNames() {
     117      var parameters = (from run in Content
     118                        where run.Visible
     119                        from parameter in run.Parameters
     120                        where parameter.Value is DoubleValue || parameter.Value is IntValue
     121                        select parameter.Key).Distinct().ToList();
     122
     123      return parameters;
     124    }
     125
     126    private Dictionary<string, ResultParameterType> GetRowNames() {
     127      Dictionary<string, ResultParameterType> ret = new Dictionary<string, ResultParameterType>();
     128
     129      var results = GetResultRowNames();
     130      var parameters = GetParameterRowNames();
     131
     132      foreach (var r in results) {
     133        ret.Add(r, ResultParameterType.Result);
     134      }
     135      foreach (var p in parameters) {
     136        if (!ret.ContainsKey(p)) {
     137          ret.Add(p, ResultParameterType.Parameter);
     138        }
     139      }
     140
     141      return ret;
     142    }
     143
     144    private List<double> GetDoublesFromResults(List<IRun> runs, string key) {
     145      List<double> res = new List<double>();
    135146
    136147      foreach (var r in runs) {
    137         var ress = r.Results.Where(y => y.Value is DoubleValue).Select(z => z.Key);
    138         foreach (var s in ress) {
    139           if (!ret.Contains(s))
    140             ret.Add(s);
    141         }
    142       }
    143 
    144       return ret;
     148        if (r.Results[key] is DoubleValue) {
     149          res.Add(((DoubleValue)r.Results[key]).Value);
     150        } else {
     151          res.Add(((IntValue)r.Results[key]).Value);
     152        }
     153      }
     154      return res;
     155    }
     156
     157    private List<double> GetDoublesFromParameters(List<IRun> runs, string key) {
     158      List<double> res = new List<double>();
     159
     160      foreach (var r in runs) {
     161        if (r.Parameters[key] is DoubleValue) {
     162          res.Add(((DoubleValue)r.Parameters[key]).Value);
     163        } else {
     164          res.Add(((IntValue)r.Parameters[key]).Value);
     165        }
     166      }
     167      return res;
    145168    }
    146169
     
    151174      columnNames[0] = "Pearson product-moment correlation coefficient";
    152175      columnNames[1] = "Spearman's rank correlation coefficient";
    153       var rowNames = GetRowNames();
     176
    154177
    155178      var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
    156179
    157       DoubleMatrix dt = new DoubleMatrix(rowNames.Count(), columnNames.Count());
    158       dt.RowNames = rowNames;
     180      DoubleMatrix dt = new DoubleMatrix(resultsParameters.Count(), columnNames.Count());
     181      dt.RowNames = resultsParameters.Keys.ToArray();
    159182      dt.ColumnNames = columnNames;
    160183
    161184      int j = 0;
    162       foreach (var rowName in rowNames) {
    163         var resultRowVals = runs.Where(x => x.Results.ContainsKey(rowName)).Where(x => x.Results[rowName] is DoubleValue).Select(x => ((DoubleValue)x.Results[rowName]).Value);
    164         var resultVals = runs.Where(x => x.Results.ContainsKey(resultName)).Where(x => x.Results[resultName] is DoubleValue).Select(x => ((DoubleValue)x.Results[resultName]).Value);
     185      foreach (var rowName in resultsParameters) {
     186        var resultVals = GetDoublesFromResults(runs.Where(x => x.Results.ContainsKey(resultName)).Where(x => x.Results[resultName] is DoubleValue || x.Results[resultName] is IntValue).ToList(), resultName);
     187
     188        List<double> resultRowVals = new List<double>();
     189        if (rowName.Value == ResultParameterType.Result) {
     190          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);
     191        } else {
     192          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);
     193        }
    165194
    166195        if (resultVals.Contains(double.NaN)
     
    184213      RebuildCorrelationTable();
    185214    }
     215
     216    private enum ResultParameterType {
     217      Result,
     218      Parameter
     219    }
    186220  }
    187221}
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ResultCorrelationView.designer.cs

    r9380 r9382  
    6060      this.stringConvertibleMatrixView.Location = new System.Drawing.Point(3, 30);
    6161      this.stringConvertibleMatrixView.Name = "stringConvertibleMatrixView";
    62       this.stringConvertibleMatrixView.ReadOnly = false;
     62      this.stringConvertibleMatrixView.ReadOnly = true;
    6363      this.stringConvertibleMatrixView.ShowRowsAndColumnsTextBox = true;
    6464      this.stringConvertibleMatrixView.ShowStatisticalInformation = true;
Note: See TracChangeset for help on using the changeset viewer.