Class BinomialDistributionImpl
java.lang.Object
org.apache.commons.math.distribution.AbstractDistribution
org.apache.commons.math.distribution.AbstractIntegerDistribution
org.apache.commons.math.distribution.BinomialDistributionImpl
- All Implemented Interfaces:
Serializable,BinomialDistribution,DiscreteDistribution,Distribution,IntegerDistribution
public class BinomialDistributionImpl
extends AbstractIntegerDistribution
implements BinomialDistribution, Serializable
The default implementation of
BinomialDistribution.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBinomialDistributionImpl(int trials, double p) Create a binomial distribution with the given number of trials and probability of success. -
Method Summary
Modifier and TypeMethodDescriptiondoublecumulativeProbability(int x) For this distribution, X, this method returns P(X ≤ x).intAccess the number of trials for this distribution.doubleReturns the mean.doubleReturns the variance.doubleAccess the probability of success for this distribution.intReturns the lower bound of the support for the distribution.intReturns 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).voidsetNumberOfTrials(int trials) 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, 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
-
Constructor Details
-
BinomialDistributionImpl
public BinomialDistributionImpl(int trials, double p) Create a binomial distribution with the given number of trials and probability of success.- Parameters:
trials- the number of trials.p- the probability of success.
-
-
Method Details
-
getNumberOfTrials
public int getNumberOfTrials()Access the number of trials for this distribution.- Specified by:
getNumberOfTrialsin interfaceBinomialDistribution- Returns:
- the number of trials.
-
getProbabilityOfSuccess
public double getProbabilityOfSuccess()Access the probability of success for this distribution.- Specified by:
getProbabilityOfSuccessin interfaceBinomialDistribution- Returns:
- the probability of success.
-
setNumberOfTrials
Deprecated.as of 2.1 (class will become immutable in 3.0)Change the number of trials for this distribution.- Specified by:
setNumberOfTrialsin interfaceBinomialDistribution- Parameters:
trials- the new number of trials.- Throws:
IllegalArgumentException- iftrialsis not a valid number of trials.
-
setProbabilityOfSuccess
Deprecated.as of 2.1 (class will become immutable in 3.0)Change the probability of success for this distribution.- Specified by:
setProbabilityOfSuccessin interfaceBinomialDistribution- Parameters:
p- the new probability of success.- Throws:
IllegalArgumentException- ifpis not a valid probability.
-
cumulativeProbability
For 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
For 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) invalid input: '<'= p
- Throws:
MathException- if the inverse cumulative probability can not be computed due to convergence or other numerical errors.IllegalArgumentException- if p invalid input: '<' 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 number of trials and probability 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 the number of trials.- Returns:
- upper bound of the support (equal to number of trials)
- Since:
- 2.2
-
getNumericalMean
public double getNumericalMean()Returns the mean. Fornnumber of trials and probability parameterp, the mean isn * p- Returns:
- the mean
- Since:
- 2.2
-
getNumericalVariance
public double getNumericalVariance()Returns the variance. Fornnumber of trials and probability parameterp, the variance isn * p * (1 - p)- Returns:
- the variance
- Since:
- 2.2
-