Class AbstractIntegerDistribution
- java.lang.Object
-
- org.apache.commons.math.distribution.AbstractDistribution
-
- org.apache.commons.math.distribution.AbstractIntegerDistribution
-
- All Implemented Interfaces:
java.io.Serializable,DiscreteDistribution,Distribution,IntegerDistribution
- Direct Known Subclasses:
BinomialDistributionImpl,HypergeometricDistributionImpl,PascalDistributionImpl,PoissonDistributionImpl,ZipfDistributionImpl
public abstract class AbstractIntegerDistribution extends AbstractDistribution implements IntegerDistribution, java.io.Serializable
Base class for integer-valued discrete distributions. Default implementations are provided for some of the methods that do not vary from distribution to distribution.- Version:
- $Revision: 1067494 $ $Date: 2011-02-05 20:49:07 +0100 (sam. 05 févr. 2011) $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected RandomDataImplrandomDataRandomData instance used to generate samples from the distribution
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractIntegerDistribution()Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description doublecumulativeProbability(double x)For a random variable X whose values are distributed according to this distribution, this method returns P(X ≤ x).doublecumulativeProbability(double x0, double x1)For a random variable X whose values are distributed according to this distribution, this method returns P(x0 ≤ X ≤ x1).abstract doublecumulativeProbability(int x)For a random variable X whose values are distributed according to this distribution, this method returns P(X ≤ x).doublecumulativeProbability(int x0, int x1)For a random variable X whose values are distributed according to this distribution, this method returns P(x0 ≤ X ≤ x1).protected abstract intgetDomainLowerBound(double p)Access the domain value lower bound, based onp, used to bracket a PDF root.protected abstract intgetDomainUpperBound(double p)Access the domain value upper bound, based onp, used to bracket a PDF root.intinverseCumulativeProbability(double p)For a random variable X whose values are distributed according to this distribution, this method returns the largest x, such that P(X ≤ x) ≤p.booleanisSupportLowerBoundInclusive()Use this method to get information about whether the lower bound of the support is inclusive or not.booleanisSupportUpperBoundInclusive()Use this method to get information about whether the upper bound of the support is inclusive or not.doubleprobability(double x)For a random variable X whose values are distributed according to this distribution, this method returns P(X = x).voidreseedRandomGenerator(long seed)Reseeds the random generator used to generate samples.intsample()Generates a random value sampled from this distribution.int[]sample(int sampleSize)Generates a random sample from the distribution.-
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
probability
-
-
-
-
Field Detail
-
randomData
protected final RandomDataImpl randomData
RandomData instance used to generate samples from the distribution- Since:
- 2.2
-
-
Method Detail
-
cumulativeProbability
public double cumulativeProbability(double x) throws MathExceptionFor a random variable X whose values are distributed according to this distribution, this method returns P(X ≤ x). In other words, this method represents the (cumulative) distribution function, or CDF, for this distribution.If
xdoes not represent an integer value, the CDF is evaluated at the greatest integer less than x.- Specified by:
cumulativeProbabilityin interfaceDistribution- Parameters:
x- the value at which the distribution function is evaluated.- Returns:
- cumulative probability that a random variable with this
distribution takes a value less than or equal to
x - Throws:
MathException- if the cumulative probability can not be computed due to convergence or other numerical errors.
-
cumulativeProbability
public double cumulativeProbability(double x0, double x1) throws MathExceptionFor a random variable X whose values are distributed according to this distribution, this method returns P(x0 ≤ X ≤ x1).- Specified by:
cumulativeProbabilityin interfaceDistribution- Overrides:
cumulativeProbabilityin classAbstractDistribution- Parameters:
x0- the (inclusive) lower boundx1- the (inclusive) upper bound- Returns:
- the probability that a random variable with this distribution
will take a value between
x0andx1, including the endpoints. - Throws:
MathException- if the cumulative probability can not be computed due to convergence or other numerical errors.java.lang.IllegalArgumentException- ifx0 > x1
-
cumulativeProbability
public abstract double cumulativeProbability(int x) throws MathExceptionFor a random variable X whose values are distributed according to this distribution, this method returns P(X ≤ x). In other words, this method represents the probability distribution function, or PDF, for this distribution.- Specified by:
cumulativeProbabilityin interfaceIntegerDistribution- 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(double x)
For a random variable X whose values are distributed according to this distribution, this method returns P(X = x). In other words, this method represents the probability mass function, or PMF, for the distribution.If
xdoes not represent an integer value, 0 is returned.- Specified by:
probabilityin interfaceDiscreteDistribution- Parameters:
x- the value at which the probability density function is evaluated- Returns:
- the value of the probability density function at x
-
cumulativeProbability
public double cumulativeProbability(int x0, int x1) throws MathExceptionFor a random variable X whose values are distributed according to this distribution, this method returns P(x0 ≤ X ≤ x1).- Specified by:
cumulativeProbabilityin interfaceIntegerDistribution- Parameters:
x0- the inclusive, lower boundx1- the inclusive, upper bound- Returns:
- the cumulative probability.
- Throws:
MathException- if the cumulative probability can not be computed due to convergence or other numerical errors.java.lang.IllegalArgumentException- if x0 > x1
-
inverseCumulativeProbability
public int inverseCumulativeProbability(double p) throws MathExceptionFor a random variable X whose values are distributed according to this distribution, this method returns the largest x, such that P(X ≤ x) ≤p.- Specified by:
inverseCumulativeProbabilityin interfaceIntegerDistribution- 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
-
reseedRandomGenerator
public void reseedRandomGenerator(long seed)
Reseeds the random generator used to generate samples.- Parameters:
seed- the new seed- Since:
- 2.2
-
sample
public int sample() throws MathExceptionGenerates a random value sampled from this distribution. The default implementation uses the inversion method.- Returns:
- random value
- Throws:
MathException- if an error occurs generating the random value- Since:
- 2.2
-
sample
public int[] sample(int sampleSize) throws MathExceptionGenerates a random sample from the distribution. The default implementation generates the sample by callingsample()in a loop.- Parameters:
sampleSize- number of random values to generate- Returns:
- an array representing the random sample
- Throws:
MathException- if an error occurs generating the samplejava.lang.IllegalArgumentException- if sampleSize is not positive- Since:
- 2.2
-
getDomainLowerBound
protected abstract int getDomainLowerBound(double p)
Access the domain value lower bound, based onp, used to bracket a PDF root. This method is used byinverseCumulativeProbability(double)to find critical values.- Parameters:
p- the desired probability for the critical value- Returns:
- domain value lower bound, i.e.
P(X < lower bound) <
p
-
getDomainUpperBound
protected abstract int getDomainUpperBound(double p)
Access the domain value upper bound, based onp, used to bracket a PDF root. This method is used byinverseCumulativeProbability(double)to find critical values.- Parameters:
p- the desired probability for the critical value- Returns:
- domain value upper bound, i.e.
P(X < upper bound) >
p
-
isSupportLowerBoundInclusive
public boolean isSupportLowerBoundInclusive()
Use this method to get information about whether the lower bound of the support is inclusive or not. For discrete support, only true here is meaningful.- Returns:
- true (always but at Integer.MIN_VALUE because of the nature of discrete support)
- Since:
- 2.2
-
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.- Returns:
- true (always but at Integer.MAX_VALUE because of the nature of discrete support)
- Since:
- 2.2
-
-