Class PoissonDistributionImpl
java.lang.Object
org.apache.commons.math.distribution.AbstractDistribution
org.apache.commons.math.distribution.AbstractIntegerDistribution
org.apache.commons.math.distribution.PoissonDistributionImpl
- All Implemented Interfaces:
Serializable,DiscreteDistribution,Distribution,IntegerDistribution,PoissonDistribution
public class PoissonDistributionImpl
extends AbstractIntegerDistribution
implements PoissonDistribution, Serializable
Implementation for the
PoissonDistribution.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleDefault convergence criterion.static final intDefault maximum number of iterations for cumulative probability calculations. -
Constructor Summary
ConstructorsConstructorDescriptionPoissonDistributionImpl(double p) Create a new Poisson distribution with the given the mean.PoissonDistributionImpl(double p, double epsilon) Create a new Poisson distribution with the given mean and convergence criterion.PoissonDistributionImpl(double p, double epsilon, int maxIterations) Create a new Poisson distribution with the given mean, convergence criterion and maximum number of iterations.PoissonDistributionImpl(double p, int maxIterations) Create a new Poisson distribution with the given mean and maximum number of iterations.PoissonDistributionImpl(double p, NormalDistribution z) Deprecated.as of 2.1 (to avoid possibly inconsistent state, the "NormalDistribution" will be instantiated internally) -
Method Summary
Modifier and TypeMethodDescriptiondoublecumulativeProbability(int x) The probability distribution function P(X invalid input: '<'= x) for a Poisson distribution.doublegetMean()Get the Poisson mean for the distribution.doubleReturns the variance of the distribution.intReturns the lower bound of the support for the distribution.intReturns the upper bound of the support for the distribution.doublenormalApproximateProbability(int x) Calculates the Poisson distribution function using a normal approximation.doubleprobability(int x) The probability mass function P(X = x) for a Poisson distribution.intsample()Generates a random value sampled from this distribution.voidsetMean(double p) Deprecated.as of 2.1 (class will become immutable in 3.0)voidsetNormal(NormalDistribution value) Deprecated.as of 2.1 (class will become immutable in 3.0)Methods inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
cumulativeProbability, cumulativeProbability, cumulativeProbability, inverseCumulativeProbability, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive, probability, reseedRandomGenerator, sampleMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.math.distribution.DiscreteDistribution
probabilityMethods inherited from interface org.apache.commons.math.distribution.Distribution
cumulativeProbability, cumulativeProbabilityMethods inherited from interface org.apache.commons.math.distribution.IntegerDistribution
cumulativeProbability, inverseCumulativeProbability
-
Field Details
-
DEFAULT_MAX_ITERATIONS
public static final int DEFAULT_MAX_ITERATIONSDefault maximum number of iterations for cumulative probability calculations.- Since:
- 2.1
- See Also:
-
DEFAULT_EPSILON
public static final double DEFAULT_EPSILONDefault convergence criterion.- Since:
- 2.1
- See Also:
-
-
Constructor Details
-
PoissonDistributionImpl
public PoissonDistributionImpl(double p) Create a new Poisson distribution with the given the mean. The mean value must be positive; otherwise anIllegalArgumentis thrown.- Parameters:
p- the Poisson mean- Throws:
IllegalArgumentException- if p ≤ 0
-
PoissonDistributionImpl
public PoissonDistributionImpl(double p, double epsilon, int maxIterations) Create a new Poisson distribution with the given mean, convergence criterion and maximum number of iterations.- Parameters:
p- the Poisson meanepsilon- the convergence criteria for cumulative probabilitesmaxIterations- the maximum number of iterations for cumulative probabilites- Since:
- 2.1
-
PoissonDistributionImpl
public PoissonDistributionImpl(double p, double epsilon) Create a new Poisson distribution with the given mean and convergence criterion.- Parameters:
p- the Poisson meanepsilon- the convergence criteria for cumulative probabilites- Since:
- 2.1
-
PoissonDistributionImpl
public PoissonDistributionImpl(double p, int maxIterations) Create a new Poisson distribution with the given mean and maximum number of iterations.- Parameters:
p- the Poisson meanmaxIterations- the maximum number of iterations for cumulative probabilites- Since:
- 2.1
-
PoissonDistributionImpl
Deprecated.as of 2.1 (to avoid possibly inconsistent state, the "NormalDistribution" will be instantiated internally)Create a new Poisson distribution with the given the mean. The mean value must be positive; otherwise anIllegalArgumentis thrown.- Parameters:
p- the Poisson meanz- a normal distribution used to compute normal approximations.- Throws:
IllegalArgumentException- if p ≤ 0- Since:
- 1.2
-
-
Method Details
-
getMean
public double getMean()Get the Poisson mean for the distribution.- Specified by:
getMeanin interfacePoissonDistribution- Returns:
- the Poisson mean for the distribution.
-
setMean
Deprecated.as of 2.1 (class will become immutable in 3.0)Set the Poisson mean for the distribution. The mean value must be positive; otherwise anIllegalArgumentis thrown.- Specified by:
setMeanin interfacePoissonDistribution- Parameters:
p- the Poisson mean value- Throws:
IllegalArgumentException- if p ≤ 0
-
probability
public double probability(int x) The probability mass function P(X = x) for a Poisson distribution.- Specified by:
probabilityin interfaceIntegerDistribution- Parameters:
x- the value at which the probability density function is evaluated.- Returns:
- the value of the probability mass function at x
-
cumulativeProbability
The probability distribution function P(X invalid input: '<'= x) for a Poisson distribution.- Specified by:
cumulativeProbabilityin interfaceIntegerDistribution- Specified by:
cumulativeProbabilityin classAbstractIntegerDistribution- Parameters:
x- the value at which the PDF is evaluated.- Returns:
- Poisson distribution function evaluated at x
- Throws:
MathException- if the cumulative probability can not be computed due to convergence or other numerical errors.
-
normalApproximateProbability
Calculates the Poisson distribution function using a normal approximation. TheN(mean, sqrt(mean))distribution is used to approximate the Poisson distribution.The computation uses "half-correction" -- evaluating the normal distribution function at
x + 0.5- Specified by:
normalApproximateProbabilityin interfacePoissonDistribution- Parameters:
x- the upper bound, inclusive- Returns:
- the distribution function value calculated using a normal approximation
- Throws:
MathException- if an error occurs computing the normal approximation
-
sample
Generates a random value sampled from this distribution.Algorithm Description:
- For small means, uses simulation of a Poisson process using Uniform deviates, as described here. The Poisson process (and hence value returned) is bounded by 1000 * mean. invalid input: '<'
- For large means, uses the rejection algorithm described in
Devroye, Luc. (1981).The Computer Generation of Poisson Random Variables Computing vol. 26 pp. 197-207.
- Overrides:
samplein classAbstractIntegerDistribution- Returns:
- random value
- Throws:
MathException- if an error occurs generating the random value- Since:
- 2.2
-
setNormal
Deprecated.as of 2.1 (class will become immutable in 3.0)Modify the normal distribution used to compute normal approximations. The caller is responsible for insuring the normal distribution has the proper parameter settings.- Parameters:
value- the new distribution- Since:
- 1.2
-
getSupportLowerBound
public int getSupportLowerBound()Returns the lower bound of the support for the distribution. The lower bound of the support is always 0 no matter the mean parameter.- Returns:
- lower bound of the support (always 0)
- Since:
- 2.2
-
getSupportUpperBound
public int getSupportUpperBound()Returns the upper bound of the support for the distribution. The upper bound of the support is positive infinity, regardless of the parameter values. There is no integer infinity, so this method returnsInteger.MAX_VALUEandAbstractIntegerDistribution.isSupportUpperBoundInclusive()returnstrue.- Returns:
- upper bound of the support (always
Integer.MAX_VALUEfor positive infinity) - Since:
- 2.2
-
getNumericalVariance
public double getNumericalVariance()Returns the variance of the distribution. For mean parameterp, the variance isp- Returns:
- the variance
- Since:
- 2.2
-