Top Description Fields Constructors Methods
org.apache.commons.math3.distribution

public Class HypergeometricDistribution

extends AbstractIntegerDistribution
Class Inheritance
Imports
org.apache.commons.math3.exception.NotPositiveException, .NotStrictlyPositiveException, .NumberIsTooLargeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.random.RandomGenerator, .Well19937c, org.apache.commons.math3.util.FastMath

Implementation of the hypergeometric distribution.
See Also
Hypergeometric distribution (Wikipedia), Hypergeometric distribution (MathWorld)

Field Summary

Modifier and TypeField and Description
private final int
numberOfSuccesses

The number of successes in the population.

private double
numericalVariance

Cached numerical variance

private boolean
numericalVarianceIsCalculated

Whether or not the numerical variance has been calculated

private final int
populationSize

The population size.

private final int
sampleSize

The sample size.

private static final long
Inherited from org.apache.commons.math3.distribution.AbstractIntegerDistribution:
randomrandomData

Constructor Summary

AccessConstructor and Description
public
HypergeometricDistribution(int
Population size.
populationSize
,
int
Number of successes in the population.
numberOfSuccesses
,
int
Sample size.
sampleSize
)

Construct a new hypergeometric distribution with the specified population size, number of successes in the population, and sample size.

public
HypergeometricDistribution(RandomGenerator
Random number generator.
rng
,
int
Population size.
populationSize
,
int
Number of successes in the population.
numberOfSuccesses
,
int
Sample size.
sampleSize
)

Creates a new hypergeometric distribution.

Method Summary

Modifier and TypeMethod and Description
protected double

Returns:

the variance of this distribution
calculateNumericalVariance
()

Used by getNumericalVariance().

public double
cumulativeProbability(int
the point at which the CDF is evaluated
x
)

Implements org.apache.commons.math3.distribution.IntegerDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x).

private int[]

Returns:

a two element array containing the lower and upper bounds of the hypergeometric distribution.
getDomain
(int
Population size.
n
,
int
Number of successes in the population.
m
,
int
Sample size.
k
)

Return the domain for the given hypergeometric distribution parameters.

private int

Returns:

the lowest domain value of the hypergeometric distribution.
getLowerDomain
(int
Population size.
n
,
int
Number of successes in the population.
m
,
int
Sample size.
k
)

Return the lowest domain value for the given hypergeometric distribution parameters.

public int

Returns:

the number of successes.
getNumberOfSuccesses
()

Access the number of successes.

public double
getNumericalMean()

Implements org.apache.commons.math3.distribution.IntegerDistribution.getNumericalMean.

Use this method to get the numerical value of the mean of this distribution.

public double
getNumericalVariance()

Implements org.apache.commons.math3.distribution.IntegerDistribution.getNumericalVariance.

Use this method to get the numerical value of the variance of this distribution.

public int

Returns:

the population size.
getPopulationSize
()

Access the population size.

public int

Returns:

the sample size.
getSampleSize
()

Access the sample size.

public int

Returns:

lower bound of the support
getSupportLowerBound
()

Implements org.apache.commons.math3.distribution.IntegerDistribution.getSupportLowerBound.

Access the lower bound of the support.

public int

Returns:

upper bound of the support
getSupportUpperBound
()

Implements org.apache.commons.math3.distribution.IntegerDistribution.getSupportUpperBound.

Access the upper bound of the support.

private int

Returns:

the highest domain value of the hypergeometric distribution.
getUpperDomain
(int
Number of successes in the population.
m
,
int
Sample size.
k
)

Return the highest domain value for the given hypergeometric distribution parameters.

private double

Returns:

P(x0 <= X <= x1).
innerCumulativeProbability
(int
Inclusive lower bound.
x0
,
int
Inclusive upper bound.
x1
,
int
Direction of summation (1 indicates summing from x0 to x1, and 0 indicates summing from x1 to x0).
dx
)

For this distribution, X, this method returns P(x0 <= X <= x1).

public boolean

Returns:

true
isSupportConnected
()

Implements org.apache.commons.math3.distribution.IntegerDistribution.isSupportConnected.

Use this method to get information about whether the support is connected, i.e. whether all integers between the lower and upper bound of the support are included in the support.

public double
logProbability(int
the point at which the PMF is evaluated
x
)

Overrides org.apache.commons.math3.distribution.AbstractIntegerDistribution.logProbability.

