Class Hypergeom
java.lang.Object
org.apache.commons.statistics.inference.Hypergeom
Provide a wrapper around the
HypergeometricDistribution
that caches
all probability mass values.
This class extracts the logic from the HypergeometricDistribution implementation used for the cumulative probability functions. It allows fast computation of the CDF and SF for the entire supported domain.
- Since:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
1/2.private final int
The lower bound of the support (inclusive).private final int
Cached midpoint, m, of the CDF/SF.private final int
Lower mode.private final int
Upper mode.private final double
Cached CDF of the midpoint.private final double[]
Cached probability values.private final int
The upper bound of the support (inclusive). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) double
cdf
(int x) Compute the cumulative distribution function (CDF) at the specified value.(package private) int
Get the lower mode of the distribution.(package private) int
Get the lower bound of the support.(package private) int
Get the upper bound of the support.(package private) int
Get the upper mode of the distribution.private double
innerCumulativeProbability
(int x0, int x1) For this distribution,X
, this method returnsP(x0 <= X <= x1)
.(package private) double
pmf
(int x) Compute the probability mass function (PMF) at the specified value.(package private) double
sf
(int x) Compute the survival function (SF) at the specified value.
-
Field Details
-
HALF
private static final double HALF1/2.- See Also:
-
lowerBound
private final int lowerBoundThe lower bound of the support (inclusive). -
upperBound
private final int upperBoundThe upper bound of the support (inclusive). -
prob
private final double[] probCached probability values. This holds values from x=0 even though the supported lower bound may be above x=0. This allows x to be used as an index without offsetting using the lower bound. -
m
private final int mCached midpoint, m, of the CDF/SF. This is not the true median. It is the value where the CDF is closest to 0.5; as such the CDF(m) may be below 0.5 if the next value CDF(m+1) is further from 0.5. Used for the cumulative probability functions. -
midCDF
private final double midCDFCached CDF of the midpoint. Used for the cumulative probability functions. -
m1
private final int m1Lower mode. -
m2
private final int m2Upper mode.
-
-
Constructor Details
-
Hypergeom
Hypergeom(int populationSize, int numberOfSuccesses, int sampleSize) - Parameters:
populationSize
- Population size.numberOfSuccesses
- Number of successes in the population.sampleSize
- Sample size.
-
-
Method Details
-
getSupportLowerBound
int getSupportLowerBound()Get the lower bound of the support.- Returns:
- lower bound
-
getSupportUpperBound
int getSupportUpperBound()Get the upper bound of the support.- Returns:
- upper bound
-
getLowerMode
int getLowerMode()Get the lower mode of the distribution.- Returns:
- lower mode
-
getUpperMode
int getUpperMode()Get the upper mode of the distribution.- Returns:
- upper mode
-
pmf
double pmf(int x) Compute the probability mass function (PMF) at the specified value.- Parameters:
x
- Value.- Returns:
- P(X = x)
- Throws:
IndexOutOfBoundsException
- if the valuex
is not in the supported domain.
-
cdf
double cdf(int x) Compute the cumulative distribution function (CDF) at the specified value.- Parameters:
x
- Value.- Returns:
- P(X invalid input: '<'= x)
-
sf
double sf(int x) Compute the survival function (SF) at the specified value. This is the complementary cumulative distribution function.- Parameters:
x
- Value.- Returns:
- P(X > x)
-
innerCumulativeProbability
private double innerCumulativeProbability(int x0, int x1) For this distribution,X
, this method returnsP(x0 <= X <= x1)
. This probability is computed by summing the point probabilities for the valuesx0, x0 + dx, x0 + 2 * dx, ..., x1
; the directiondx
is determined using a comparison of the input bounds. This should be called by usingx0
as the domain limit andx1
as the internal value. This will result in a sum of increasingly larger magnitudes.- Parameters:
x0
- Inclusive domain bound.x1
- Inclusive internal bound.- Returns:
P(x0 <= X <= x1)
.
-