Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/17/13 13:32:08 (11 years ago)
Author:
ascheibe
Message:

#2031

  • made operations in ChartAnalysisView asynchronous
  • renamed views to go along with the other RunCollection views
Location:
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ChartAnalysisView.cs

    r9706 r9713  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading.Tasks;
    2526using System.Windows.Forms;
    2627using HeuristicLab.Common;
     
    2829using HeuristicLab.Data;
    2930using HeuristicLab.MainForm;
     31using HeuristicLab.MainForm.WindowsForms;
    3032using HeuristicLab.Optimization;
    3133using HeuristicLab.PluginInfrastructure;
    3234
    3335namespace HeuristicLab.Analysis.Statistics {
    34   [View("RunCollection Chart Analysis View")]
     36  [View("RunCollection Chart Analysis")]
    3537  [Content(typeof(RunCollection), false)]
    3638  public sealed partial class ChartAnalysisView : ItemView {
     
    4648
    4749    private List<IRun> runs;
     50    private Progress progress;
     51    private ProgressView progressView;
     52    private bool valuesAdded = false;
    4853
    4954    public ChartAnalysisView() {
    5055      InitializeComponent();
     56      progress = new Progress() {
     57        CanBeCanceled = false,
     58        ProgressState = ProgressState.Finished
     59      };
     60      progressView = new ProgressView(this, progress);
     61
    5162      stringConvertibleMatrixView.DataGridView.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(DataGridView_RowHeaderMouseDoubleClick);
    5263
     
    6778        components.Dispose();
    6879      }
     80      if (disposing)
     81        progressView.Dispose();
    6982      base.Dispose(disposing);
    7083    }
     
    98111
    99112    private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    100       RebuildDataTable();
     113      RebuildDataTableAsync();
    101114    }
    102115
    103116    private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    104       RebuildDataTable();
     117      RebuildDataTableAsync();
    105118    }
    106119
    107120    private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    108       RebuildDataTable();
     121      RebuildDataTableAsync();
    109122    }
    110123
    111124    void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
    112       if (!Content.UpdateOfRunsInProgress) {
    113         RebuildDataTable();
     125      if (!Content.UpdateOfRunsInProgress && !valuesAdded) {
     126        RebuildDataTableAsync();
     127      }
     128      if (valuesAdded) {
     129        valuesAdded = false;
    114130      }
    115131    }
     
    133149
    134150    private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    135       RebuildDataTable();
     151      RebuildDataTableAsync();
    136152    }
    137153
    138154    private void addLineToChart_Click(object sender, EventArgs e) {
     155      progress.Status = "Adding fitted lines to charts...";
     156      progress.ProgressState = ProgressState.Started;
     157      progress.ProgressValue = 0.0;
     158
     159      var task = System.Threading.Tasks.Task.Factory.StartNew(AddLineToChart);
     160
     161      task.ContinueWith((t) => {
     162        progress.Finish();
     163        ErrorHandling.ShowErrorDialog("An error occured while adding lines to charts. ", t.Exception);
     164      }, TaskContinuationOptions.OnlyOnFaulted);
     165
     166      task.ContinueWith((t) => {
     167        progress.Finish();
     168      }, TaskContinuationOptions.OnlyOnRanToCompletion);
     169    }
     170
     171    private void AddLineToChart() {
    139172      string resultName = (string)dataTableComboBox.SelectedItem;
    140173      string rowName = (string)dataRowComboBox.SelectedItem;
     
    171204        }
    172205      }
     206      valuesAdded = true;
    173207      Content.UpdateOfRunsInProgress = false;
    174208    }
     
    200234    }
    201235
     236    private void RebuildDataTableAsync() {
     237      progress.Status = "Calculating values...";
     238      progress.ProgressState = ProgressState.Started;
     239      progress.ProgressValue = 0.0;
     240
     241      var task = System.Threading.Tasks.Task.Factory.StartNew(RebuildDataTable);
     242
     243      task.ContinueWith((t) => {
     244        progress.Finish();
     245        ErrorHandling.ShowErrorDialog("An error occured while calculating values. ", t.Exception);
     246      }, TaskContinuationOptions.OnlyOnFaulted);
     247
     248      task.ContinueWith((t) => {
     249        progress.Finish();
     250      }, TaskContinuationOptions.OnlyOnRanToCompletion);
     251    }
     252
    202253    private void RebuildDataTable() {
    203254      string resultName = (string)dataTableComboBox.SelectedItem;
    204255      string rowName = (string)dataRowComboBox.SelectedItem;
    205       string[] columnNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Gradient", "Relative Error", "Avg. of Upper 25 %", " Avg. of Lower 25 %", "Avg. of First 25 %", "Avg. of Last 25 %" };
     256      LinearLeastSquaresFitting llsFitting = new LinearLeastSquaresFitting();
     257      LogFitting logFitting = new LogFitting();
     258      string[] columnNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Avg. of Upper 25 %", " Avg. of Lower 25 %", "Avg. of First 25 %", "Avg. of Last 25 %", "Gradient", "Relative Error", "a", "b" };
    206259
    207260      runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible).ToList();
     
    226279        double percentile25 = values.Percentile(0.25);
    227280        double percentile75 = values.Percentile(0.75);
    228         double k, d, r;
    229         LinearLeastSquaresFitting llsf = new LinearLeastSquaresFitting();
    230         llsf.Calculate(values.ToArray(), out k, out d);
    231         r = llsf.CalculateError(values.ToArray(), k, d);
    232281        double lowerAvg = values.OrderBy(x => x).Take((int)(values.Count() * 0.25)).Average();
    233282        double upperAvg = values.OrderByDescending(x => x).Take((int)(values.Count() * 0.25)).Average();
    234283        double firstAvg = values.Take((int)(values.Count() * 0.25)).Average();
    235284        double lastAvg = values.Skip((int)(values.Count() * 0.75)).Average();
     285        double k, d, r, a, b;
     286        llsFitting.Calculate(values.ToArray(), out k, out d);
     287        r = llsFitting.CalculateError(values.ToArray(), k, d);
     288        logFitting.Calculate(values.ToArray(), out a, out b);
    236289
    237290        dt[i, 0] = cnt;
     
    244297        dt[i, 7] = percentile25;
    245298        dt[i, 8] = percentile75;
    246         dt[i, 9] = k;
    247         dt[i, 10] = r;
    248         dt[i, 11] = upperAvg;
    249         dt[i, 12] = lowerAvg;
    250         dt[i, 13] = firstAvg;
    251         dt[i, 14] = lastAvg;
     299        dt[i, 9] = upperAvg;
     300        dt[i, 10] = lowerAvg;
     301        dt[i, 11] = firstAvg;
     302        dt[i, 12] = lastAvg;
     303        dt[i, 13] = k;
     304        dt[i, 14] = r;
     305        dt[i, 15] = a;
     306        dt[i, 16] = b;
    252307
    253308        i++;
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ChartAnalysisView.designer.cs

    r9706 r9713  
    4949      this.fittingComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    5050      this.fittingComboBox.FormattingEnabled = true;
    51       this.fittingComboBox.Location = new System.Drawing.Point(147, 359);
     51      this.fittingComboBox.Location = new System.Drawing.Point(142, 359);
    5252      this.fittingComboBox.Name = "fittingComboBox";
    53       this.fittingComboBox.Size = new System.Drawing.Size(200, 21);
     53      this.fittingComboBox.Size = new System.Drawing.Size(214, 21);
    5454      this.fittingComboBox.TabIndex = 12;
    5555      //
    5656      // addValuesButton
    5757      //
    58       this.addValuesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    59       this.addValuesButton.Location = new System.Drawing.Point(8, 359);
     58      this.addValuesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     59      this.addValuesButton.Location = new System.Drawing.Point(3, 357);
    6060      this.addValuesButton.Name = "addValuesButton";
    6161      this.addValuesButton.Size = new System.Drawing.Size(133, 23);
     
    6868      //
    6969      this.addLineToChart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    70       this.addLineToChart.Location = new System.Drawing.Point(353, 359);
     70      this.addLineToChart.Location = new System.Drawing.Point(362, 357);
    7171      this.addLineToChart.Name = "addLineToChart";
    7272      this.addLineToChart.Size = new System.Drawing.Size(133, 23);
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.cs

    r9706 r9713  
    3030
    3131namespace HeuristicLab.Analysis.Statistics {
    32   [View("Correlation View")]
     32  [View("RunCollection Correlations")]
    3333  [Content(typeof(RunCollection), false)]
    3434  public sealed partial class CorrelationView : ItemView {
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/LinearLeastSquaresFitting.cs

    r9706 r9713  
    5252    }
    5353
    54     //TODO: adapt or remove
    55     public double CalculateError(double[] dataPoints, double a1, double a0) {
     54    public double CalculateError(double[] dataPoints, double p0, double p1) {
    5655      double r = 0.0;
    5756      double avgy = dataPoints.Average();
     
    6059
    6160      for (int i = 0; i < dataPoints.Count(); i++) {
    62         double y = a1 * i + a0;
     61        double y = p0 * i + p1;
    6362        sstot += Math.Pow(dataPoints[i] - avgy, 2);
    6463        sserr += Math.Pow(dataPoints[i] - y, 2);
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.cs

    r9706 r9713  
    3434
    3535namespace HeuristicLab.Analysis.Statistics {
    36   [View("Sample Size Influence View")]
     36  [View("RunCollection Sample Size Influences")]
    3737  [Content(typeof(RunCollection), false)]
    3838  public partial class SampleSizeInfluenceView : AsynchronousContentView {
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/StatisticalTestingView.cs

    r9706 r9713  
    3232
    3333namespace HeuristicLab.Analysis.Statistics {
    34   [View("Statistical Testing View")]
     34  [View("RunCollection Statistical Testing")]
    3535  [Content(typeof(RunCollection), false)]
    3636  public sealed partial class StatisticalTestingView : ItemView {
Note: See TracChangeset for help on using the changeset viewer.