Class Hypergeom
- java.lang.Object
-
- org.apache.commons.statistics.inference.Hypergeom
-
class Hypergeom extends java.lang.ObjectProvide a wrapper around theHypergeometricDistributionthat 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
Fields Modifier and Type Field Description private static doubleHALF1/2.private intlowerBoundThe lower bound of the support (inclusive).private intmCached midpoint, m, of the CDF/SF.private intm1Lower mode.private intm2Upper mode.private doublemidCDFCached CDF of the midpoint.private double[]probCached probability values.private intupperBoundThe upper bound of the support (inclusive).
-
Constructor Summary
Constructors Constructor Description Hypergeom(int populationSize, int numberOfSuccesses, int sampleSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) doublecdf(int x)Compute the cumulative distribution function (CDF) at the specified value.(package private) intgetLowerMode()Get the lower mode of the distribution.(package private) intgetSupportLowerBound()Get the lower bound of the support.(package private) intgetSupportUpperBound()Get the upper bound of the support.(package private) intgetUpperMode()Get the upper mode of the distribution.private doubleinnerCumulativeProbability(int x0, int x1)For this distribution,X, this method returnsP(x0 <= X <= x1).(package private) doublepmf(int x)Compute the probability mass function (PMF) at the specified value.(package private) doublesf(int x)Compute the survival function (SF) at the specified value.
-
-
-
Field Detail
-
HALF
private static final double HALF
1/2.- See Also:
- Constant Field Values
-
lowerBound
private final int lowerBound
The lower bound of the support (inclusive).
-
upperBound
private final int upperBound
The upper bound of the support (inclusive).
-
prob
private final double[] prob
Cached 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 m
Cached 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 midCDF
Cached CDF of the midpoint. Used for the cumulative probability functions.
-
m1
private final int m1
Lower mode.
-
m2
private final int m2
Upper mode.
-
-
Method Detail
-
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:
java.lang.IndexOutOfBoundsException- if the valuexis 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 <= 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 directiondxis determined using a comparison of the input bounds. This should be called by usingx0as the domain limit andx1as 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).
-
-