Changeset 11914
- Timestamp:
- 02/05/15 16:09:10 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 8 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis.Statistics.Views/3.3/ChartAnalysisView.cs
r11705 r11914 177 177 178 178 var fittingAlg = fittingComboBox.SelectedItem as IFitting; 179 DataRow newRow = fittingAlg.CalculateFittedLine(values, row.Name + " (" + fittingAlg + ")"); 179 DataRow newRow = fittingAlg.CalculateFittedLine(values); 180 newRow.Name = row.Name + " (" + fittingAlg + ")"; 180 181 181 182 if (!resTable.Rows.ContainsKey(newRow.Name)) … … 265 266 LinearLeastSquaresFitting llsFitting = new LinearLeastSquaresFitting(); 266 267 string[] columnNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", 267 "Avg. of Upper 25 %", " Avg. of Lower 25 %", "Avg. of First 25 %", "Avg. of Last 25 %", " Linear Gradient", "Average Relative Error" };268 "Avg. of Upper 25 %", " Avg. of Lower 25 %", "Avg. of First 25 %", "Avg. of Last 25 %", "Slope", "Intercept", "Average Relative Error" }; 268 269 269 270 runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible).ToList(); … … 277 278 dt.SortableView = true; 278 279 DataRow row = resTable.Rows[rowName]; 279 var values = row.Values. AsEnumerable();280 var values = row.Values.ToArray(); 280 281 281 282 double cnt = values.Count(); … … 292 293 double firstAvg = values.Take((int)(values.Count() * 0.25)).Average(); 293 294 double lastAvg = values.Skip((int)(values.Count() * 0.75)).Average(); 294 double k, d, r;295 llsFitting.Calculate(values .ToArray(), out k, out d);296 r = llsFitting.CalculateError(values .ToArray(), k, d);295 double slope, intercept, r; 296 llsFitting.Calculate(values, out slope, out intercept); 297 r = llsFitting.CalculateError(values, slope, intercept); 297 298 298 299 dt[i, 0] = cnt; … … 309 310 dt[i, 11] = firstAvg; 310 311 dt[i, 12] = lastAvg; 311 dt[i, 13] = k; 312 dt[i, 14] = r; 312 dt[i, 13] = slope; 313 dt[i, 14] = intercept; 314 dt[i, 15] = r; 313 315 314 316 i++; -
trunk/sources/HeuristicLab.Analysis.Statistics.Views/3.3/SampleSizeInfluenceView.cs
r11705 r11914 333 333 if (yValue.Any(x => !x.HasValue)) return; 334 334 335 double estimatedSampleSize = SampleSizeDetermination.DetermineSampleSizeByEstimatingMean ForLargeSampleSizes(yValue.Select(x => x.Value).ToArray());335 double estimatedSampleSize = SampleSizeDetermination.DetermineSampleSizeByEstimatingMean(yValue.Select(x => x.Value).ToArray()); 336 336 sampleSizeTextBox.Text = estimatedSampleSize.ToString(); 337 337 } -
trunk/sources/HeuristicLab.Analysis/3.3/DataVisualization/DataRow.cs
r11171 r11914 76 76 this.values = new ObservableList<double>(original.values); 77 77 } 78 public DataRow() : this("DataRow") { } 78 79 public DataRow(string name) 79 80 : base(name) { … … 116 117 OnVisualPropertiesChanged(); 117 118 } 119 protected override void OnNameChanged() { 120 base.OnNameChanged(); 121 VisualProperties.DisplayName = Name; 122 } 118 123 } 119 124 } -
trunk/sources/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj
r11703 r11914 161 161 <Compile Include="Statistics\BonferroniHolm.cs" /> 162 162 <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" /> 165 165 <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" /> 168 168 <Compile Include="Statistics\NormalDistribution.cs" /> 169 169 <Compile Include="Statistics\PairwiseTest.cs" /> -
trunk/sources/HeuristicLab.Analysis/3.3/Statistics/BonferroniHolm.cs
r11703 r11914 41 41 pValuesIndizes.Add(i, pValues[i]); 42 42 } 43 var sortedPValues = pValuesIndizes.OrderBy(x => x.Value) ;43 var sortedPValues = pValuesIndizes.OrderBy(x => x.Value).ToArray(); 44 44 45 45 for (int i = 1; i < k + 1; i++) { 46 46 alphaNiveau[i - 1] = globalAlpha / (k - i + 1); 47 int idx = sortedPValues .ElementAt(i - 1).Key;47 int idx = sortedPValues[i - 1].Key; 48 48 49 49 if (i == 1) { 50 50 //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); 53 53 } 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)); 56 56 } 57 57 if (adjustedPValues[idx] > 1.0) { -
trunk/sources/HeuristicLab.Analysis/3.3/Statistics/EnumerableStatisticsExtension.cs
r11703 r11914 28 28 public static class EnumerableStatisticExtensions { 29 29 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 } 31 32 33 public static Tuple<double, double> ConfidenceIntervals(this double[] values, double alpha) { 32 34 double lower, upper; 35 int n = values.Length; 36 if (n <= 1) return new Tuple<double, double>(double.NaN, double.NaN); 37 33 38 double s = values.StandardDeviation(); 34 39 double x = values.Average(); 35 int n = values.Count();36 40 double t = alglib.invstudenttdistribution(n - 1, (1.0 - alpha) / 2.0); 37 41 -
trunk/sources/HeuristicLab.Analysis/3.3/Statistics/Fitting/ExpFitting.cs
r11913 r11914 25 25 namespace HeuristicLab.Analysis.Statistics { 26 26 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) { 28 28 func = Math.Exp(-c[0] * Math.Pow(x[0], 2)); 29 29 } … … 34 34 } 35 35 36 public void Calculate(double[] dataPoints, out double p0 , out double p1) {36 public void Calculate(double[] dataPoints, out double p0) { 37 37 var stdX = GetDefaultXValues(dataPoints.Count()); 38 Calculate(dataPoints, stdX, out p0 , out p1);38 Calculate(dataPoints, stdX, out p0); 39 39 } 40 40 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) { 42 42 if (y.Count() != x.Count()) { 43 43 throw new ArgumentException("The lenght of x and y needs do be equal. "); … … 60 60 alglib.lsfitcreatef(xx, y, c, diffstep, out state); 61 61 alglib.lsfitsetcond(state, epsf, epsx, maxits); 62 alglib.lsfitfit(state, LogFunc, null, null);62 alglib.lsfitfit(state, ExpFunc, null, null); 63 63 alglib.lsfitresults(state, out info, out c, out rep); 64 64 65 65 p0 = c[0]; 66 p1 = c[0];67 66 } 68 67 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); 73 72 var stdX = GetDefaultXValues(dataPoints.Count()); 74 73 … … 80 79 } 81 80 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); 86 85 87 86 for (int i = 0; i < x.Count(); i++) { -
trunk/sources/HeuristicLab.Analysis/3.3/Statistics/Fitting/IFitting.cs
r11913 r11914 22 22 namespace HeuristicLab.Analysis.Statistics { 23 23 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); 29 26 } 30 27 } -
trunk/sources/HeuristicLab.Analysis/3.3/Statistics/Fitting/LinearLeastSquaresFitting.cs
r11913 r11914 25 25 namespace HeuristicLab.Analysis.Statistics { 26 26 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) { 28 28 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); 30 30 } 31 31 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) { 33 33 if (y.Count() != x.Count()) { 34 34 throw new ArgumentException("The lenght of x and y needs do be equal. "); … … 48 48 } 49 49 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; 52 52 } 53 53 54 public double CalculateError(double[] dataPoints, double p0, double p1) {54 public double CalculateError(double[] dataPoints, double slope, double intercept) { 55 55 double r; 56 56 double avgy = dataPoints.Average(); … … 59 59 60 60 for (int i = 0; i < dataPoints.Count(); i++) { 61 double y = p0 * i + p1;61 double y = slope * i + intercept; 62 62 sstot += Math.Pow(dataPoints[i] - avgy, 2); 63 63 sserr += Math.Pow(dataPoints[i] - y, 2); … … 68 68 } 69 69 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); 73 73 74 DataRow newRow = new DataRow( rowName);74 DataRow newRow = new DataRow(); 75 75 for (int i = 0; i < x.Count(); i++) { 76 newRow.Values.Add( k * x[i] + d);76 newRow.Values.Add(slope * x[i] + intercept); 77 77 } 78 78 return newRow; 79 79 } 80 80 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); 85 85 var stdX = Enumerable.Range(0, dataPoints.Count()).Select(x => (double)x).ToArray(); 86 86 87 87 for (int i = 0; i < stdX.Count(); i++) { 88 newRow.Values.Add( c0 * stdX[i] + c1);88 newRow.Values.Add(slope * stdX[i] + intercept); 89 89 } 90 90 -
trunk/sources/HeuristicLab.Analysis/3.3/Statistics/Fitting/LogFitting.cs
r11913 r11914 67 67 } 68 68 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(); 71 71 double c0, c1; 72 72 Calculate(dataPoints, out c0, out c1); … … 80 80 } 81 81 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(); 84 84 double c0, c1; 85 85 Calculate(y, x, out c0, out c1); -
trunk/sources/HeuristicLab.Analysis/3.3/Statistics/SampleSizeDetermination.cs
r11703 r11914 36 36 if (conf < 0.0 || conf > 1.0) throw new ArgumentException("The confidence interval must be between zero and one."); 37 37 38 var confInterval = samples.ConfidenceIntervals( 0.95);38 var confInterval = samples.ConfidenceIntervals(conf); 39 39 double e = (confInterval.Item2 - confInterval.Item1) / 2; 40 40 double s = samples.StandardDeviation(); … … 43 43 44 44 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 else50 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));62 45 63 46 result = Math.Ceiling(result);
Note: See TracChangeset
for help on using the changeset viewer.