public double probability()

in commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/HypergeometricDistribution.java [179:202]


    public double probability(int x0, int x1) {
        if (x0 > x1) {
            throw new DistributionException(DistributionException.INVALID_RANGE_LOW_GT_HIGH, x0, x1);
        }
        if (x0 == x1 || x1 < lowerBound) {
            return 0;
        }
        // If the range is outside the bounds use the appropriate cumulative probability
        if (x0 < lowerBound) {
            return cumulativeProbability(x1);
        }
        if (x1 >= upperBound) {
            // 1 - cdf(x0)
            return survivalProbability(x0);
        }
        // Here: lower <= x0 < x1 < upper:
        // sum(pdf(x)) for x in (x0, x1]
        final int lo = x0 + 1;
        // Sum small values first by starting at the point the greatest distance from the mode.
        final int mode = (int) Math.floor((sampleSize + 1.0) * (numberOfSuccesses + 1.0) / (populationSize + 2.0));
        return Math.abs(mode - lo) > Math.abs(mode - x1) ?
            innerCumulativeProbability(lo, x1) :
            innerCumulativeProbability(x1, lo);
    }