For a random variable X whose values are distributed according to this distribution, this method returns log(P(X = x)), where log is the natural logarithm.

public double
probability(int
the point at which the PMF is evaluated
x
)

Implements org.apache.commons.math3.distribution.IntegerDistribution.probability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X = x).

public double

Returns:

the upper tail CDF for this distribution.
upperCumulativeProbability
(int
Value at which the CDF is evaluated.
x
)

For this distribution, X, this method returns P(X >= x).

Inherited from org.apache.commons.math3.distribution.AbstractIntegerDistribution:
cumulativeProbabilityinverseCumulativeProbabilityreseedRandomGeneratorsamplesamplesolveInverseCumulativeProbability

Field Detail

numberOfSuccessesback to summary
private final int numberOfSuccesses

The number of successes in the population.

numericalVarianceback to summary
private double numericalVariance

Cached numerical variance

numericalVarianceIsCalculatedback to summary
private boolean numericalVarianceIsCalculated

Whether or not the numerical variance has been calculated

populationSizeback to summary
private final int populationSize

The population size.

sampleSizeback to summary
private final int sampleSize

The sample size.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.math3.distribution.AbstractIntegerDistribution.serialVersionUID.

Serializable version identifier.

Constructor Detail

HypergeometricDistributionback to summary
public HypergeometricDistribution(int populationSize, int numberOfSuccesses, int sampleSize) throws NotPositiveException, NotStrictlyPositiveException, NumberIsTooLargeException

Construct a new hypergeometric distribution with the specified population size, number of successes in the population, and sample size.

Note

this constructor will implicitly create an instance of Well19937c as random generator to be used for sampling only (see sample() and sample(int)). In case no sampling is needed for the created distribution, it is advised to pass null as random generator via the appropriate constructors to avoid the additional initialisation overhead.

Parameters
populationSize:int

Population size.

numberOfSuccesses:int

Number of successes in the population.

sampleSize:int

Sample size.

Exceptions
NotPositiveException:
if numberOfSuccesses < 0.
NotStrictlyPositiveException:
if populationSize <= 0.
NumberIsTooLargeException:
if numberOfSuccesses > populationSize, or sampleSize > populationSize.
HypergeometricDistributionback to summary
public HypergeometricDistribution(RandomGenerator rng, int populationSize, int numberOfSuccesses, int sampleSize) throws NotPositiveException, NotStrictlyPositiveException, NumberIsTooLargeException

Creates a new hypergeometric distribution.

Parameters
rng:RandomGenerator

Random number generator.

populationSize:int

Population size.

numberOfSuccesses:int

Number of successes in the population.

sampleSize:int

Sample size.

Exceptions
NotPositiveException:
if numberOfSuccesses < 0.
NotStrictlyPositiveException:
if populationSize <= 0.
NumberIsTooLargeException:
if numberOfSuccesses > populationSize, or sampleSize > populationSize.
Since
3.1

Method Detail

calculateNumericalVarianceback to summary
protected double calculateNumericalVariance()

Used by getNumericalVariance().

Returns:double

the variance of this distribution

cumulativeProbabilityback to summary
public double cumulativeProbability(int x)

Implements org.apache.commons.math3.distribution.IntegerDistribution.cumulativeProbability.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x). In other words, this method represents the (cumulative) distribution function (CDF) for this distribution.

Parameters
x:int

the point at which the CDF is evaluated

Returns:double

the probability that a random variable with this distribution takes a value less than or equal to x

getDomainback to summary
private int[] getDomain(int n, int m, int k)

Return the domain for the given hypergeometric distribution parameters.

Parameters
n:int

Population size.

m:int

Number of successes in the population.

k:int

Sample size.

Returns:int[]

a two element array containing the lower and upper bounds of the hypergeometric distribution.

getLowerDomainback to summary
private int getLowerDomain(int n, int m, int k)

Return the lowest domain value for the given hypergeometric distribution parameters.

Parameters
n:int

Population size.

m:int

Number of successes in the population.

k:int

Sample size.

Returns:int

the lowest domain value of the hypergeometric distribution.

getNumberOfSuccessesback to summary
public int getNumberOfSuccesses()

Access the number of successes.

Returns:int

the number of successes.

getNumericalMeanback to summary
public double getNumericalMean()

Implements org.apache.commons.math3.distribution.IntegerDistribution.getNumericalMean.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.getNumericalMean.

