Changeset 13034


Ignore:
Timestamp:
10/19/15 16:17:04 (4 years ago)
Author:
gkronber
Message:

#2491: removed separate (incorrect) implementation of percentile function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/EnumerableStatisticExtensions.cs

    r13033 r13034  
    202202    /// </summary>
    203203    public static double Percentile(this IEnumerable<double> values, double p) {
    204       // iterate only once
    205       double[] valuesArr = values.ToArray();
    206       int n = valuesArr.Length;
    207       if (n == 0) throw new InvalidOperationException("Enumeration contains no elements.");
    208       if (n == 1) return values.ElementAt(0);
    209 
    210       if (p.IsAlmost(0.0)) return valuesArr[0];
    211       if (p.IsAlmost(1.0)) return valuesArr[n - 1];
    212 
    213       double t = p * (n - 1);
    214       int index = (int)Math.Floor(t);
    215       double percentage = t - index;
    216       return valuesArr[index] * (1 - percentage) + valuesArr[index + 1] * percentage;
     204      // percentiles are actually quantiles where alpha is constrained to integer percentage values from 1% to 99%
     205      return Quantile(values, p);
    217206    }
    218207
Note: See TracChangeset for help on using the changeset viewer.