Class AbstractIntegerDistribution
- java.lang.Object
-
- org.apache.commons.math4.distribution.AbstractIntegerDistribution
-
- All Implemented Interfaces:
java.io.Serializable,IntegerDistribution,DiscreteDistribution
- Direct Known Subclasses:
EnumeratedIntegerDistribution
public abstract class AbstractIntegerDistribution extends java.lang.Object 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.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.commons.statistics.distribution.DiscreteDistribution
DiscreteDistribution.Sampler
-
-
Constructor Summary
Constructors Constructor Description AbstractIntegerDistribution()
-
Method Summary
Modifier and Type Method Description DiscreteDistribution.SamplercreateSampler(UniformRandomProvider rng)Creates a sampler.intinverseCumulativeProbability(double p)Computes the quantile function of this distribution.doublelogProbability(int x)For a random variableXwhose values are distributed according to this distribution, this method returnslog(P(X = x)), wherelogis the natural logarithm.doubleprobability(int x0, int x1)For a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1).static int[]sample(int n, DiscreteDistribution.Sampler sampler)Utility function for allocating an array and filling it withnsamples generated by the givensampler.protected intsolveInverseCumulativeProbability(double p, int lower, int upper)This is a utility function used byinverseCumulativeProbability(double).-
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.statistics.distribution.DiscreteDistribution
cumulativeProbability, getMean, getSupportLowerBound, getSupportUpperBound, getVariance, isSupportConnected, probability
-
-
-
-
Method Detail
-
probability
public double probability(int x0, int x1) throws NumberIsTooLargeExceptionFor a random variableXwhose values are distributed according to this distribution, this method returnsP(x0 < X <= x1). The default implementation uses the identityP(x0 < X <= x1) = P(X <= x1) - P(X <= x0)- Specified by:
probabilityin interfaceDiscreteDistribution- Parameters:
x0- Lower bound (exclusive).x1- Upper bound (inclusive).- Returns:
- the probability that a random variable with this distribution
will take a value between
x0andx1, excluding the lower and including the upper endpoint. - Throws:
NumberIsTooLargeException- Since:
- 4.0, was previously named cumulativeProbability
-
inverseCumulativeProbability
public int inverseCumulativeProbability(double p) throws OutOfRangeExceptionComputes the quantile function of this distribution. For a random variableXdistributed according to this distribution, the returned value isinf{x in Z | P(X<=x) >= p}for0 < p <= 1,inf{x in Z | P(X<=x) > 0}forp = 0.
int, thenInteger.MIN_VALUEorInteger.MAX_VALUEis returned. The default implementation returnsDiscreteDistribution.getSupportLowerBound()forp = 0,DiscreteDistribution.getSupportUpperBound()forp = 1, andsolveInverseCumulativeProbability(double, int, int)for0 < p < 1.
- Specified by:
inverseCumulativeProbabilityin interfaceDiscreteDistribution- Parameters:
p- Cumulative probability.- Returns:
- the smallest
p-quantile of this distribution (largest 0-quantile forp = 0). - Throws:
OutOfRangeException
-
solveInverseCumulativeProbability
protected int solveInverseCumulativeProbability(double p, int lower, int upper)This is a utility function used byinverseCumulativeProbability(double). It assumes0 < p < 1and that the inverse cumulative probability lies in the bracket(lower, upper]. The implementation does simple bisection to find the smallestp-quantileinf{x in Z | P(X<=x) >= p}.- Parameters:
p- the cumulative probabilitylower- a value satisfyingcumulativeProbability(lower) < pupper- a value satisfyingp <= cumulativeProbability(upper)- Returns:
- the smallest
p-quantile of this distribution
-
logProbability
public double logProbability(int x)
For a random variableXwhose values are distributed according to this distribution, this method returnslog(P(X = x)), wherelogis the natural logarithm.The default implementation simply computes the logarithm of
probability(x).- Specified by:
logProbabilityin interfaceDiscreteDistribution- Parameters:
x- Point at which the PMF is evaluated.- Returns:
- the logarithm of the value of the probability mass function at
x.
-
sample
public static int[] sample(int n, DiscreteDistribution.Sampler sampler)Utility function for allocating an array and filling it withnsamples generated by the givensampler.- Parameters:
n- Number of samples.sampler- Sampler.- Returns:
- an array of size
n.
-
createSampler
public DiscreteDistribution.Sampler createSampler(UniformRandomProvider rng)
Creates a sampler.- Specified by:
createSamplerin interfaceDiscreteDistribution- Parameters:
rng- Generator of uniformly distributed numbers.- Returns:
- a sampler that produces random numbers according this distribution.
-
-