/// <summary>Gets the relative number of values inside a specific range, for example the relative number of positive values in the specified sample. /// </summary> /// <param name="lowerBound">The lower bound.</param> /// <param name="upperBound">The upper bound.</param> /// <returns>The relative number of values inside the range specified by <paramref name="lowerBound"/> and <paramref name="upperBound"/>.</returns> public double GetRangeStatistics(double lowerBound = 0.0, double upperBound = Double.MaxValue) { int lowerBoundIndex = SortedSample.BinarySearch(lowerBound); if (lowerBoundIndex < 0) { lowerBoundIndex = ~lowerBoundIndex; if (lowerBoundIndex >= SampleSize) // each element is less than the specified lower bound { return(0.0); } } int upperBoundIndex = SortedSample.BinarySearch(upperBound); if (upperBoundIndex < 0) { upperBoundIndex = Math.Max(0, ~upperBoundIndex - 1); } return((upperBoundIndex - lowerBoundIndex + 1.0) / SampleSize); }
/// <summary>Gets a specific value of the cummulative distribution function. /// </summary> /// <param name="x">The value where to evaluate.</param> /// <returns>The specified value of the cummulative distribution function.</returns> public double GetCdfValue(double x) { /* search for n with x_n <= x, where (x_n) is sorted and n is maximal with this property */ int upperBoundIndex = SortedSample.BinarySearch(x); if (upperBoundIndex >= 0) // perhaps there are other items in the sample with the same value { int k = upperBoundIndex; while ((k < SampleSize) && (SortedSample[k] <= x)) { k++; } upperBoundIndex = k - 1; } else { upperBoundIndex = Math.Max(0, ~upperBoundIndex - 1); } return((upperBoundIndex + 1.0) / SampleSize); }