Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/08/15 15:32:12 (9 years ago)
Author:
dglaser
Message:

#2388: Merged trunk into HiveStatistics branch

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  
    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) {
    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;
    117176      RebuildDataTable();
    118     }
    119 
    120     void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
    121       if (!Content.UpdateOfRunsInProgress) {
    122         RebuildDataTable();
    123       }
     177      FillCompComboBox();
     178      ResetUI();
     179      CalculateValues();
    124180    }
    125181    #endregion
    126182
    127183    private void UpdateGroupsComboBox() {
     184      string selectedItem = (string)groupComboBox.SelectedItem;
     185
    128186      groupComboBox.Items.Clear();
    129 
    130187      var parameters = (from run in Content
    131188                        where run.Visible
     
    156213        }
    157214
    158         if (possibleIndizes.Count > 0) {
     215        if (selectedItem != null && groupComboBox.Items.Contains(selectedItem)) {
     216          groupComboBox.SelectedItem = selectedItem;
     217        } else if (possibleIndizes.Count > 0) {
    159218          groupComboBox.SelectedItem = groupComboBox.Items[possibleIndizes.First()];
    160         } else {
    161           groupComboBox.SelectedItem = groupComboBox.Items[0];
    162219        }
    163220      }
     
    171228
    172229    private void UpdateResultComboBox() {
     230      string selectedItem = (string)resultComboBox.SelectedItem;
     231
    173232      resultComboBox.Items.Clear();
    174233      var results = (from run in Content
     
    179238
    180239      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      }
    182246    }
    183247
    184248    private void FillCompComboBox() {
     249      string selectedItem = (string)groupCompComboBox.SelectedItem;
    185250      string parameterName = (string)groupComboBox.SelectedItem;
    186251      if (parameterName != null) {
     
    191256          groupCompComboBox.Items.Clear();
    192257          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          }
    194263        }
    195264      }
     
    261330    }
    262331
    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 
    276332    private bool VerifyDataLength(bool showMessage) {
    277333      if (data == null || data.Length == 0)
     
    294350
    295351      if (data != null && data.All(x => x != null)) {
    296         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>()
     352        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>()
    297353          .AddOperationProgressToView(this, "Calculating...");
    298354
     
    307363      CalculatePairwiseTest(groupName);
    308364
    309       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     365      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    310366    }
    311367
    312368    private void CalculatePairwise(string groupName) {
     369      if (groupName == null) return;
    313370      if (!VerifyDataLength(false))
    314371        return;
    315372
    316       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");
     373      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");
    317374      Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName));
    318375    }
     
    321378      CalculatePairwiseTest(groupName);
    322379
    323       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);
     380      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);
    324381    }
    325382
     
    328385      pValTextBox.Text = pval.ToString();
    329386      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;
    332389          groupComTextLabel.Text = "There are groups with different distributions";
    333390        }));
    334391      } else {
    335         this.Invoke(new Action(() => {
    336           groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;
     392        Invoke(new Action(() => {
     393          groupCompLabel.Image = VSImageLibrary.Warning;
    337394          groupComTextLabel.Text = "Groups have an equal distribution";
    338395        }));
     
    345402      DoubleMatrix pValsMatrix = new DoubleMatrix(1, stringConvertibleMatrixView.Content.Columns);
    346403      pValsMatrix.ColumnNames = stringConvertibleMatrixView.Content.ColumnNames;
    347       pValsMatrix.RowNames = new string[] { "p-Value" };
     404      pValsMatrix.RowNames = new[] { "p-Value" };
    348405
    349406      for (int i = 0; i < data.Length; i++) {
     
    355412      // p-value is below significance level and thus the null hypothesis (data is normally distributed) is rejected
    356413      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;
    359416          normalityTextLabel.Text = "Some groups may not be normally distributed";
    360417        }));
    361418      } else {
    362         this.Invoke(new Action(() => {
    363           normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;
     419        Invoke(new Action(() => {
     420          normalityLabel.Image = VSImageLibrary.Default;
    364421          normalityTextLabel.Text = "All sample data is normally distributed";
    365422        }));
    366423      }
    367424
    368       this.Invoke(new Action(() => {
     425      Invoke(new Action(() => {
    369426        normalityStringConvertibleMatrixView.Content = pValsMatrix;
    370427        normalityStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
     
    374431    private void ShowPairwiseResult(int nrOfEqualDistributions) {
    375432      double ratio = ((double)nrOfEqualDistributions) / (data.Length - 1) * 100.0;
    376       equalDistsTextBox.Text = ratio.ToString() + " %";
     433      equalDistsTextBox.Text = ratio + " %";
    377434
    378435      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;
    381438          pairwiseTextLabel.Text = "All groups have different distributions";
    382439        }));
    383440      } else {
    384         this.Invoke(new Action(() => {
    385           pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;
     441        Invoke(new Action(() => {
     442          pairwiseLabel.Image = VSImageLibrary.Warning;
    386443          pairwiseTextLabel.Text = "Some groups have equal distributions";
    387444        }));
     
    396453      double[][] newData = FilterDataForPairwiseTest(colIndex);
    397454
    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",
    399456            "p-Value of T-Test", "Adjusted p-Value of T-Test", "Cohen's d", "Hedges' g" };
    400457
     
    435492      }
    436493
    437       this.Invoke(new Action(() => {
     494      Invoke(new Action(() => {
    438495        pairwiseStringConvertibleMatrixView.Content = pValsMatrix;
    439496        pairwiseStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
     
    471528      return newData;
    472529    }
    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     }
    487530  }
    488531}
Note: See TracChangeset for help on using the changeset viewer.