Class PoissonDistribution
java.lang.Object
org.apache.commons.statistics.distribution.AbstractDiscreteDistribution
org.apache.commons.statistics.distribution.PoissonDistribution
- All Implemented Interfaces:
DiscreteDistribution
Implementation of the Poisson distribution.
The probability mass function of \( X \) is:
\[ f(k; \lambda) = \frac{\lambda^k e^{-k}}{k!} \]
for \( \lambda \in (0, \infty) \) the mean and \( k \in \{0, 1, 2, \dots\} \) the number of events.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.commons.statistics.distribution.DiscreteDistribution
DiscreteDistribution.Sampler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
0.5 * ln(2 * pi).private static final double
Upper bound on the mean to use the PoissonSampler.private final double
Mean of the distribution. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateSampler
(org.apache.commons.rng.UniformRandomProvider rng) Creates a sampler.double
cumulativeProbability
(int x) For a random variableX
whose values are distributed according to this distribution, this method returnsP(X <= x)
.double
getMean()
Gets the mean of this distribution.int
Gets the lower bound of the support.int
Gets the upper bound of the support.double
Gets the variance of this distribution.double
logProbability
(int x) For a random variableX
whose values are distributed according to this distribution, this method returnslog(P(X = x))
, wherelog
is the natural logarithm.static PoissonDistribution
of
(double mean) Creates a Poisson distribution.double
probability
(int x) For a random variableX
whose values are distributed according to this distribution, this method returnsP(X = x)
.double
survivalProbability
(int x) For a random variableX
whose values are distributed according to this distribution, this method returnsP(X > x)
.Methods inherited from class org.apache.commons.statistics.distribution.AbstractDiscreteDistribution
getMedian, inverseCumulativeProbability, inverseSurvivalProbability, probability
-
Field Details
-
HALF_LOG_TWO_PI
private static final double HALF_LOG_TWO_PI0.5 * ln(2 * pi). Computed to 25-digits precision.- See Also:
-
MAX_MEAN
private static final double MAX_MEANUpper bound on the mean to use the PoissonSampler.- See Also:
-
mean
private final double meanMean of the distribution.
-
-
Constructor Details
-
PoissonDistribution
private PoissonDistribution(double mean) - Parameters:
mean
- Poisson mean. probabilities.
-
-
Method Details
-
of
Creates a Poisson distribution.- Parameters:
mean
- Poisson mean.- Returns:
- the distribution
- Throws:
IllegalArgumentException
- ifmean <= 0
.
-
probability
public double probability(int x) For a random variableX
whose values are distributed according to this distribution, this method returnsP(X = x)
. In other words, this method represents the probability mass function (PMF) for the distribution.- Parameters:
x
- Point at which the PMF is evaluated.- Returns:
- the value of the probability mass function at
x
.
-
logProbability
public double logProbability(int x) For a random variableX
whose values are distributed according to this distribution, this method returnslog(P(X = x))
, wherelog
is the natural logarithm.- Parameters:
x
- Point at which the PMF is evaluated.- Returns:
- the logarithm of the value of the probability mass function at
x
.
-
cumulativeProbability
public double cumulativeProbability(int x) For a random variableX
whose values are distributed according to this distribution, this method returnsP(X <= x)
. In other, words, this method represents the (cumulative) distribution function (CDF) for this distribution.- Parameters:
x
- Point at which the CDF is evaluated.- Returns:
- the probability that a random variable with this distribution
takes a value less than or equal to
x
.
-
survivalProbability
public double survivalProbability(int x) For a random variableX
whose values are distributed according to this distribution, this method returnsP(X > x)
. In other words, this method represents the complementary cumulative distribution function.By default, this is defined as
1 - cumulativeProbability(x)
, but the specific implementation may be more accurate.- Parameters:
x
- Point at which the survival function is evaluated.- Returns:
- the probability that a random variable with this
distribution takes a value greater than
x
.
-
getMean
public double getMean()Gets the mean of this distribution.- Returns:
- the mean.
-
getVariance
public double getVariance()Gets the variance of this distribution.The variance is equal to the
mean
.- Returns:
- the variance.
-
getSupportLowerBound
public int getSupportLowerBound()Gets the lower bound of the support. This method must return the same value asinverseCumulativeProbability(0)
, i.e. \( \inf \{ x \in \mathbb Z : P(X \le x) \gt 0 \} \). By convention,Integer.MIN_VALUE
should be substituted for negative infinity.The lower bound of the support is always 0.
- Returns:
- 0.
-
getSupportUpperBound
public int getSupportUpperBound()Gets the upper bound of the support. This method must return the same value asinverseCumulativeProbability(1)
, i.e. \( \inf \{ x \in \mathbb Z : P(X \le x) = 1 \} \). By convention,Integer.MAX_VALUE
should be substituted for positive infinity.The upper bound of the support is always positive infinity.
- Returns:
Integer.MAX_VALUE
-
createSampler
Creates a sampler.- Specified by:
createSampler
in interfaceDiscreteDistribution
- Overrides:
createSampler
in classAbstractDiscreteDistribution
- Parameters:
rng
- Generator of uniformly distributed numbers.- Returns:
- a sampler that produces random numbers according this distribution.
-