Changeset 11644 for branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.cs
- Timestamp:
- 12/04/14 10:59:47 (10 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.