Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/05/15 16:09:10 (9 years ago)
Author:
ascheibe
Message:

#2031 implemented review comments

Location:
trunk/sources/HeuristicLab.Analysis/3.3
Files:
1 added
5 edited
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis/3.3/DataVisualization/DataRow.cs

    r11171 r11914  
    7676      this.values = new ObservableList<double>(original.values);
    7777    }
     78    public DataRow() : this("DataRow") { }
    7879    public DataRow(string name)
    7980      : base(name) {
     
    116117      OnVisualPropertiesChanged();
    117118    }
     119    protected override void OnNameChanged() {
     120      base.OnNameChanged();
     121      VisualProperties.DisplayName = Name;
     122    }
    118123  }
    119124}
  • trunk/sources/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj

    r11703 r11914  
    161161    <Compile Include="Statistics\BonferroniHolm.cs" />
    162162    <Compile Include="Statistics\EnumerableStatisticsExtension.cs" />
    163     <Compile Include="Statistics\ExpFitting.cs" />
    164     <Compile Include="Statistics\IFitting.cs" />
     163    <Compile Include="Statistics\Fitting\ExpFitting.cs" />
     164    <Compile Include="Statistics\Fitting\IFitting.cs" />
    165165    <Compile Include="Statistics\KruskalWallisTest.cs" />
    166     <Compile Include="Statistics\LinearLeastSquaresFitting.cs" />
    167     <Compile Include="Statistics\LogFitting.cs" />
     166    <Compile Include="Statistics\Fitting\LinearLeastSquaresFitting.cs" />
     167    <Compile Include="Statistics\Fitting\LogFitting.cs" />
    168168    <Compile Include="Statistics\NormalDistribution.cs" />
    169169    <Compile Include="Statistics\PairwiseTest.cs" />
  • trunk/sources/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs

    r11703 r11914  
    4141        pValuesIndizes.Add(i, pValues[i]);
    4242      }
    43       var sortedPValues = pValuesIndizes.OrderBy(x => x.Value);
     43      var sortedPValues = pValuesIndizes.OrderBy(x => x.Value).ToArray();
    4444
    4545      for (int i = 1; i < k + 1; i++) {
    4646        alphaNiveau[i - 1] = globalAlpha / (k - i + 1);
    47         int idx = sortedPValues.ElementAt(i - 1).Key;
     47        int idx = sortedPValues[i - 1].Key;
    4848
    4949        if (i == 1) {
    5050          //true means reject
    51           decision[idx] = sortedPValues.ElementAt(i - 1).Value < alphaNiveau[i - 1];
    52           adjustedPValues[idx] = sortedPValues.ElementAt(i - 1).Value * (k - i + 1);
     51          decision[idx] = sortedPValues[i - 1].Value < alphaNiveau[i - 1];
     52          adjustedPValues[idx] = sortedPValues[i - 1].Value * (k - i + 1);
    5353        } else {
    54           decision[idx] = decision[sortedPValues.ElementAt(i - 2).Key] ? (sortedPValues.ElementAt(i - 1).Value < alphaNiveau[i - 1]) : false;
    55           adjustedPValues[idx] = Math.Max(adjustedPValues[sortedPValues.ElementAt(i - 2).Key], sortedPValues.ElementAt(i - 1).Value * (k - i + 1));
     54          decision[idx] = decision[sortedPValues[i - 2].Key] && (sortedPValues[i - 1].Value < alphaNiveau[i - 1]);
     55          adjustedPValues[idx] = Math.Max(adjustedPValues[sortedPValues[i - 2].Key], sortedPValues[i - 1].Value * (k - i + 1));
    5656        }
    5757        if (adjustedPValues[idx] > 1.0) {
  • trunk/sources/HeuristicLab.Analysis/3.3/Statistics/EnumerableStatisticsExtension.cs

    r11703 r11914  
    2828  public static class EnumerableStatisticExtensions {
    2929    public static Tuple<double, double> ConfidenceIntervals(this IEnumerable<double> values, double alpha) {
    30       if (values.Count() <= 1) return new Tuple<double, double>(double.NaN, double.NaN);
     30      return ConfidenceIntervals(values.ToArray(), alpha);
     31    }
    3132
     33    public static Tuple<double, double> ConfidenceIntervals(this double[] values, double alpha) {
    3234      double lower, upper;
     35      int n = values.Length;
     36      if (n <= 1) return new Tuple<double, double>(double.NaN, double.NaN);
     37
    3338      double s = values.StandardDeviation();
    3439      double x = values.Average();
    35       int n = values.Count();
    3640      double t = alglib.invstudenttdistribution(n - 1, (1.0 - alpha) / 2.0);
    3741
  • trunk/sources/HeuristicLab.Analysis/3.3/Statistics/Fitting/ExpFitting.cs

    r11913 r11914  
    2525namespace HeuristicLab.Analysis.Statistics {
    2626  public class ExpFitting : IFitting {
    27     private void LogFunc(double[] c, double[] x, ref double func, object obj) {
     27    private void ExpFunc(double[] c, double[] x, ref double func, object obj) {
    2828      func = Math.Exp(-c[0] * Math.Pow(x[0], 2));
    2929    }
     
    3434    }
    3535
    36     public void Calculate(double[] dataPoints, out double p0, out double p1) {
     36    public void Calculate(double[] dataPoints, out double p0) {
    3737      var stdX = GetDefaultXValues(dataPoints.Count());
    38       Calculate(dataPoints, stdX, out p0, out p1);
     38      Calculate(dataPoints, stdX, out p0);
    3939    }
    4040
    41     public void Calculate(double[] y, double[] x, out double p0, out double p1) {
     41    public void Calculate(double[] y, double[] x, out double p0) {
    4242      if (y.Count() != x.Count()) {
    4343        throw new ArgumentException("The lenght of x and y needs do be equal. ");
     
    6060      alglib.lsfitcreatef(xx, y, c, diffstep, out state);
    6161      alglib.lsfitsetcond(state, epsf, epsx, maxits);
    62       alglib.lsfitfit(state, LogFunc, null, null);
     62      alglib.lsfitfit(state, ExpFunc, null, null);
    6363      alglib.lsfitresults(state, out info, out c, out rep);
    6464
    6565      p0 = c[0];
    66       p1 = c[0];
    6766    }
    6867
    69     public DataRow CalculateFittedLine(double[] dataPoints, string rowName) {
    70       DataRow newRow = new DataRow(rowName);
    71       double c0, c1;
    72       Calculate(dataPoints, out c0, out c1);
     68    public DataRow CalculateFittedLine(double[] dataPoints) {
     69      DataRow newRow = new DataRow();
     70      double c0;
     71      Calculate(dataPoints, out c0);
    7372      var stdX = GetDefaultXValues(dataPoints.Count());
    7473
     
    8079    }
    8180
    82     public DataRow CalculateFittedLine(double[] y, double[] x, string rowName) {
    83       DataRow newRow = new DataRow(rowName);
    84       double c0, c1;
    85       Calculate(y, x, out c0, out c1);
     81    public DataRow CalculateFittedLine(double[] y, double[] x) {
     82      DataRow newRow = new DataRow();
     83      double c0;
     84      Calculate(y, x, out c0);
    8685
    8786      for (int i = 0; i < x.Count(); i++) {
  • trunk/sources/HeuristicLab.Analysis/3.3/Statistics/Fitting/IFitting.cs

    r11913 r11914  
    2222namespace HeuristicLab.Analysis.Statistics {
    2323  public interface IFitting {
    24     void Calculate(double[] dataPoints, out double p0, out double p1);
    25     void Calculate(double[] y, double[] x, out double p0, out double p1);
    26 
    27     DataRow CalculateFittedLine(double[] dataPoints, string rowName);
    28     DataRow CalculateFittedLine(double[] y, double[] x, string rowName);
     24    DataRow CalculateFittedLine(double[] dataPoints);
     25    DataRow CalculateFittedLine(double[] y, double[] x);
    2926  }
    3027}
  • trunk/sources/HeuristicLab.Analysis/3.3/Statistics/Fitting/LinearLeastSquaresFitting.cs

    r11913 r11914  
    2525namespace HeuristicLab.Analysis.Statistics {
    2626  public class LinearLeastSquaresFitting : IFitting {
    27     public void Calculate(double[] dataPoints, out double p0, out double p1) {
     27    public void Calculate(double[] dataPoints, out double slope, out double intercept) {
    2828      var stdX = Enumerable.Range(0, dataPoints.Count()).Select(x => (double)x).ToArray();
    29       Calculate(dataPoints, stdX, out p0, out p1);
     29      Calculate(dataPoints, stdX, out slope, out intercept);
    3030    }
    3131
    32     public void Calculate(double[] y, double[] x, out double p0, out double p1) {
     32    public void Calculate(double[] y, double[] x, out double slope, out double intercept) {
    3333      if (y.Count() != x.Count()) {
    3434        throw new ArgumentException("The lenght of x and y needs do be equal. ");
     
    4848      }
    4949
    50       p0 = (sxy - (n * avgx * avgy)) / (sxx - (n * avgx * avgx));
    51       p1 = avgy - p0 * avgx;
     50      slope = (sxy - (n * avgx * avgy)) / (sxx - (n * avgx * avgx));
     51      intercept = avgy - slope * avgx;
    5252    }
    5353
    54     public double CalculateError(double[] dataPoints, double p0, double p1) {
     54    public double CalculateError(double[] dataPoints, double slope, double intercept) {
    5555      double r;
    5656      double avgy = dataPoints.Average();
     
    5959
    6060      for (int i = 0; i < dataPoints.Count(); i++) {
    61         double y = p0 * i + p1;
     61        double y = slope * i + intercept;
    6262        sstot += Math.Pow(dataPoints[i] - avgy, 2);
    6363        sserr += Math.Pow(dataPoints[i] - y, 2);
     
    6868    }
    6969
    70     public DataRow CalculateFittedLine(double[] y, double[] x, string rowName) {
    71       double k, d;
    72       Calculate(y, x, out k, out d);
     70    public DataRow CalculateFittedLine(double[] y, double[] x) {
     71      double slope, intercept;
     72      Calculate(y, x, out slope, out intercept);
    7373
    74       DataRow newRow = new DataRow(rowName);
     74      DataRow newRow = new DataRow();
    7575      for (int i = 0; i < x.Count(); i++) {
    76         newRow.Values.Add(k * x[i] + d);
     76        newRow.Values.Add(slope * x[i] + intercept);
    7777      }
    7878      return newRow;
    7979    }
    8080
    81     public DataRow CalculateFittedLine(double[] dataPoints, string rowName) {
    82       DataRow newRow = new DataRow(rowName);
    83       double c0, c1;
    84       Calculate(dataPoints, out c0, out c1);
     81    public DataRow CalculateFittedLine(double[] dataPoints) {
     82      DataRow newRow = new DataRow();
     83      double slope, intercept;
     84      Calculate(dataPoints, out slope, out intercept);
    8585      var stdX = Enumerable.Range(0, dataPoints.Count()).Select(x => (double)x).ToArray();
    8686
    8787      for (int i = 0; i < stdX.Count(); i++) {
    88         newRow.Values.Add(c0 * stdX[i] + c1);
     88        newRow.Values.Add(slope * stdX[i] + intercept);
    8989      }
    9090
  • trunk/sources/HeuristicLab.Analysis/3.3/Statistics/Fitting/LogFitting.cs

    r11913 r11914  
    6767    }
    6868
    69     public DataRow CalculateFittedLine(double[] dataPoints, string rowName) {
    70       DataRow newRow = new DataRow(rowName);
     69    public DataRow CalculateFittedLine(double[] dataPoints) {
     70      DataRow newRow = new DataRow();
    7171      double c0, c1;
    7272      Calculate(dataPoints, out c0, out c1);
     
    8080    }
    8181
    82     public DataRow CalculateFittedLine(double[] y, double[] x, string rowName) {
    83       DataRow newRow = new DataRow(rowName);
     82    public DataRow CalculateFittedLine(double[] y, double[] x) {
     83      DataRow newRow = new DataRow();
    8484      double c0, c1;
    8585      Calculate(y, x, out c0, out c1);
  • trunk/sources/HeuristicLab.Analysis/3.3/Statistics/SampleSizeDetermination.cs

    r11703 r11914  
    3636      if (conf < 0.0 || conf > 1.0) throw new ArgumentException("The confidence interval must be between zero and one.");
    3737
    38       var confInterval = samples.ConfidenceIntervals(0.95);
     38      var confInterval = samples.ConfidenceIntervals(conf);
    3939      double e = (confInterval.Item2 - confInterval.Item1) / 2;
    4040      double s = samples.StandardDeviation();
     
    4343
    4444      double result = Math.Pow(s, 2) / ((Math.Pow(e, 2) / Math.Pow(z, 2)) + (Math.Pow(s, 2) / n));
    45 
    46       result = Math.Ceiling(result);
    47       if (result > int.MaxValue)
    48         return int.MaxValue;
    49       else
    50         return (int)result;
    51     }
    52 
    53     public static int DetermineSampleSizeByEstimatingMeanForLargeSampleSizes(double[] samples, double conf = 0.95) {
    54       if (conf < 0.0 || conf > 1.0) throw new ArgumentException("The confidence interval must be between zero and one.");
    55 
    56       var confInterval = samples.ConfidenceIntervals(0.95);
    57       double e = (confInterval.Item2 - confInterval.Item1) / 2;
    58       double s = samples.StandardDeviation();
    59       double z = alglib.invnormaldistribution((conf + 1) / 2);
    60 
    61       double result = Math.Pow(z, 2) * (Math.Pow(s, 2) / Math.Pow(e, 2));
    6245
    6346      result = Math.Ceiling(result);
Note: See TracChangeset for help on using the changeset viewer.