Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/11/15 13:37:32 (9 years ago)
Author:
ascheibe
Message:

#2270 and #2354: merged r12173, r12458, r12077, r12599, r12613, r12112, r12116, r12117, r12131, r12631, r12672, r12684, r12690, r12692 into stable

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs

    r12009 r12725  
    2727using HeuristicLab.Collections;
    2828using HeuristicLab.Common;
     29using HeuristicLab.Common.Resources;
    2930using HeuristicLab.Core.Views;
    3031using HeuristicLab.Data;
     
    4041    private const int requiredSampleSize = 5;
    4142    private double[][] data;
     43    private bool suppressUpdates;
     44    private bool initializing;
    4245
    4346    public double SignificanceLevel {
     
    7679
    7780      if (Content != null) {
    78         UpdateResultComboBox();
    79         UpdateGroupsComboBox();
    80         RebuildDataTable();
     81        UpdateUI();
     82      } else {
     83        ResetUI();
    8184      }
    8285      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;
    8397    }
    8498
     
    92106      Content.ColumnsChanged += Content_ColumnsChanged;
    93107      Content.RowsChanged += Content_RowsChanged;
    94       Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     108      Content.CollectionReset += Content_CollectionReset;
    95109      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
    96110    }
     
    100114      Content.ColumnsChanged -= Content_ColumnsChanged;
    101115      Content.RowsChanged -= Content_RowsChanged;
    102       Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     116      Content.CollectionReset -= Content_CollectionReset;
    103117      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
    104118    }
    105119
    106120    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;
    107169      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;
    111176      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();
    122180    }
    123181    #endregion
    124182
    125183    private void UpdateGroupsComboBox() {
     184      string selectedItem = (string)groupComboBox.SelectedItem;
     185
    126186      groupComboBox.Items.Clear();
    127 
    128187      var parameters = (from run in Content
    129188                        where run.Visible
     
    154213        }
    155214
    156         if (possibleIndizes.Count > 0) {
     215        if (selectedItem != null && groupComboBox.Items.Contains(selectedItem)) {
     216          groupComboBox.SelectedItem = selectedItem;
     217        } else if (possibleIndizes.Count > 0) {
    157218          groupComboBox.SelectedItem = groupComboBox.Items[possibleIndizes.First()];
    158         } else {
    159           groupComboBox.SelectedItem = groupComboBox.Items[0];
    160219        }
    161220      }
     
    169228
    170229    private void UpdateResultComboBox() {
     230      string selectedItem = (string)resultComboBox.SelectedItem;
     231
    171232      resultComboBox.Items.Clear();
    172233      var results = (from run in Content
     
    177238
    178239      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      }
    180246    }
    181247
    182248    private void FillCompComboBox() {
     249      string selectedItem = (string)groupCompComboBox.SelectedItem;
    183250      string parameterName = (string)groupComboBox.SelectedItem;
    184251      if (parameterName != null) {
     
    189256          groupCompComboBox.Items.Clear();
    190257          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          }
    192263        }
    193264      }
     
    259330    }
    260331
    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 
    274332    private bool VerifyDataLength(bool showMessage) {
    275333      if (data == null || data.Length == 0)
     
    277335
    278336      //alglib needs at least 5 samples for computation
    279       if (data.Any(x => x.Length <= requiredSampleSize)) {
     337      if (data.Any(x => x.Length < requiredSampleSize)) {
    280338        if (showMessage)
    281339          MessageBox.Show(this, "You need at least " + requiredSampleSize
     
    291349        return;
    292350
    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>()
    295353          .AddOperationProgressToView(this, "Calculating...");
    296354
     
    305363      CalculatePairwiseTest(groupName);
    306364
    307       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     365      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    308366    }
    309367
    310368    private void CalculatePairwise(string groupName) {
     369      if (groupName == null) return;
    311370      if (!VerifyDataLength(false))
    312371        return;
    313372
    314       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");
     373      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");
    315374      Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName));
    316375    }
     
    319378      CalculatePairwiseTest(groupName);
    320379
    321       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);
     380      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);
    322381    }
    323382
    324383    private void CalculateAllGroupsTest() {
    325384      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;
    330395          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;
    335398          groupComTextLabel.Text = "Groups have an equal distribution";
    336         }));
     399        }
    337400      }
    338401    }
     
    343406      DoubleMatrix pValsMatrix = new DoubleMatrix(1, stringConvertibleMatrixView.Content.Columns);
    344407      pValsMatrix.ColumnNames = stringConvertibleMatrixView.Content.ColumnNames;
    345       pValsMatrix.RowNames = new string[] { "p-Value" };
     408      pValsMatrix.RowNames = new[] { "p-Value" };
    346409
    347410      for (int i = 0; i < data.Length; i++) {
     
    353416      // p-value is below significance level and thus the null hypothesis (data is normally distributed) is rejected
    354417      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;
    357420          normalityTextLabel.Text = "Some groups may not be normally distributed";
    358421        }));
    359422      } else {
    360         this.Invoke(new Action(() => {
    361           normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;
     423        Invoke(new Action(() => {
     424          normalityLabel.Image = VSImageLibrary.Default;
    362425          normalityTextLabel.Text = "All sample data is normally distributed";
    363426        }));
    364427      }
    365428
    366       this.Invoke(new Action(() => {
     429      Invoke(new Action(() => {
    367430        normalityStringConvertibleMatrixView.Content = pValsMatrix;
    368431        normalityStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
     
    372435    private void ShowPairwiseResult(int nrOfEqualDistributions) {
    373436      double ratio = ((double)nrOfEqualDistributions) / (data.Length - 1) * 100.0;
    374       equalDistsTextBox.Text = ratio.ToString() + " %";
     437      equalDistsTextBox.Text = ratio + " %";
    375438
    376439      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;
    379442          pairwiseTextLabel.Text = "All groups have different distributions";
    380443        }));
    381444      } else {
    382         this.Invoke(new Action(() => {
    383           pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;
     445        Invoke(new Action(() => {
     446          pairwiseLabel.Image = VSImageLibrary.Warning;
    384447          pairwiseTextLabel.Text = "Some groups have equal distributions";
    385448        }));
     
    394457      double[][] newData = FilterDataForPairwiseTest(colIndex);
    395458
    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",
    397460            "p-Value of T-Test", "Adjusted p-Value of T-Test", "Cohen's d", "Hedges' g" };
    398461
     
    433496      }
    434497
    435       this.Invoke(new Action(() => {
     498      Invoke(new Action(() => {
    436499        pairwiseStringConvertibleMatrixView.Content = pValsMatrix;
    437500        pairwiseStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
     
    469532      return newData;
    470533    }
    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     }
    485534  }
    486535}
Note: See TracChangeset for help on using the changeset viewer.