- Timestamp:
- 07/11/15 13:37:32 (9 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 12077,12112,12116-12117,12131,12173,12458,12599,12613,12631,12672,12684,12690,12692
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs
r12009 r12725 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; 43 private bool suppressUpdates; 44 private bool initializing; 42 45 43 46 public double SignificanceLevel { … … 76 79 77 80 if (Content != null) { 78 Update ResultComboBox();79 UpdateGroupsComboBox();80 Re buildDataTable();81 UpdateUI(); 82 } else { 83 ResetUI(); 81 84 } 82 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; 83 97 } 84 98 … … 92 106 Content.ColumnsChanged += Content_ColumnsChanged; 93 107 Content.RowsChanged += Content_RowsChanged; 94 Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);108 Content.CollectionReset += Content_CollectionReset; 95 109 Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged; 96 110 } … … 100 114 Content.ColumnsChanged -= Content_ColumnsChanged; 101 115 Content.RowsChanged -= Content_RowsChanged; 102 Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);116 Content.CollectionReset -= Content_CollectionReset; 103 117 Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged; 104 118 } 105 119 106 120 void Content_RowsChanged(object sender, EventArgs e) { 121 if (suppressUpdates) return; 122 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_RowsChanged, sender, e); 123 else { 124 UpdateUI(); 125 } 126 } 127 128 void Content_ColumnsChanged(object sender, EventArgs e) { 129 if (suppressUpdates) return; 130 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ColumnsChanged, sender, e); 131 else { 132 UpdateUI(); 133 } 134 } 135 136 private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 137 if (suppressUpdates) return; 138 if (InvokeRequired) Invoke((Action<object, CollectionItemsChangedEventArgs<IRun>>)Content_CollectionReset, sender, e); 139 else { 140 UpdateUI(); 141 } 142 } 143 144 void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) { 145 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_UpdateOfRunsInProgressChanged, sender, e); 146 else { 147 suppressUpdates = Content.UpdateOfRunsInProgress; 148 if (!suppressUpdates) UpdateUI(); 149 } 150 } 151 152 private void openBoxPlotToolStripMenuItem_Click(object sender, EventArgs e) { 153 RunCollectionBoxPlotView boxplotView = new RunCollectionBoxPlotView(); 154 boxplotView.Content = Content; 155 boxplotView.SetXAxis(groupComboBox.SelectedItem.ToString()); 156 boxplotView.SetYAxis(resultComboBox.SelectedItem.ToString()); 157 158 boxplotView.Show(); 159 } 160 161 private void groupCompComboBox_SelectedValueChanged(object sender, EventArgs e) { 162 if (initializing || suppressUpdates) return; 163 string curItem = (string)groupCompComboBox.SelectedItem; 164 CalculatePairwise(curItem); 165 } 166 167 private void resultComboBox_SelectedValueChanged(object sender, EventArgs e) { 168 if (initializing || suppressUpdates) return; 107 169 RebuildDataTable(); 108 } 109 110 void Content_ColumnsChanged(object sender, EventArgs e) { 170 ResetUI(); 171 CalculateValues(); 172 } 173 174 private void groupComboBox_SelectedValueChanged(object sender, EventArgs e) { 175 if (initializing || suppressUpdates) return; 111 176 RebuildDataTable(); 112 } 113 114 private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 115 RebuildDataTable(); 116 } 117 118 void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) { 119 if (!Content.UpdateOfRunsInProgress) { 120 RebuildDataTable(); 121 } 177 FillCompComboBox(); 178 ResetUI(); 179 CalculateValues(); 122 180 } 123 181 #endregion 124 182 125 183 private void UpdateGroupsComboBox() { 184 string selectedItem = (string)groupComboBox.SelectedItem; 185 126 186 groupComboBox.Items.Clear(); 127 128 187 var parameters = (from run in Content 129 188 where run.Visible … … 154 213 } 155 214 156 if (possibleIndizes.Count > 0) { 215 if (selectedItem != null && groupComboBox.Items.Contains(selectedItem)) { 216 groupComboBox.SelectedItem = selectedItem; 217 } else if (possibleIndizes.Count > 0) { 157 218 groupComboBox.SelectedItem = groupComboBox.Items[possibleIndizes.First()]; 158 } else {159 groupComboBox.SelectedItem = groupComboBox.Items[0];160 219 } 161 220 } … … 169 228 170 229 private void UpdateResultComboBox() { 230 string selectedItem = (string)resultComboBox.SelectedItem; 231 171 232 resultComboBox.Items.Clear(); 172 233 var results = (from run in Content … … 177 238 178 239 resultComboBox.Items.AddRange(results); 179 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 } 180 246 } 181 247 182 248 private void FillCompComboBox() { 249 string selectedItem = (string)groupCompComboBox.SelectedItem; 183 250 string parameterName = (string)groupComboBox.SelectedItem; 184 251 if (parameterName != null) { … … 189 256 groupCompComboBox.Items.Clear(); 190 257 columnNames.ForEach(x => groupCompComboBox.Items.Add(x)); 191 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 } 192 263 } 193 264 } … … 259 330 } 260 331 261 private void resultComboBox_SelectedValueChanged(object sender, EventArgs e) {262 RebuildDataTable();263 ResetUI();264 CalculateValues();265 }266 267 private void groupComboBox_SelectedValueChanged(object sender, EventArgs e) {268 RebuildDataTable();269 FillCompComboBox();270 ResetUI();271 CalculateValues();272 }273 274 332 private bool VerifyDataLength(bool showMessage) { 275 333 if (data == null || data.Length == 0) … … 277 335 278 336 //alglib needs at least 5 samples for computation 279 if (data.Any(x => x.Length < =requiredSampleSize)) {337 if (data.Any(x => x.Length < requiredSampleSize)) { 280 338 if (showMessage) 281 339 MessageBox.Show(this, "You need at least " + requiredSampleSize … … 291 349 return; 292 350 293 if (data != null ) {294 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>()351 if (data != null && data.All(x => x != null)) { 352 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>() 295 353 .AddOperationProgressToView(this, "Calculating..."); 296 354 … … 305 363 CalculatePairwiseTest(groupName); 306 364 307 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);365 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); 308 366 } 309 367 310 368 private void CalculatePairwise(string groupName) { 369 if (groupName == null) return; 311 370 if (!VerifyDataLength(false)) 312 371 return; 313 372 314 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");373 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating..."); 315 374 Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName)); 316 375 } … … 319 378 CalculatePairwiseTest(groupName); 320 379 321 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);380 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox); 322 381 } 323 382 324 383 private void CalculateAllGroupsTest() { 325 384 double pval = KruskalWallisTest.Test(data); 326 pValTextBox.Text = pval.ToString(); 327 if (pval < significanceLevel) { 328 this.Invoke(new Action(() => { 329 groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default; 385 DisplayAllGroupsTextResults(pval); 386 } 387 388 private void DisplayAllGroupsTextResults(double pval) { 389 if (InvokeRequired) { 390 Invoke((Action<double>)DisplayAllGroupsTextResults, pval); 391 } else { 392 pValTextBox.Text = pval.ToString(); 393 if (pval < significanceLevel) { 394 groupCompLabel.Image = VSImageLibrary.Default; 330 395 groupComTextLabel.Text = "There are groups with different distributions"; 331 })); 332 } else { 333 this.Invoke(new Action(() => { 334 groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning; 396 } else { 397 groupCompLabel.Image = VSImageLibrary.Warning; 335 398 groupComTextLabel.Text = "Groups have an equal distribution"; 336 } ));399 } 337 400 } 338 401 } … … 343 406 DoubleMatrix pValsMatrix = new DoubleMatrix(1, stringConvertibleMatrixView.Content.Columns); 344 407 pValsMatrix.ColumnNames = stringConvertibleMatrixView.Content.ColumnNames; 345 pValsMatrix.RowNames = new string[] { "p-Value" };408 pValsMatrix.RowNames = new[] { "p-Value" }; 346 409 347 410 for (int i = 0; i < data.Length; i++) { … … 353 416 // p-value is below significance level and thus the null hypothesis (data is normally distributed) is rejected 354 417 if (res.Any(x => x < significanceLevel)) { 355 this.Invoke(new Action(() => {356 normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;418 Invoke(new Action(() => { 419 normalityLabel.Image = VSImageLibrary.Warning; 357 420 normalityTextLabel.Text = "Some groups may not be normally distributed"; 358 421 })); 359 422 } else { 360 this.Invoke(new Action(() => {361 normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;423 Invoke(new Action(() => { 424 normalityLabel.Image = VSImageLibrary.Default; 362 425 normalityTextLabel.Text = "All sample data is normally distributed"; 363 426 })); 364 427 } 365 428 366 this.Invoke(new Action(() => {429 Invoke(new Action(() => { 367 430 normalityStringConvertibleMatrixView.Content = pValsMatrix; 368 431 normalityStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); … … 372 435 private void ShowPairwiseResult(int nrOfEqualDistributions) { 373 436 double ratio = ((double)nrOfEqualDistributions) / (data.Length - 1) * 100.0; 374 equalDistsTextBox.Text = ratio .ToString()+ " %";437 equalDistsTextBox.Text = ratio + " %"; 375 438 376 439 if (nrOfEqualDistributions == 0) { 377 this.Invoke(new Action(() => {378 pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;440 Invoke(new Action(() => { 441 pairwiseLabel.Image = VSImageLibrary.Default; 379 442 pairwiseTextLabel.Text = "All groups have different distributions"; 380 443 })); 381 444 } else { 382 this.Invoke(new Action(() => {383 pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;445 Invoke(new Action(() => { 446 pairwiseLabel.Image = VSImageLibrary.Warning; 384 447 pairwiseTextLabel.Text = "Some groups have equal distributions"; 385 448 })); … … 394 457 double[][] newData = FilterDataForPairwiseTest(colIndex); 395 458 396 var rowNames = new string[] { "p-Value of Mann-Whitney U", "Adjusted p-Value of Mann-Whitney U",459 var rowNames = new[] { "p-Value of Mann-Whitney U", "Adjusted p-Value of Mann-Whitney U", 397 460 "p-Value of T-Test", "Adjusted p-Value of T-Test", "Cohen's d", "Hedges' g" }; 398 461 … … 433 496 } 434 497 435 this.Invoke(new Action(() => {498 Invoke(new Action(() => { 436 499 pairwiseStringConvertibleMatrixView.Content = pValsMatrix; 437 500 pairwiseStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); … … 469 532 return newData; 470 533 } 471 472 private void openBoxPlotToolStripMenuItem_Click(object sender, EventArgs e) {473 RunCollectionBoxPlotView boxplotView = new RunCollectionBoxPlotView();474 boxplotView.Content = Content;475 boxplotView.SetXAxis(groupComboBox.SelectedItem.ToString());476 boxplotView.SetYAxis(resultComboBox.SelectedItem.ToString());477 478 boxplotView.Show();479 }480 481 private void groupCompComboBox_SelectedValueChanged(object sender, EventArgs e) {482 string curItem = (string)groupCompComboBox.SelectedItem;483 CalculatePairwise(curItem);484 }485 534 } 486 535 }
Note: See TracChangeset
for help on using the changeset viewer.