Class PoissonDistribution
- java.lang.Object
-
- org.apache.commons.statistics.distribution.AbstractDiscreteDistribution
-
- org.apache.commons.statistics.distribution.PoissonDistribution
-
- All Implemented Interfaces:
DiscreteDistribution
public final class PoissonDistribution extends AbstractDiscreteDistribution
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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.commons.statistics.distribution.DiscreteDistribution
DiscreteDistribution.Sampler
-
-
Constructor Summary
Constructors Modifier Constructor Description private
PoissonDistribution(double mean)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DiscreteDistribution.Sampler
createSampler(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
getSupportLowerBound()
Gets the lower bound of the support.int
getSupportUpperBound()
Gets the upper bound of the support.double
getVariance()
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 Detail
-
MAX_MEAN
private static final double MAX_MEAN
Upper bound on the mean to use the PoissonSampler.- See Also:
- Constant Field Values
-
mean
private final double mean
Mean of the distribution.
-
-
Method Detail
-
of
public static PoissonDistribution of(double mean)
Creates a Poisson distribution.- Parameters:
mean
- Poisson mean.- Returns:
- the distribution
- Throws:
java.lang.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
public DiscreteDistribution.Sampler createSampler(org.apache.commons.rng.UniformRandomProvider rng)
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.
-
-