Class Hypergeom
- java.lang.Object
-
- org.apache.commons.statistics.inference.Hypergeom
-
class Hypergeom extends java.lang.Object
Provide a wrapper around theHypergeometricDistribution
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
Fields Modifier and Type Field Description private static double
HALF
1/2.private int
lowerBound
The lower bound of the support (inclusive).private int
m
Cached midpoint, m, of the CDF/SF.private int
m1
Lower mode.private int
m2
Upper mode.private double
midCDF
Cached CDF of the midpoint.private double[]
prob
Cached probability values.private int
upperBound
The 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) double
cdf(int x)
Compute the cumulative distribution function (CDF) at the specified value.(package private) int
getLowerMode()
Get the lower mode of the distribution.(package private) int
getSupportLowerBound()
Get the lower bound of the support.(package private) int
getSupportUpperBound()
Get the upper bound of the support.(package private) int
getUpperMode()
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 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 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 <= 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)
.
-
-