Package smile.stat.distribution
Class HyperGeometricDistribution
java.lang.Object
smile.stat.distribution.DiscreteDistribution
smile.stat.distribution.HyperGeometricDistribution
- All Implemented Interfaces:
Serializable
,Distribution
The hypergeometric distribution is a discrete probability distribution that
describes the number of successes in a sequence of n draws from a finite
population without replacement, just as the binomial distribution describes
the number of successes for draws with replacement.
Suppose you are to draw "n" balls without replacement from an urn containing "N" balls in total, "m" of which are white. The hypergeometric distribution describes the distribution of the number of white balls drawn from the urn.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondouble
cdf
(double k) Cumulative distribution function.double
entropy()
Returns Shannon entropy of the distribution.int
length()
Returns the number of parameters of the distribution.double
logp
(int k) The probability mass function in log scale.double
mean()
Returns the mean of distribution.double
p
(int k) The probability mass function.double
quantile
(double p) The quantile, the probability to the left of quantile is p.double
rand()
Uses inversion by chop-down search from the mode when themean < 20
and the patchwork-rejection method when themean >= 20
.toString()
double
variance()
Returns the variance of distribution.Methods inherited from class smile.stat.distribution.DiscreteDistribution
likelihood, logLikelihood, logp, p, quantile, randi, randi
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface smile.stat.distribution.Distribution
inverseTransformSampling, likelihood, logLikelihood, quantile, quantile, rand, rejectionSampling, sd
-
Field Details
-
N
public final int NThe number of total samples. -
m
public final int mThe number of defects. -
n
public final int nThe number of draws.
-
-
Constructor Details
-
HyperGeometricDistribution
public HyperGeometricDistribution(int N, int m, int n) Constructor.- Parameters:
N
- the number of total samples.m
- the number of defects.n
- the number of draws.
-
-
Method Details
-
length
public int length()Description copied from interface:Distribution
Returns the number of parameters of the distribution. The "length" is in the sense of the minimum description length principle.- Returns:
- The number of parameters.
-
mean
public double mean()Description copied from interface:Distribution
Returns the mean of distribution.- Returns:
- The mean.
-
variance
public double variance()Description copied from interface:Distribution
Returns the variance of distribution.- Returns:
- The variance.
-
entropy
public double entropy()Description copied from interface:Distribution
Returns Shannon entropy of the distribution.- Returns:
- Shannon entropy.
-
toString
-
p
public double p(int k) Description copied from class:DiscreteDistribution
The probability mass function.- Specified by:
p
in classDiscreteDistribution
- Parameters:
k
- a real value.- Returns:
- the probability.
-
logp
public double logp(int k) Description copied from class:DiscreteDistribution
The probability mass function in log scale.- Specified by:
logp
in classDiscreteDistribution
- Parameters:
k
- a real value.- Returns:
- the log probability.
-
cdf
public double cdf(double k) Description copied from interface:Distribution
Cumulative distribution function. That is the probability to the left of x.- Parameters:
k
- a real number.- Returns:
- the probability.
-
quantile
public double quantile(double p) Description copied from interface:Distribution
The quantile, the probability to the left of quantile is p. It is actually the inverse of cdf.- Parameters:
p
- the probability.- Returns:
- the quantile.
-
rand
public double rand()Uses inversion by chop-down search from the mode when themean < 20
and the patchwork-rejection method when themean >= 20
.- Returns:
- a random number.
-