org.apache.commons.math.distribution
Class PascalDistributionImpl

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.PascalDistributionImpl
All Implemented Interfaces:
java.io.Serializable, DiscreteDistribution, Distribution, IntegerDistribution, PascalDistribution

public class PascalDistributionImpl
extends AbstractIntegerDistribution
implements PascalDistribution, java.io.Serializable

The default implementation of PascalDistribution.

Since:
1.2
Version:
$Id: PascalDistributionImpl.java 1182787 2011-10-13 11:20:48Z celestin $
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
randomData
 
Constructor Summary
PascalDistributionImpl(int r, double p)
          Create a Pascal distribution with the given number of trials and probability of success.
 
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)
          For this distribution, X, this method returns P(X <= x).
protected  int getDomainLowerBound(double p)
          Access the domain value lower bound, based on p, used to bracket a PDF root.
protected  int getDomainUpperBound(double p)
          Access the domain value upper bound, based on p, used to bracket a PDF root.
 int getNumberOfSuccesses()
          Access the number of successes for this distribution.
 double getProbabilityOfSuccess()
          Access the probability of success for this distribution.
 int getSupportLowerBound()
          Access the lower bound of the support.
 int getSupportUpperBound()
          Access the upper bound of the support.
 int inverseCumulativeProbability(double p)
          For this distribution, X, this method returns the largest x, such that P(X <= x) <= p.
 boolean isSupportUpperBoundInclusive()
          Use this method to get information about whether the upper bound of the support is inclusive or not.
 double probability(int x)
          For this distribution, X, this method returns P(X = x).
 
Methods inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution
cumulativeProbability, cumulativeProbability, cumulativeProbability, isSupportLowerBoundInclusive, probability, reseedRandomGenerator, sample, 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, reseedRandomGenerator, sample, 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
 

Constructor Detail

PascalDistributionImpl

public PascalDistributionImpl(int r,
                              double p)
Create a Pascal distribution with the given number of trials and probability of success.

Parameters:
r - Number of successes.
p - Probability of success.
Method Detail

getNumberOfSuccesses

public int getNumberOfSuccesses()
Access the number of successes for this distribution.

Specified by:
getNumberOfSuccesses in interface PascalDistribution
Returns:
the number of successes.

getProbabilityOfSuccess

public double getProbabilityOfSuccess()
Access the probability of success for this distribution.

Specified by:
getProbabilityOfSuccess in interface PascalDistribution
Returns:
the probability of success.

getDomainLowerBound

protected int getDomainLowerBound(double p)
Access the domain value lower bound, based on p, used to bracket a PDF root.

Specified by:
getDomainLowerBound in class AbstractIntegerDistribution
Parameters:
p - Desired probability for the critical value.
Returns:
the domain value lower bound, i.e. P(X < 'lower bound') < p.

getDomainUpperBound

protected int getDomainUpperBound(double p)
Access the domain value upper bound, based on p, used to bracket a PDF root.

Specified by:
getDomainUpperBound in class AbstractIntegerDistribution
Parameters:
p - Desired probability for the critical value
Returns:
the domain value upper bound, i.e. P(X < 'upper bound') > p.

cumulativeProbability

public double cumulativeProbability(int x)
For this distribution, X, this method returns P(X <= x).

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

probability

public double probability(int x)
For this distribution, X, this method returns P(X = x).

Specified by:
probability in interface IntegerDistribution
Parameters:
x - Value at which the PMF is evaluated.
Returns:
PMF for this distribution.

inverseCumulativeProbability

public int inverseCumulativeProbability(double p)
For this distribution, X, this method returns the largest x, such that P(X <= x) <= p. It will return -1 when p = 0 and Integer.MAX_VALUE when p = 1.

Specified by:
inverseCumulativeProbability in interface IntegerDistribution
Overrides:
inverseCumulativeProbability in class AbstractIntegerDistribution
Parameters:
p - Desired probability.
Returns:
the largest x such that P(X <= x) <= p.
Throws:
OutOfRangeException - if p < 0 or p > 1.

getSupportLowerBound

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

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 always positive infinity no matter the parameters. Positive infinity is symbolised by Integer.MAX_VALUE together with isSupportUpperBoundInclusive() being false

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 number of successes r and probability of success p, the mean is ( r * p ) / ( 1 - 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 number of successes r and probability of success p, the mean is ( r * p ) / ( 1 - p )^2

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.