org.apache.commons.math.distribution
Class PoissonDistributionImpl

java.lang.Object
  extended by org.apache.commons.math.distribution.AbstractDistribution
      extended by org.apache.commons.math.distribution.AbstractIntegerDistribution
          extended by org.apache.commons.math.distribution.PoissonDistributionImpl
All Implemented Interfaces:
java.io.Serializable, DiscreteDistribution, Distribution, IntegerDistribution, PoissonDistribution

public class PoissonDistributionImpl
extends AbstractIntegerDistribution
implements PoissonDistribution, java.io.Serializable

Implementation for the PoissonDistribution.

Version:
$Id: PoissonDistributionImpl.java 1178295 2011-10-03 04:36:27Z psteitz $
See Also:
Serialized Form

Field Summary
static double DEFAULT_EPSILON
          Default convergence criterion.
static int DEFAULT_MAX_ITERATIONS
          Default maximum number of iterations for cumulative probability calculations.
 
Fields inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
randomData
 
Constructor Summary
PoissonDistributionImpl(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.
 
Method Summary
protected  double calculateNumericalMean()
          Use this method to actually calculate the mean for the specific distribution.
protected  double calculateNumericalVariance()
          Use this method to actually calculate the variance for the specific distribution.
 double cumulativeProbability(int x)
          The probability distribution function P(X <= x) for a Poisson distribution.
protected  int getDomainLowerBound(double p)
          Access the domain value lower bound, based on p, used to bracket a CDF root.
protected  int getDomainUpperBound(double p)
          Access the domain value upper bound, based on p, used to bracket a CDF root.
 double getMean()
          Get the mean for the distribution.
 int getSupportLowerBound()
          Access the lower bound of the support.
 int getSupportUpperBound()
          Access the upper bound of the support.
 boolean isSupportUpperBoundInclusive()
          Use this method to get information about whether the upper bound of the support is inclusive or not.
 double normalApproximateProbability(int x)
          Calculates the Poisson distribution function using a normal approximation.
 double probability(int x)
          The probability mass function P(X = x) for a Poisson distribution.
 int sample()
          Generates a random value sampled from this distribution.
 
Methods inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
cumulativeProbability, cumulativeProbability, cumulativeProbability, inverseCumulativeProbability, isSupportLowerBoundInclusive, probability, reseedRandomGenerator, sample
 
Methods inherited from class org.apache.commons.math.distribution.AbstractDistribution
getNumericalMean, getNumericalVariance, isSupportConnected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.commons.math.distribution.IntegerDistribution
cumulativeProbability, inverseCumulativeProbability, reseedRandomGenerator, sample
 
Methods inherited from interface org.apache.commons.math.distribution.DiscreteDistribution
probability
 
Methods inherited from interface org.apache.commons.math.distribution.Distribution
cumulativeProbability, cumulativeProbability, getNumericalMean, getNumericalVariance, isSupportConnected, isSupportLowerBoundInclusive
 

Field Detail

DEFAULT_MAX_ITERATIONS

public static final int DEFAULT_MAX_ITERATIONS
Default maximum number of iterations for cumulative probability calculations.

Since:
2.1
See Also:
Constant Field Values

DEFAULT_EPSILON

public static final double DEFAULT_EPSILON
Default convergence criterion.

Since:
2.1
See Also:
Constant Field Values
Constructor Detail

PoissonDistributionImpl

public PoissonDistributionImpl(double p)
Create a new Poisson distribution with the given the mean. The mean value must be positive; otherwise an IllegalArgument is thrown.

Parameters:
p - the Poisson mean
Throws:
NotStrictlyPositiveException - 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 - Poisson mean.
epsilon - Convergence criterion for cumulative probabilities.
maxIterations - the maximum number of iterations for cumulative probabilities.
Since:
2.1

PoissonDistributionImpl

public PoissonDistributionImpl(double p,
                               double epsilon)
Create a new Poisson distribution with the given mean and convergence criterion.

Parameters:
p - Poisson mean.
epsilon - Convergence criterion for cumulative probabilities.
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 - Poisson mean.
maxIterations - Maximum number of iterations for cumulative probabilities.
Since:
2.1
Method Detail

getMean

public double getMean()
Get the mean for the distribution.

Specified by:
getMean in interface PoissonDistribution
Returns:
the mean for the distribution.

probability

public double probability(int x)
The probability mass function P(X = x) for a Poisson distribution.

Specified by:
probability in interface IntegerDistribution
Parameters:
x - Value at which the probability density function is evaluated.
Returns:
the value of the probability mass function at x.

cumulativeProbability

public double cumulativeProbability(int x)
The probability distribution function P(X <= x) for a Poisson distribution.

Specified by:
cumulativeProbability in interface IntegerDistribution
Specified by:
cumulativeProbability in class AbstractIntegerDistribution
Parameters:
x - Value at which the PDF is evaluated.
Returns:
the Poisson distribution function evaluated at x. due to convergence or other numerical errors.

normalApproximateProbability

public double normalApproximateProbability(int x)
Calculates the Poisson distribution function using a normal approximation. The N(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:
normalApproximateProbability in interface PoissonDistribution
Parameters:
x - Upper bound, inclusive.
Returns:
the distribution function value calculated using a normal approximation. approximation.

sample

public int sample()
Generates a random value sampled from this distribution.
Algorithm Description:

Specified by:
sample in interface IntegerDistribution
Overrides:
sample in class AbstractIntegerDistribution
Returns:
a random value.
Since:
2.2

getDomainLowerBound

protected int getDomainLowerBound(double p)
Access the domain value lower bound, based on p, used to bracket a CDF root. This method is used by AbstractIntegerDistribution.inverseCumulativeProbability(double) to find critical values.

Specified by:
getDomainLowerBound in class AbstractIntegerDistribution
Parameters:
p - Desired probability for the critical value.
Returns:
the domain lower bound.

getDomainUpperBound

protected int getDomainUpperBound(double p)
Access the domain value upper bound, based on p, used to bracket a CDF root. This method is used by AbstractIntegerDistribution.inverseCumulativeProbability(double) to find critical values.

Specified by:
getDomainUpperBound in class AbstractIntegerDistribution
Parameters:
p - Desired probability for the critical value.
Returns:
the domain upper bound.

getSupportLowerBound

public int getSupportLowerBound()
Access the lower bound of the support. The lower bound of the support is always 0 no matter the mean parameter.

Specified by:
getSupportLowerBound in class AbstractIntegerDistribution
Returns:
lower bound of the support (always 0)

getSupportUpperBound

public int getSupportUpperBound()
Access the upper bound of the support. The upper bound of the support is positive infinity, regardless of the parameter values. There is no integer infinity, so this method returns Integer.MAX_VALUE and isSupportUpperBoundInclusive() returns true.

Specified by:
getSupportUpperBound in class AbstractIntegerDistribution
Returns:
upper bound of the support (always Integer.MAX_VALUE for positive infinity)

calculateNumericalMean

protected double calculateNumericalMean()
Use this method to actually calculate the mean for the specific distribution. Use AbstractDistribution.getNumericalMean() (which implements caching) to actually get the mean. For mean parameter p, the mean is p

Specified by:
calculateNumericalMean in class AbstractDistribution
Returns:
the mean or Double.NaN if it's not defined

calculateNumericalVariance

protected double calculateNumericalVariance()
Use this method to actually calculate the variance for the specific distribution. Use AbstractDistribution.getNumericalVariance() (which implements caching) to actually get the variance. For mean parameter p, the variance is p

Specified by:
calculateNumericalVariance in class AbstractDistribution
Returns:
the variance or Double.NaN if it's not defined

isSupportUpperBoundInclusive

public boolean isSupportUpperBoundInclusive()
Use this method to get information about whether the upper bound of the support is inclusive or not. For discrete support, only true here is meaningful.

Specified by:
isSupportUpperBoundInclusive in interface Distribution
Overrides:
isSupportUpperBoundInclusive in class AbstractIntegerDistribution
Returns:
true (always but at Integer.MAX_VALUE because of the nature of discrete support)


Copyright © 2003-2011 The Apache Software Foundation. All Rights Reserved.