org.apache.commons.math.distribution

## Class PascalDistributionImpl

- java.lang.Object
- - org.apache.commons.math.distribution.AbstractDistribution
  - - org.apache.commons.math.distribution.AbstractIntegerDistribution
    - - org.apache.commons.math.distribution.PascalDistributionImpl

All Implemented Interfaces:
  Serializable, DiscreteDistribution, Distribution, IntegerDistribution, PascalDistribution

    public class PascalDistributionImpl
    extends AbstractIntegerDistribution
    implements PascalDistribution, Serializable

The default implementation of `PascalDistribution`.

Since:
  1.2
Version:
  $Revision: 1054524 $ $Date: 2011-01-03 05:59:18 +0100 (lun. 03 janv. 2011) $
See Also:
  Serialized Form

### Field Summary

Fields
`private int` `numberOfSuccesses` The number of successes
`private double` `probabilityOfSuccess` The probability of success
`private static long` `serialVersionUID` Serializable version identifier

### Fields inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution

`randomData`

### Constructor Summary

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

### Method Summary

Methods
`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` `getNumericalMean()` Returns the mean.
`double` `getNumericalVariance()` Returns the variance.
`double` `getProbabilityOfSuccess()` Access the probability of success for this distribution.
`int` `getSupportLowerBound()` Returns the lower bound of the support for the distribution.
`int` `getSupportUpperBound()` Returns the upper bound of the support for the distribution.
`int` `inverseCumulativeProbability(double p)` For this distribution, X, this method returns the largest x, such that P(X ≤ x) ≤ `p`.
`double` `probability(int x)` For this distribution, X, this method returns P(X = x).
`void` `setNumberOfSuccesses(int successes)` Deprecated. as of 2.1 (class will become immutable in 3.0)
`private void` `setNumberOfSuccessesInternal(int successes)` Change the number of successes for this distribution.
`void` `setProbabilityOfSuccess(double p)` Deprecated. as of 2.1 (class will become immutable in 3.0)
`private void` `setProbabilityOfSuccessInternal(double p)` Change the probability of success for this distribution.

### Methods inherited from class org.apache.commons.math.distribution.AbstractIntegerDistribution

`cumulativeProbability, cumulativeProbability, cumulativeProbability, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive, probability, reseedRandomGenerator, sample, sample`

### 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`

### Methods inherited from interface org.apache.commons.math.distribution.DiscreteDistribution

`probability`

### Methods inherited from interface org.apache.commons.math.distribution.Distribution

`cumulativeProbability, cumulativeProbability`

### Field Detail

#### serialVersionUID

    private static final long serialVersionUID

Serializable version identifier

See Also:
  Constant Field Values

#### numberOfSuccesses

    private int numberOfSuccesses

The number of successes

#### probabilityOfSuccess

    private double probabilityOfSuccess

The probability of success

### 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` - the number of successes
  `p` - the 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

#### setNumberOfSuccesses

    @Deprecated
    public void setNumberOfSuccesses(int successes)

Deprecated. as of 2.1 (class will become immutable in 3.0)
Change the number of successes for this distribution.

Specified by:
  `setNumberOfSuccesses` in interface `PascalDistribution`
Parameters:
  `successes` - the new number of successes
Throws:
  `IllegalArgumentException` - if `successes` is not positive.

#### setNumberOfSuccessesInternal

    private void setNumberOfSuccessesInternal(int successes)

Change the number of successes for this distribution.

Parameters:
  `successes` - the new number of successes
Throws:
  `IllegalArgumentException` - if `successes` is not positive.

#### setProbabilityOfSuccess

    @Deprecated
    public void setProbabilityOfSuccess(double p)

Deprecated. as of 2.1 (class will become immutable in 3.0)
Change the probability of success for this distribution.

Specified by:
  `setProbabilityOfSuccess` in interface `PascalDistribution`
Parameters:
  `p` - the new probability of success
Throws:
  `IllegalArgumentException` - if `p` is not a valid probability.

#### setProbabilityOfSuccessInternal

    private void setProbabilityOfSuccessInternal(double p)

Change the probability of success for this distribution.

Parameters:
  `p` - the new probability of success
Throws:
  `IllegalArgumentException` - if `p` is not a valid probability.

#### 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` - the desired probability for the critical value
Returns:
  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` - the desired probability for the critical value
Returns:
  domain value upper bound, i.e. P(X < upper bound) > `p`

#### cumulativeProbability

    public double cumulativeProbability(int x)
                                 throws MathException

For this distribution, X, this method returns P(X ≤ x).

Specified by:
  `cumulativeProbability` in interface `IntegerDistribution`
Specified by:
  `cumulativeProbability` in class `AbstractIntegerDistribution`
Parameters:
  `x` - the value at which the PDF is evaluated
Returns:
  PDF for this distribution
Throws:
  `MathException` - if the cumulative probability can not be computed 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` - the value at which the PMF is evaluated
Returns:
  PMF for this distribution

#### inverseCumulativeProbability

    public int inverseCumulativeProbability(double p)
                                     throws MathException

For this distribution, X, this method returns the largest x, such that P(X ≤ x) ≤ `p`.

Returns `-1` for p=0 and `Integer.MAX_VALUE` for p=1.

Specified by:
  `inverseCumulativeProbability` in interface `IntegerDistribution`
Overrides:
  `inverseCumulativeProbability` in class `AbstractIntegerDistribution`
Parameters:
  `p` - the desired probability
Returns:
  the largest x such that P(X ≤ x) <= p
Throws:
  `MathException` - if the inverse cumulative probability can not be computed due to convergence or other numerical errors.
  `IllegalArgumentException` - if p < 0 or p > 1

#### 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 parameters.

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

Returns:
  upper bound of the support (always `Integer.MAX_VALUE` for positive infinity)
Since:
  2.2

#### getNumericalMean

    public double getNumericalMean()

Returns the mean. For number of successes `r` and probability of success `p`, the mean is `( r * p ) / ( 1 - p )`

Returns:
  the mean
Since:
  2.2

#### getNumericalVariance

    public double getNumericalVariance()

Returns the variance. For number of successes `r` and probability of success `p`, the mean is `( r * p ) / ( 1 - p )^2`

Returns:
  the variance
Since:
  2.2