Changeset 12689 for branches/HiveStatistics/sources/HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs
- Timestamp:
- 07/08/15 15:32:12 (9 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
-
branches/HiveStatistics/sources/HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs
r12131 r12689 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) { 111 if (!Content.UpdateOfRunsInProgress) { 112 RebuildDataTable(); 113 } 114 } 115 116 private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 170 ResetUI(); 171 CalculateValues(); 172 } 173 174 private void groupComboBox_SelectedValueChanged(object sender, EventArgs e) { 175 if (initializing || suppressUpdates) return; 117 176 RebuildDataTable(); 118 } 119 120 void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) { 121 if (!Content.UpdateOfRunsInProgress) { 122 RebuildDataTable(); 123 } 177 FillCompComboBox(); 178 ResetUI(); 179 CalculateValues(); 124 180 } 125 181 #endregion 126 182 127 183 private void UpdateGroupsComboBox() { 184 string selectedItem = (string)groupComboBox.SelectedItem; 185 128 186 groupComboBox.Items.Clear(); 129 130 187 var parameters = (from run in Content 131 188 where run.Visible … … 156 213 } 157 214 158 if (possibleIndizes.Count > 0) { 215 if (selectedItem != null && groupComboBox.Items.Contains(selectedItem)) { 216 groupComboBox.SelectedItem = selectedItem; 217 } else if (possibleIndizes.Count > 0) { 159 218 groupComboBox.SelectedItem = groupComboBox.Items[possibleIndizes.First()]; 160 } else {161 groupComboBox.SelectedItem = groupComboBox.Items[0];162 219 } 163 220 } … … 171 228 172 229 private void UpdateResultComboBox() { 230 string selectedItem = (string)resultComboBox.SelectedItem; 231 173 232 resultComboBox.Items.Clear(); 174 233 var results = (from run in Content … … 179 238 180 239 resultComboBox.Items.AddRange(results); 181 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 } 182 246 } 183 247 184 248 private void FillCompComboBox() { 249 string selectedItem = (string)groupCompComboBox.SelectedItem; 185 250 string parameterName = (string)groupComboBox.SelectedItem; 186 251 if (parameterName != null) { … … 191 256 groupCompComboBox.Items.Clear(); 192 257 columnNames.ForEach(x => groupCompComboBox.Items.Add(x)); 193 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 } 194 263 } 195 264 } … … 261 330 } 262 331 263 private void resultComboBox_SelectedValueChanged(object sender, EventArgs e) {264 RebuildDataTable();265 ResetUI();266 CalculateValues();267 }268 269 private void groupComboBox_SelectedValueChanged(object sender, EventArgs e) {270 RebuildDataTable();271 FillCompComboBox();272 ResetUI();273 CalculateValues();274 }275 276 332 private bool VerifyDataLength(bool showMessage) { 277 333 if (data == null || data.Length == 0) … … 294 350 295 351 if (data != null && data.All(x => x != null)) { 296 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>()352 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>() 297 353 .AddOperationProgressToView(this, "Calculating..."); 298 354 … … 307 363 CalculatePairwiseTest(groupName); 308 364 309 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);365 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); 310 366 } 311 367 312 368 private void CalculatePairwise(string groupName) { 369 if (groupName == null) return; 313 370 if (!VerifyDataLength(false)) 314 371 return; 315 372 316 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");373 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating..."); 317 374 Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName)); 318 375 } … … 321 378 CalculatePairwiseTest(groupName); 322 379 323 MainFormManager.GetMainForm< HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);380 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox); 324 381 } 325 382 … … 328 385 pValTextBox.Text = pval.ToString(); 329 386 if (pval < significanceLevel) { 330 this.Invoke(new Action(() => {331 groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;387 Invoke(new Action(() => { 388 groupCompLabel.Image = VSImageLibrary.Default; 332 389 groupComTextLabel.Text = "There are groups with different distributions"; 333 390 })); 334 391 } else { 335 this.Invoke(new Action(() => {336 groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;392 Invoke(new Action(() => { 393 groupCompLabel.Image = VSImageLibrary.Warning; 337 394 groupComTextLabel.Text = "Groups have an equal distribution"; 338 395 })); … … 345 402 DoubleMatrix pValsMatrix = new DoubleMatrix(1, stringConvertibleMatrixView.Content.Columns); 346 403 pValsMatrix.ColumnNames = stringConvertibleMatrixView.Content.ColumnNames; 347 pValsMatrix.RowNames = new string[] { "p-Value" };404 pValsMatrix.RowNames = new[] { "p-Value" }; 348 405 349 406 for (int i = 0; i < data.Length; i++) { … … 355 412 // p-value is below significance level and thus the null hypothesis (data is normally distributed) is rejected 356 413 if (res.Any(x => x < significanceLevel)) { 357 this.Invoke(new Action(() => {358 normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;414 Invoke(new Action(() => { 415 normalityLabel.Image = VSImageLibrary.Warning; 359 416 normalityTextLabel.Text = "Some groups may not be normally distributed"; 360 417 })); 361 418 } else { 362 this.Invoke(new Action(() => {363 normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;419 Invoke(new Action(() => { 420 normalityLabel.Image = VSImageLibrary.Default; 364 421 normalityTextLabel.Text = "All sample data is normally distributed"; 365 422 })); 366 423 } 367 424 368 this.Invoke(new Action(() => {425 Invoke(new Action(() => { 369 426 normalityStringConvertibleMatrixView.Content = pValsMatrix; 370 427 normalityStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); … … 374 431 private void ShowPairwiseResult(int nrOfEqualDistributions) { 375 432 double ratio = ((double)nrOfEqualDistributions) / (data.Length - 1) * 100.0; 376 equalDistsTextBox.Text = ratio .ToString()+ " %";433 equalDistsTextBox.Text = ratio + " %"; 377 434 378 435 if (nrOfEqualDistributions == 0) { 379 this.Invoke(new Action(() => {380 pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;436 Invoke(new Action(() => { 437 pairwiseLabel.Image = VSImageLibrary.Default; 381 438 pairwiseTextLabel.Text = "All groups have different distributions"; 382 439 })); 383 440 } else { 384 this.Invoke(new Action(() => {385 pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;441 Invoke(new Action(() => { 442 pairwiseLabel.Image = VSImageLibrary.Warning; 386 443 pairwiseTextLabel.Text = "Some groups have equal distributions"; 387 444 })); … … 396 453 double[][] newData = FilterDataForPairwiseTest(colIndex); 397 454 398 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", 399 456 "p-Value of T-Test", "Adjusted p-Value of T-Test", "Cohen's d", "Hedges' g" }; 400 457 … … 435 492 } 436 493 437 this.Invoke(new Action(() => {494 Invoke(new Action(() => { 438 495 pairwiseStringConvertibleMatrixView.Content = pValsMatrix; 439 496 pairwiseStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); … … 471 528 return newData; 472 529 } 473 474 private void openBoxPlotToolStripMenuItem_Click(object sender, EventArgs e) {475 RunCollectionBoxPlotView boxplotView = new RunCollectionBoxPlotView();476 boxplotView.Content = Content;477 boxplotView.SetXAxis(groupComboBox.SelectedItem.ToString());478 boxplotView.SetYAxis(resultComboBox.SelectedItem.ToString());479 480 boxplotView.Show();481 }482 483 private void groupCompComboBox_SelectedValueChanged(object sender, EventArgs e) {484 string curItem = (string)groupCompComboBox.SelectedItem;485 CalculatePairwise(curItem);486 }487 530 } 488 531 }
Note: See TracChangeset
for help on using the changeset viewer.