Changeset 11644
- Timestamp:
- 12/04/14 10:59:47 (10 years ago)
- 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 34 34 [Content(typeof(RunCollection), false)] 35 35 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 36 39 private enum ResultParameterType { 37 40 Result, … … 39 42 } 40 43 44 private bool suppressUpdates = false; 45 41 46 public new RunCollection Content { 42 47 get { return (RunCollection)base.Content; } … … 48 53 set { /*not needed because results are always readonly */} 49 54 } 50 51 private Dictionary<string, ResultParameterType> resultsParameters;52 private bool suppressUpdates = false;53 55 54 56 public CorrelationView() { … … 56 58 stringConvertibleMatrixView.Minimum = -1.0; 57 59 stringConvertibleMatrixView.Maximum = 1.0; 60 61 methodComboBox.Items.Add(PearsonName); 62 methodComboBox.Items.Add(SpearmanName); 63 methodComboBox.SelectedIndex = 0; 58 64 } 59 65 60 66 protected override void OnContentChanged() { 61 67 base.OnContentChanged(); 62 resultComboBox.Items.Clear();63 68 64 69 if (Content != null) { 65 UpdateResultComboBox();70 RebuildCorrelationTable(); 66 71 } 67 72 UpdateCaption(); … … 174 179 private void UpdateUI() { 175 180 if (!suppressUpdates) { 176 UpdateResultComboBox();177 181 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];191 182 } 192 183 } … … 197 188 from result in run.Results 198 189 where result.Value is DoubleValue || result.Value is IntValue 199 select result.Key).Distinct(). ToList();190 select result.Key).Distinct().OrderBy(x => x).ToList(); 200 191 201 192 return results; … … 207 198 from parameter in run.Parameters 208 199 where parameter.Value is DoubleValue || parameter.Value is IntValue 209 select parameter.Key).Distinct(). ToList();200 select parameter.Key).Distinct().OrderBy(x => x).ToList(); 210 201 211 202 return parameters; … … 256 247 } 257 248 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 258 259 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); 266 265 267 266 DoubleMatrix dt = new DoubleMatrix(resultsParameters.Count(), columnNames.Count()); 268 dt.RowNames = resultsParameters.Keys.ToArray();267 dt.RowNames = columnNames; 269 268 dt.ColumnNames = columnNames; 270 269 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++; 280 291 } 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++; 292 293 } 293 294 … … 296 297 } 297 298 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 } 300 303 } 301 304 } -
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.designer.cs
r11375 r11644 47 47 this.stringConvertibleMatrixView = new HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView(); 48 48 this.label1 = new System.Windows.Forms.Label(); 49 this. resultComboBox = new System.Windows.Forms.ComboBox();49 this.methodComboBox = new System.Windows.Forms.ComboBox(); 50 50 this.SuspendLayout(); 51 51 // 52 52 // stringConvertibleMatrixView 53 53 // 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) 56 56 | System.Windows.Forms.AnchorStyles.Right))); 57 57 this.stringConvertibleMatrixView.Caption = "StringConvertibleMatrix View"; 58 58 this.stringConvertibleMatrixView.Content = null; 59 59 this.stringConvertibleMatrixView.Location = new System.Drawing.Point(3, 30); 60 this.stringConvertibleMatrixView.Maximum = 0D; 61 this.stringConvertibleMatrixView.Minimum = 0D; 60 62 this.stringConvertibleMatrixView.Name = "stringConvertibleMatrixView"; 61 63 this.stringConvertibleMatrixView.ReadOnly = true; … … 70 72 this.label1.Location = new System.Drawing.Point(5, 6); 71 73 this.label1.Name = "label1"; 72 this.label1.Size = new System.Drawing.Size( 37, 13);74 this.label1.Size = new System.Drawing.Size(46, 13); 73 75 this.label1.TabIndex = 6; 74 this.label1.Text = " Value:";76 this.label1.Text = "Method:"; 75 77 // 76 // resultComboBox78 // methodComboBox 77 79 // 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) 79 81 | 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); 87 89 // 88 90 // CorrelationView 89 91 // 90 92 this.Controls.Add(this.label1); 91 this.Controls.Add(this. resultComboBox);93 this.Controls.Add(this.methodComboBox); 92 94 this.Controls.Add(this.stringConvertibleMatrixView); 93 95 this.Name = "CorrelationView"; … … 101 103 private HeuristicLab.Data.Views.EnhancedStringConvertibleMatrixView stringConvertibleMatrixView; 102 104 private System.Windows.Forms.Label label1; 103 private System.Windows.Forms.ComboBox resultComboBox;105 private System.Windows.Forms.ComboBox methodComboBox; 104 106 } 105 107 }
Note: See TracChangeset
for help on using the changeset viewer.