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:
java.io.Serializable,DiscreteDistribution,Distribution,IntegerDistribution,PascalDistribution
public class PascalDistributionImpl extends AbstractIntegerDistribution implements PascalDistribution, java.io.Serializable
The default implementation ofPascalDistribution.- Since:
- 1.2
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description PascalDistributionImpl(int r, double p)Create a Pascal distribution with the given number of trials and probability of success.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description doublecumulativeProbability(int x)For this distribution, X, this method returns P(X ≤ x).intgetNumberOfSuccesses()Access the number of successes for this distribution.doublegetNumericalMean()Returns the mean.doublegetNumericalVariance()Returns the variance.doublegetProbabilityOfSuccess()Access the probability of success for this distribution.intgetSupportLowerBound()Returns the lower bound of the support for the distribution.intgetSupportUpperBound()Returns the upper bound of the support for the distribution.intinverseCumulativeProbability(double p)For this distribution, X, this method returns the largest x, such that P(X ≤ x) ≤p.doubleprobability(int x)For this distribution, X, this method returns P(X = x).voidsetNumberOfSuccesses(int successes)Deprecated.as of 2.1 (class will become immutable in 3.0)voidsetProbabilityOfSuccess(double p)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, isSupportLowerBoundInclusive, isSupportUpperBoundInclusive, probability, reseedRandomGenerator, sample, sample
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.math.distribution.DiscreteDistribution
probability
-
Methods inherited from interface org.apache.commons.math.distribution.Distribution
cumulativeProbability, cumulativeProbability
-
Methods inherited from interface org.apache.commons.math.distribution.IntegerDistribution
cumulativeProbability
-
-
-
-
Method Detail
-
getNumberOfSuccesses
public int getNumberOfSuccesses()
Access the number of successes for this distribution.- Specified by:
getNumberOfSuccessesin interfacePascalDistribution- Returns:
- the number of successes
-
getProbabilityOfSuccess
public double getProbabilityOfSuccess()
Access the probability of success for this distribution.- Specified by:
getProbabilityOfSuccessin interfacePascalDistribution- 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:
setNumberOfSuccessesin interfacePascalDistribution- Parameters:
successes- the new number of successes- Throws:
java.lang.IllegalArgumentException- ifsuccessesis 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:
setProbabilityOfSuccessin interfacePascalDistribution- Parameters:
p- the new probability of success- Throws:
java.lang.IllegalArgumentException- ifpis not a valid probability.
-
cumulativeProbability
public double cumulativeProbability(int x) throws MathExceptionFor this distribution, X, this method returns P(X ≤ x).- Specified by:
cumulativeProbabilityin interfaceIntegerDistribution- Specified by:
cumulativeProbabilityin classAbstractIntegerDistribution- 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:
probabilityin interfaceIntegerDistribution- Parameters:
x- the value at which the PMF is evaluated- Returns:
- PMF for this distribution
-
inverseCumulativeProbability
public int inverseCumulativeProbability(double p) throws MathExceptionFor this distribution, X, this method returns the largest x, such that P(X ≤ x) ≤p.Returns
-1for p=0 andInteger.MAX_VALUEfor p=1.- Specified by:
inverseCumulativeProbabilityin interfaceIntegerDistribution- Overrides:
inverseCumulativeProbabilityin classAbstractIntegerDistribution- 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.java.lang.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 byInteger.MAX_VALUEtogether withAbstractIntegerDistribution.isSupportUpperBoundInclusive()beingfalse- Returns:
- upper bound of the support (always
Integer.MAX_VALUEfor positive infinity) - Since:
- 2.2
-
getNumericalMean
public double getNumericalMean()
Returns the mean. For number of successesrand probability of successp, the mean is( r * p ) / ( 1 - p )- Returns:
- the mean
- Since:
- 2.2
-
getNumericalVariance
public double getNumericalVariance()
Returns the variance. For number of successesrand probability of successp, the mean is( r * p ) / ( 1 - p )^2- Returns:
- the variance
- Since:
- 2.2
-
-