Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12684


Ignore:
Timestamp:
07/08/15 13:59:55 (9 years ago)
Author:
ascheibe
Message:

#2270 statistical analysis view updates now properly when the runcollection is changed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs

    r12613 r12684  
    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;
    42     private bool suppressUpdates = false;
    43     private bool initializing = false;
     43    private bool suppressUpdates;
     44    private bool initializing;
    4445
    4546    public double SignificanceLevel {
     
    7879
    7980      if (Content != null) {
    80         initializing = true;
    81         UpdateResultComboBox();
    82         UpdateGroupsComboBox();
    83         RebuildDataTable();
    84         FillCompComboBox();
     81        UpdateUI();
     82      } else {
    8583        ResetUI();
    86         CalculateValues();
    87         initializing = false;
    8884      }
    8985      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;
    9097    }
    9198
     
    99106      Content.ColumnsChanged += Content_ColumnsChanged;
    100107      Content.RowsChanged += Content_RowsChanged;
    101       Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     108      Content.CollectionReset += Content_CollectionReset;
    102109      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
    103110    }
     
    107114      Content.ColumnsChanged -= Content_ColumnsChanged;
    108115      Content.RowsChanged -= Content_RowsChanged;
    109       Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     116      Content.CollectionReset -= Content_CollectionReset;
    110117      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
    111118    }
     
    115122      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_RowsChanged, sender, e);
    116123      else {
    117         RebuildDataTable();
     124        UpdateUI();
    118125      }
    119126    }
     
    123130      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ColumnsChanged, sender, e);
    124131      else {
    125         RebuildDataTable();
     132        UpdateUI();
    126133      }
    127134    }
     
    131138      if (InvokeRequired) Invoke((Action<object, CollectionItemsChangedEventArgs<IRun>>)Content_CollectionReset, sender, e);
    132139      else {
    133         RebuildDataTable();
     140        UpdateUI();
    134141      }
    135142    }
     
    139146      else {
    140147        suppressUpdates = Content.UpdateOfRunsInProgress;
    141         if (!suppressUpdates) RebuildDataTable();
     148        if (!suppressUpdates) UpdateUI();
    142149      }
    143150    }
     
    153160
    154161    private void groupCompComboBox_SelectedValueChanged(object sender, EventArgs e) {
    155       if (initializing) return;
     162      if (initializing || suppressUpdates) return;
    156163      string curItem = (string)groupCompComboBox.SelectedItem;
    157164      CalculatePairwise(curItem);
     
    159166
    160167    private void resultComboBox_SelectedValueChanged(object sender, EventArgs e) {
    161       if (initializing) return;
     168      if (initializing || suppressUpdates) return;
    162169      RebuildDataTable();
    163170      ResetUI();
     
    166173
    167174    private void groupComboBox_SelectedValueChanged(object sender, EventArgs e) {
    168       if (initializing) return;
     175      if (initializing || suppressUpdates) return;
    169176      RebuildDataTable();
    170177      FillCompComboBox();
     
    175182
    176183    private void UpdateGroupsComboBox() {
     184      string selectedItem = (string)groupComboBox.SelectedItem;
     185
    177186      groupComboBox.Items.Clear();
    178 
    179187      var parameters = (from run in Content
    180188                        where run.Visible
     
    205213        }
    206214
    207         if (possibleIndizes.Count > 0) {
     215        if (selectedItem != null && groupComboBox.Items.Contains(selectedItem)) {
     216          groupComboBox.SelectedItem = selectedItem;
     217        } else if (possibleIndizes.Count > 0) {
    208218          groupComboBox.SelectedItem = groupComboBox.Items[possibleIndizes.First()];
    209         } else {
    210           groupComboBox.SelectedItem = groupComboBox.Items[0];
    211219        }
    212220      }
     
    220228
    221229    private void UpdateResultComboBox() {
     230      string selectedItem = (string)resultComboBox.SelectedItem;
     231
    222232      resultComboBox.Items.Clear();
    223233      var results = (from run in Content
     
    228238
    229239      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      }
    231246    }
    232247
    233248    private void FillCompComboBox() {
     249      string selectedItem = (string)groupCompComboBox.SelectedItem;
    234250      string parameterName = (string)groupComboBox.SelectedItem;
    235251      if (parameterName != null) {
     
    240256          groupCompComboBox.Items.Clear();
    241257          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          }
    243263        }
    244264      }
     
    330350
    331351      if (data != null && data.All(x => x != null)) {
    332         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>()
     352        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>()
    333353          .AddOperationProgressToView(this, "Calculating...");
    334354
     
    343363      CalculatePairwiseTest(groupName);
    344364
    345       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     365      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    346366    }
    347367
    348368    private void CalculatePairwise(string groupName) {
     369      if (groupName == null) return;
    349370      if (!VerifyDataLength(false))
    350371        return;
    351372
    352       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");
     373      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");
    353374      Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName));
    354375    }
     
    357378      CalculatePairwiseTest(groupName);
    358379
    359       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);
     380      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);
    360381    }
    361382
     
    364385      pValTextBox.Text = pval.ToString();
    365386      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;
    368389          groupComTextLabel.Text = "There are groups with different distributions";
    369390        }));
    370391      } else {
    371         this.Invoke(new Action(() => {
    372           groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;
     392        Invoke(new Action(() => {
     393          groupCompLabel.Image = VSImageLibrary.Warning;
    373394          groupComTextLabel.Text = "Groups have an equal distribution";
    374395        }));
     
    381402      DoubleMatrix pValsMatrix = new DoubleMatrix(1, stringConvertibleMatrixView.Content.Columns);
    382403      pValsMatrix.ColumnNames = stringConvertibleMatrixView.Content.ColumnNames;
    383       pValsMatrix.RowNames = new string[] { "p-Value" };
     404      pValsMatrix.RowNames = new[] { "p-Value" };
    384405
    385406      for (int i = 0; i < data.Length; i++) {
     
    391412      // p-value is below significance level and thus the null hypothesis (data is normally distributed) is rejected
    392413      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;
    395416          normalityTextLabel.Text = "Some groups may not be normally distributed";
    396417        }));
    397418      } else {
    398         this.Invoke(new Action(() => {
    399           normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;
     419        Invoke(new Action(() => {
     420          normalityLabel.Image = VSImageLibrary.Default;
    400421          normalityTextLabel.Text = "All sample data is normally distributed";
    401422        }));
    402423      }
    403424
    404       this.Invoke(new Action(() => {
     425      Invoke(new Action(() => {
    405426        normalityStringConvertibleMatrixView.Content = pValsMatrix;
    406427        normalityStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
     
    410431    private void ShowPairwiseResult(int nrOfEqualDistributions) {
    411432      double ratio = ((double)nrOfEqualDistributions) / (data.Length - 1) * 100.0;
    412       equalDistsTextBox.Text = ratio.ToString() + " %";
     433      equalDistsTextBox.Text = ratio + " %";
    413434
    414435      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;
    417438          pairwiseTextLabel.Text = "All groups have different distributions";
    418439        }));
    419440      } else {
    420         this.Invoke(new Action(() => {
    421           pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;
     441        Invoke(new Action(() => {
     442          pairwiseLabel.Image = VSImageLibrary.Warning;
    422443          pairwiseTextLabel.Text = "Some groups have equal distributions";
    423444        }));
     
    432453      double[][] newData = FilterDataForPairwiseTest(colIndex);
    433454
    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",
    435456            "p-Value of T-Test", "Adjusted p-Value of T-Test", "Cohen's d", "Hedges' g" };
    436457
     
    471492      }
    472493
    473       this.Invoke(new Action(() => {
     494      Invoke(new Action(() => {
    474495        pairwiseStringConvertibleMatrixView.Content = pValsMatrix;
    475496        pairwiseStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
Note: See TracChangeset for help on using the changeset viewer.