Changeset 12684 for trunk/sources/HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs
- Timestamp:
- 07/08/15 13:59:55 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs
r12613 r12684 27 27 using HeuristicLab.Collections; 28 28 using HeuristicLab.Common; 29 using HeuristicLab.Common.Resources; 29 30 using HeuristicLab.Core.Views; 30 31 using HeuristicLab.Data; … … 40 41 private const int requiredSampleSize = 5; 41 42 private double[][] data; 42 private bool suppressUpdates = false;43 private bool initializing = false;43 private bool suppressUpdates; 44 private bool initializing; 44 45 45 46 public double SignificanceLevel { … … 78 79 79 80 if (Content != null) { 80 initializing = true; 81 UpdateResultComboBox(); 82 UpdateGroupsComboBox(); 83 RebuildDataTable(); 84 FillCompComboBox(); 81 UpdateUI(); 82 } else { 85 83 ResetUI(); 86 CalculateValues();87 initializing = false;88 84 } 89 85 UpdateCaption(); 86 } 87 88 private void UpdateUI() { 89 initializing = true; 90 UpdateResultComboBox(); 91 UpdateGroupsComboBox(); 92 RebuildDataTable(); 93 FillCompComboBox(); 94 ResetUI(); 95 CalculateValues(); 96 initializing = false; 90 97 } 91 98 … … 99 106 Content.ColumnsChanged += Content_ColumnsChanged; 100 107 Content.RowsChanged += Content_RowsChanged; 101 Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);108 Content.CollectionReset += Content_CollectionReset; 102 109 Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged; 103 110 } … … 107 114 Content.ColumnsChanged -= Content_ColumnsChanged; 108 115 Content.RowsChanged -= Content_RowsChanged; 109 Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);116 Content.CollectionReset -= Content_CollectionReset; 110 117 Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged; 111 118 } … … 115 122 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_RowsChanged, sender, e); 116 123 else { 117 RebuildDataTable();124 UpdateUI(); 118 125 } 119 126 } … … 123 130 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ColumnsChanged, sender, e); 124 131 else { 125 RebuildDataTable();132 UpdateUI(); 126 133 } 127 134 } … … 131 138 if (InvokeRequired) Invoke((Action<object, CollectionItemsChangedEventArgs<IRun>>)Content_CollectionReset, sender, e); 132 139 else { 133 RebuildDataTable();140 UpdateUI(); 134 141 } 135 142 } … … 139 146 else { 140 147 suppressUpdates = Content.UpdateOfRunsInProgress; 141 if (!suppressUpdates) RebuildDataTable();148 if (!suppressUpdates) UpdateUI(); 142 149 } 143 150 } … … 153 160 154 161 private void groupCompComboBox_SelectedValueChanged(object sender, EventArgs e) { 155 if (initializing ) return;162 if (initializing || suppressUpdates) return; 156 163 string curItem = (string)groupCompComboBox.SelectedItem; 157 164 CalculatePairwise(curItem); … … 159 166 160 167 private void resultComboBox_SelectedValueChanged(object sender, EventArgs e) { 161 if (initializing ) return;168 if (initializing || suppressUpdates) return; 162 169 RebuildDataTable(); 163 170 ResetUI(); … … 166 173 167 174 private void groupComboBox_SelectedValueChanged(object sender, EventArgs e) { 168 if (initializing ) return;175 if (initializing || suppressUpdates) return; 169 176 RebuildDataTable(); 170 177 FillCompComboBox(); … … 175 182 176 183 private void UpdateGroupsComboBox() { 184 string selectedItem = (string)groupComboBox.SelectedItem; 185 177 186 groupComboBox.Items.Clear(); 178 179 187 var parameters = (from run in Content 180 188 where run.Visible … … 205 213 } 206 214 207 if (possibleIndizes.Count > 0) { 215 if (selectedItem != null && groupComboBox.Items.Contains(selectedItem)) { 216 groupComboBox.SelectedItem = selectedItem; 217 } else if (possibleIndizes.Count > 0) { 208 218 groupComboBox.SelectedItem = groupComboBox.Items[possibleIndizes.First()]; 209 } else {210 groupComboBox.SelectedItem = groupComboBox.Items[0];211 219 } 212 220 } … … 220 228 221 229 private void UpdateResultComboBox() { 230 string selectedItem = (string)resultComboBox.SelectedItem; 231 222 232 resultComboBox.Items.Clear(); 223 233 var results = (from run in Content … … 228 238 229 239 resultComboBox.Items.AddRange(results); 230 if (resultComboBox.Items.Count > 0) resultComboBox.SelectedItem = resultComboBox.Items[0]; 240 241 if (selectedItem != null && resultComboBox.Items.Contains(selectedItem)) { 242 resultComboBox.SelectedItem = selectedItem; 243 } else if (resultComboBox.Items.Count > 0) { 244 resultComboBox.SelectedItem = resultComboBox.Items[0]; 245 } 231 246 } 232 247 233 248 private void FillCompComboBox() { 249 string selectedItem = (string)groupCompComboBox.SelectedItem; 234 250 string parameterName = (string)groupComboBox.SelectedItem; 235 251 if (parameterName != null) { … … 240 256 groupCompComboBox.Items.Clear(); 241 257 columnNames.ForEach(x => groupCompComboBox.Items.Add(x)); 242 if (groupCompComboBox.Items.Count > 0) groupCompComboBox.SelectedItem = groupCompComboBox.Items[0]; 258 if (selectedItem != null && groupCompComboBox.Items.Contains(selectedItem)) { 259 groupCompComboBox.SelectedItem = selectedItem; 260 } else if (groupCompComboBox.Items.Count > 0) { 261 groupCompComboBox.SelectedItem = groupCompComboBox.Items[0]; 262 } 243 263 } 244 264 } … … 330 350 331 351 if (data != null && data.All(x => x != null)) { 332 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>()352 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>() 333 353 .AddOperationProgressToView(this, "Calculating..."); 334 354 … … 343 363 CalculatePairwiseTest(groupName); 344 364 345 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);365 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); 346 366 } 347 367 348 368 private void CalculatePairwise(string groupName) { 369 if (groupName == null) return; 349 370 if (!VerifyDataLength(false)) 350 371 return; 351 372 352 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");373 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating..."); 353 374 Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName)); 354 375 } … … 357 378 CalculatePairwiseTest(groupName); 358 379 359 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);380 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox); 360 381 } 361 382 … … 364 385 pValTextBox.Text = pval.ToString(); 365 386 if (pval < significanceLevel) { 366 this.Invoke(new Action(() => {367 groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;387 Invoke(new Action(() => { 388 groupCompLabel.Image = VSImageLibrary.Default; 368 389 groupComTextLabel.Text = "There are groups with different distributions"; 369 390 })); 370 391 } else { 371 this.Invoke(new Action(() => {372 groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;392 Invoke(new Action(() => { 393 groupCompLabel.Image = VSImageLibrary.Warning; 373 394 groupComTextLabel.Text = "Groups have an equal distribution"; 374 395 })); … … 381 402 DoubleMatrix pValsMatrix = new DoubleMatrix(1, stringConvertibleMatrixView.Content.Columns); 382 403 pValsMatrix.ColumnNames = stringConvertibleMatrixView.Content.ColumnNames; 383 pValsMatrix.RowNames = new string[] { "p-Value" };404 pValsMatrix.RowNames = new[] { "p-Value" }; 384 405 385 406 for (int i = 0; i < data.Length; i++) { … … 391 412 // p-value is below significance level and thus the null hypothesis (data is normally distributed) is rejected 392 413 if (res.Any(x => x < significanceLevel)) { 393 this.Invoke(new Action(() => {394 normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;414 Invoke(new Action(() => { 415 normalityLabel.Image = VSImageLibrary.Warning; 395 416 normalityTextLabel.Text = "Some groups may not be normally distributed"; 396 417 })); 397 418 } else { 398 this.Invoke(new Action(() => {399 normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;419 Invoke(new Action(() => { 420 normalityLabel.Image = VSImageLibrary.Default; 400 421 normalityTextLabel.Text = "All sample data is normally distributed"; 401 422 })); 402 423 } 403 424 404 this.Invoke(new Action(() => {425 Invoke(new Action(() => { 405 426 normalityStringConvertibleMatrixView.Content = pValsMatrix; 406 427 normalityStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); … … 410 431 private void ShowPairwiseResult(int nrOfEqualDistributions) { 411 432 double ratio = ((double)nrOfEqualDistributions) / (data.Length - 1) * 100.0; 412 equalDistsTextBox.Text = ratio .ToString()+ " %";433 equalDistsTextBox.Text = ratio + " %"; 413 434 414 435 if (nrOfEqualDistributions == 0) { 415 this.Invoke(new Action(() => {416 pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;436 Invoke(new Action(() => { 437 pairwiseLabel.Image = VSImageLibrary.Default; 417 438 pairwiseTextLabel.Text = "All groups have different distributions"; 418 439 })); 419 440 } else { 420 this.Invoke(new Action(() => {421 pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;441 Invoke(new Action(() => { 442 pairwiseLabel.Image = VSImageLibrary.Warning; 422 443 pairwiseTextLabel.Text = "Some groups have equal distributions"; 423 444 })); … … 432 453 double[][] newData = FilterDataForPairwiseTest(colIndex); 433 454 434 var rowNames = new string[] { "p-Value of Mann-Whitney U", "Adjusted p-Value of Mann-Whitney U",455 var rowNames = new[] { "p-Value of Mann-Whitney U", "Adjusted p-Value of Mann-Whitney U", 435 456 "p-Value of T-Test", "Adjusted p-Value of T-Test", "Cohen's d", "Hedges' g" }; 436 457 … … 471 492 } 472 493 473 this.Invoke(new Action(() => {494 Invoke(new Action(() => { 474 495 pairwiseStringConvertibleMatrixView.Content = pValsMatrix; 475 496 pairwiseStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
Note: See TracChangeset
for help on using the changeset viewer.