Use this method to get the numerical value of the mean of this distribution. For population size N, number of successes m, and sample size n, the mean is n * m / N.

Returns:double

the mean or Double.NaN if it is not defined

getNumericalVarianceback to summary
public double getNumericalVariance()

Implements org.apache.commons.math3.distribution.IntegerDistribution.getNumericalVariance.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.getNumericalVariance.

Use this method to get the numerical value of the variance of this distribution. For population size N, number of successes m, and sample size n, the variance is [n * m * (N - n) * (N - m)] / [N^2 * (N - 1)].

Returns:double

the variance (possibly Double.POSITIVE_INFINITY or Double.NaN if it is not defined)

getPopulationSizeback to summary
public int getPopulationSize()

Access the population size.

Returns:int

the population size.

getSampleSizeback to summary
public int getSampleSize()

Access the sample size.

Returns:int

the sample size.

getSupportLowerBoundback to summary
public int getSupportLowerBound()

Implements org.apache.commons.math3.distribution.IntegerDistribution.getSupportLowerBound.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.getSupportLowerBound.

Access the lower bound of the support. This method must return the same value as inverseCumulativeProbability(0). In other words, this method must return

inf {x in Z | P(X <= x) > 0}.

For population size N, number of successes m, and sample size n, the lower bound of the support is max(0, n + m - N).
Returns:int

lower bound of the support

getSupportUpperBoundback to summary
public int getSupportUpperBound()

Implements org.apache.commons.math3.distribution.IntegerDistribution.getSupportUpperBound.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.getSupportUpperBound.

Access the upper bound of the support. This method must return the same value as inverseCumulativeProbability(1). In other words, this method must return

inf {x in R | P(X <= x) = 1}.

For number of successes m and sample size n, the upper bound of the support is min(m, n).
Returns:int

upper bound of the support

getUpperDomainback to summary
private int getUpperDomain(int m, int k)

Return the highest domain value for the given hypergeometric distribution parameters.

Parameters
m:int

Number of successes in the population.

k:int

Sample size.

Returns:int

the highest domain value of the hypergeometric distribution.

innerCumulativeProbabilityback to summary
private double innerCumulativeProbability(int x0, int x1, int dx)

For this distribution, X, this method returns P(x0 <= X <= x1). This probability is computed by summing the point probabilities for the values x0, x0 + 1, x0 + 2, ..., x1, in the order directed by dx.

Parameters
x0:int

Inclusive lower bound.

x1:int

Inclusive upper bound.

dx:int

Direction of summation (1 indicates summing from x0 to x1, and 0 indicates summing from x1 to x0).

Returns:double

P(x0 <= X <= x1).

isSupportConnectedback to summary
public boolean isSupportConnected()

Implements org.apache.commons.math3.distribution.IntegerDistribution.isSupportConnected.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.isSupportConnected.

Use this method to get information about whether the support is connected, i.e. whether all integers between the lower and upper bound of the support are included in the support. The support of this distribution is connected.

Returns:boolean

true

logProbabilityback to summary
public double logProbability(int x)

Overrides org.apache.commons.math3.distribution.AbstractIntegerDistribution.logProbability.

Doc from org.apache.commons.math3.distribution.AbstractIntegerDistribution.logProbability.

For a random variable X whose values are distributed according to this distribution, this method returns log(P(X = x)), where log is the natural logarithm. In other words, this method represents the logarithm of the probability mass function (PMF) for the distribution. Note that due to the floating point precision and under/overflow issues, this method will for some distributions be more precise and faster than computing the logarithm of probability(int).

The default implementation simply computes the logarithm of probability(x).

Parameters
x:int

the point at which the PMF is evaluated

Returns:double

the logarithm of the value of the probability mass function at x

Annotations
@Override
probabilityback to summary
public double probability(int x)

Implements org.apache.commons.math3.distribution.IntegerDistribution.probability.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.probability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X = x). In other words, this method represents the probability mass function (PMF) for the distribution.

Parameters
x:int

the point at which the PMF is evaluated

Returns:double

the value of the probability mass function at x

upperCumulativeProbabilityback to summary
public double upperCumulativeProbability(int x)

For this distribution, X, this method returns P(X >= x).

Parameters
x:int

Value at which the CDF is evaluated.

Returns:double

the upper tail CDF for this distribution.

Since
1.1