Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9706


Ignore:
Timestamp:
07/15/13 16:33:13 (11 years ago)
Author:
ascheibe
Message:

#2031

  • added exponential fitting
  • added logarithmic fitting
  • refactored fitting code
  • updated license headers
Location:
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3
Files:
3 added
17 edited

Legend:

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

    r9378 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2929using HeuristicLab.MainForm;
    3030using HeuristicLab.Optimization;
     31using HeuristicLab.PluginInfrastructure;
    3132
    3233namespace HeuristicLab.Analysis.Statistics {
     
    4950      InitializeComponent();
    5051      stringConvertibleMatrixView.DataGridView.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(DataGridView_RowHeaderMouseDoubleClick);
     52
     53      var fittingAlgs = ApplicationManager.Manager.GetInstances<IFitting>();
     54      foreach (var fit in fittingAlgs) {
     55        fittingComboBox.Items.Add(fit);
     56      }
     57      fittingComboBox.SelectedIndex = 0;
    5158    }
    5259
     
    137144        DataRow row = resTable.Rows[rowName];
    138145        var values = row.Values.ToArray();
    139         double k, d;
    140         LinearLeastSquaresFitting.Calculate(values, out k, out d);
    141 
    142         DataRow newRow = new DataRow(row.Name + " Fitted Line");
    143         for (int i = 0; i < values.Count(); i++) {
    144           newRow.Values.Add(k * i + d);
    145         }
     146
     147        var fittingAlg = fittingComboBox.SelectedItem as IFitting;
     148        DataRow newRow = fittingAlg.CalculateFittedLine(values, row.Name + " (" + fittingAlg.ToString() + ")");
    146149
    147150        if (!resTable.Rows.ContainsKey(newRow.Name))
     
    224227        double percentile75 = values.Percentile(0.75);
    225228        double k, d, r;
    226         LinearLeastSquaresFitting.Calculate(values.ToArray(), out k, out d);
    227         r = LinearLeastSquaresFitting.CalculateError(values.ToArray(), k, d);
     229        LinearLeastSquaresFitting llsf = new LinearLeastSquaresFitting();
     230        llsf.Calculate(values.ToArray(), out k, out d);
     231        r = llsf.CalculateError(values.ToArray(), k, d);
    228232        double lowerAvg = values.OrderBy(x => x).Take((int)(values.Count() * 0.25)).Average();
    229233        double upperAvg = values.OrderByDescending(x => x).Take((int)(values.Count() * 0.25)).Average();
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ChartAnalysisView.designer.cs

    r9377 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3434    /// </summary>
    3535    private void InitializeComponent() {
    36       this.stringConvertibleMatrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
     36      this.fittingComboBox = new System.Windows.Forms.ComboBox();
     37      this.addValuesButton = new System.Windows.Forms.Button();
     38      this.addLineToChart = new System.Windows.Forms.Button();
    3739      this.dataRowComboBox = new System.Windows.Forms.ComboBox();
    3840      this.label2 = new System.Windows.Forms.Label();
    3941      this.label1 = new System.Windows.Forms.Label();
    4042      this.dataTableComboBox = new System.Windows.Forms.ComboBox();
    41       this.addLineToChart = new System.Windows.Forms.Button();
    42       this.addValuesButton = new System.Windows.Forms.Button();
     43      this.stringConvertibleMatrixView = new HeuristicLab.Data.Views.StringConvertibleMatrixView();
    4344      this.SuspendLayout();
    4445      //
    45       // stringConvertibleMatrixView
     46      // fittingComboBox
    4647      //
    47       this.stringConvertibleMatrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    48             | System.Windows.Forms.AnchorStyles.Left)
    49             | System.Windows.Forms.AnchorStyles.Right)));
    50       this.stringConvertibleMatrixView.Caption = "StringConvertibleMatrix View";
    51       this.stringConvertibleMatrixView.Content = null;
    52       this.stringConvertibleMatrixView.Location = new System.Drawing.Point(3, 59);
    53       this.stringConvertibleMatrixView.Name = "stringConvertibleMatrixView";
    54       this.stringConvertibleMatrixView.ReadOnly = true;
    55       this.stringConvertibleMatrixView.ShowRowsAndColumnsTextBox = true;
    56       this.stringConvertibleMatrixView.ShowStatisticalInformation = true;
    57       this.stringConvertibleMatrixView.Size = new System.Drawing.Size(492, 294);
    58       this.stringConvertibleMatrixView.TabIndex = 0;
     48      this.fittingComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     49      this.fittingComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     50      this.fittingComboBox.FormattingEnabled = true;
     51      this.fittingComboBox.Location = new System.Drawing.Point(147, 359);
     52      this.fittingComboBox.Name = "fittingComboBox";
     53      this.fittingComboBox.Size = new System.Drawing.Size(200, 21);
     54      this.fittingComboBox.TabIndex = 12;
     55      //
     56      // addValuesButton
     57      //
     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);
     60      this.addValuesButton.Name = "addValuesButton";
     61      this.addValuesButton.Size = new System.Drawing.Size(133, 23);
     62      this.addValuesButton.TabIndex = 10;
     63      this.addValuesButton.Text = "Add Values to Results";
     64      this.addValuesButton.UseVisualStyleBackColor = true;
     65      this.addValuesButton.Click += new System.EventHandler(this.addValuesButton_Click);
     66      //
     67      // addLineToChart
     68      //
     69      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);
     71      this.addLineToChart.Name = "addLineToChart";
     72      this.addLineToChart.Size = new System.Drawing.Size(133, 23);
     73      this.addLineToChart.TabIndex = 9;
     74      this.addLineToChart.Text = "Fit Line to Chart";
     75      this.addLineToChart.UseVisualStyleBackColor = true;
     76      this.addLineToChart.Click += new System.EventHandler(this.addLineToChart_Click);
    5977      //
    6078      // dataRowComboBox
     
    100118      this.dataTableComboBox.SelectedIndexChanged += new System.EventHandler(this.dataTableComboBox_SelectedIndexChanged);
    101119      //
    102       // addLineToChart
     120      // stringConvertibleMatrixView
    103121      //
    104       this.addLineToChart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    105       this.addLineToChart.Location = new System.Drawing.Point(353, 359);
    106       this.addLineToChart.Name = "addLineToChart";
    107       this.addLineToChart.Size = new System.Drawing.Size(133, 23);
    108       this.addLineToChart.TabIndex = 9;
    109       this.addLineToChart.Text = "Fit Line to Chart";
    110       this.addLineToChart.UseVisualStyleBackColor = true;
    111       this.addLineToChart.Click += new System.EventHandler(this.addLineToChart_Click);
    112       //
    113       // addValuesButton
    114       //
    115       this.addValuesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    116       this.addValuesButton.Location = new System.Drawing.Point(214, 359);
    117       this.addValuesButton.Name = "addValuesButton";
    118       this.addValuesButton.Size = new System.Drawing.Size(133, 23);
    119       this.addValuesButton.TabIndex = 10;
    120       this.addValuesButton.Text = "Add Values to Results";
    121       this.addValuesButton.UseVisualStyleBackColor = true;
    122       this.addValuesButton.Click += new System.EventHandler(this.addValuesButton_Click);
     122      this.stringConvertibleMatrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     123            | System.Windows.Forms.AnchorStyles.Left)
     124            | System.Windows.Forms.AnchorStyles.Right)));
     125      this.stringConvertibleMatrixView.Caption = "StringConvertibleMatrix View";
     126      this.stringConvertibleMatrixView.Content = null;
     127      this.stringConvertibleMatrixView.Location = new System.Drawing.Point(3, 59);
     128      this.stringConvertibleMatrixView.Name = "stringConvertibleMatrixView";
     129      this.stringConvertibleMatrixView.ReadOnly = true;
     130      this.stringConvertibleMatrixView.ShowRowsAndColumnsTextBox = true;
     131      this.stringConvertibleMatrixView.ShowStatisticalInformation = true;
     132      this.stringConvertibleMatrixView.Size = new System.Drawing.Size(492, 294);
     133      this.stringConvertibleMatrixView.TabIndex = 0;
    123134      //
    124135      // ChartAnalysisView
    125136      //
     137      this.Controls.Add(this.fittingComboBox);
    126138      this.Controls.Add(this.addValuesButton);
    127139      this.Controls.Add(this.addLineToChart);
     
    146158    private System.Windows.Forms.Button addLineToChart;
    147159    private System.Windows.Forms.Button addValuesButton;
     160    private System.Windows.Forms.ComboBox fittingComboBox;
    148161  }
    149162}
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.cs

    r9398 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/CorrelationView.designer.cs

    r9383 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/HeuristicLab.Analysis.Statistics-3.3.csproj

    r9389 r9706  
    114114  </ItemGroup>
    115115  <ItemGroup>
     116    <Compile Include="ExpFitting.cs" />
     117    <Compile Include="IFitting.cs" />
    116118    <Compile Include="LinearLeastSquaresFitting.cs" />
     119    <Compile Include="LogFitting.cs" />
    117120    <Compile Include="Resources.Designer.cs">
    118121      <AutoGen>True</AutoGen>
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/KruskalWallis.cs

    r9353 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/LinearLeastSquaresFitting.cs

    r9353 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2424
    2525namespace HeuristicLab.Analysis.Statistics {
    26   public class LinearLeastSquaresFitting {
    27     public static void Calculate(double[] dataPoints, out double a1, out double a0) {
     26  public class LinearLeastSquaresFitting : IFitting {
     27    public void Calculate(double[] dataPoints, out double p0, out double p1) {
     28      var stdX = Enumerable.Range(0, dataPoints.Count()).Select(x => (double)x).ToArray();
     29      Calculate(dataPoints, stdX, out p0, out p1);
     30    }
     31
     32    public void Calculate(double[] y, double[] x, out double p0, out double p1) {
     33      if (y.Count() != x.Count()) {
     34        throw new ArgumentException("The lenght of x and y needs do be equal. ");
     35      }
     36
    2837      double sxy = 0.0;
    2938      double sxx = 0.0;
    30       int n = dataPoints.Count();
    31       double sy = dataPoints.Sum();
     39      int n = y.Count();
     40      double sy = y.Sum();
    3241      double sx = ((n - 1) * n) / 2;
    3342      double avgy = sy / n;
     
    3544
    3645      for (int i = 0; i < n; i++) {
    37         sxy += i * dataPoints[i];
    38         sxx += i * i;
     46        sxy += x[i] * y[i];
     47        sxx += x[i] * x[i];
    3948      }
    4049
    41       a1 = (sxy - (n * avgx * avgy)) / (sxx - (n * avgx * avgx));
    42       a0 = avgy - a1 * avgx;
     50      p0 = (sxy - (n * avgx * avgy)) / (sxx - (n * avgx * avgx));
     51      p1 = avgy - p0 * avgx;
    4352    }
    4453
    45     public static double CalculateError(double[] dataPoints, double a1, double a0) {
     54    //TODO: adapt or remove
     55    public double CalculateError(double[] dataPoints, double a1, double a0) {
    4656      double r = 0.0;
    4757      double avgy = dataPoints.Average();
     
    5868      return r;
    5969    }
     70
     71    public DataRow CalculateFittedLine(double[] y, double[] x, string rowName) {
     72      double k, d;
     73      Calculate(y, x, out k, out d);
     74
     75      DataRow newRow = new DataRow(rowName);
     76      for (int i = 0; i < x.Count(); i++) {
     77        newRow.Values.Add(k * x[i] + d);
     78      }
     79      return newRow;
     80    }
     81
     82    public DataRow CalculateFittedLine(double[] dataPoints, string rowName) {
     83      DataRow newRow = new DataRow(rowName);
     84      double c0, c1;
     85      Calculate(dataPoints, out c0, out c1);
     86      var stdX = Enumerable.Range(0, dataPoints.Count()).Select(x => (double)x).ToArray();
     87
     88      for (int i = 0; i < stdX.Count(); i++) {
     89        newRow.Values.Add(c0 * stdX[i] + c1);
     90      }
     91
     92      return newRow;
     93    }
     94
     95    public override string ToString() {
     96      return "Linear Fitting";
     97    }
    6098  }
    6199}
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/Plugin.cs.frame

    r9355 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/Properties/AssemblyInfo.cs.frame

    r9353 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3232[assembly: AssemblyCompany("")]
    3333[assembly: AssemblyProduct("HeuristicLab")]
    34 [assembly: AssemblyCopyright("(c) 2002-2012 HEAL")]
     34[assembly: AssemblyCopyright("(c) 2002-2013 HEAL")]
    3535[assembly: AssemblyTrademark("")]
    3636[assembly: AssemblyCulture("")]
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeChecker.cs

    r9353 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeChecker.designer.cs

    r9353 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeDetermination.cs

    r9353 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.Designer.cs

    r9355 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.cs

    r9355 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/StatisticalTestingView.cs

    r9389 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/StatisticalTestingView.designer.cs

    r9389 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/TTest.cs

    r9353 r9706  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
Note: See TracChangeset for help on using the changeset viewer.