Class AbstractIntegerDistribution
- java.lang.Object
-
- org.apache.commons.math4.legacy.distribution.AbstractIntegerDistribution
-
- All Implemented Interfaces:
org.apache.commons.statistics.distribution.DiscreteDistribution
- Direct Known Subclasses:
EnumeratedIntegerDistribution
public abstract class AbstractIntegerDistribution extends Object implements org.apache.commons.statistics.distribution.DiscreteDistribution
Base class for integer-valued discrete distributions. Default implementations are provided for some of the methods that do not vary from distribution to distribution.
-
-
Constructor Summary
Constructors Constructor Description AbstractIntegerDistribution()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.commons.statistics.distribution.DiscreteDistribution.Sampler
createSampler(org.apache.commons.rng.UniformRandomProvider rng)
int
inverseCumulativeProbability(double p)
The default implementation returnsDiscreteDistribution.getSupportLowerBound()
forp = 0
,DiscreteDistribution.getSupportUpperBound()
forp = 1
, andsolveInverseCumulativeProbability(double, int, int)
for0 < p < 1
.double
logProbability(int x)
double
probability(int x0, int x1)
The default implementation uses the identitystatic int[]
sample(int n, org.apache.commons.statistics.distribution.DiscreteDistribution.Sampler sampler)
Utility function for allocating an array and filling it withn
samples generated by the givensampler
.protected int
solveInverseCumulativeProbability(double p, int lower, int upper)
This is a utility function used byinverseCumulativeProbability(double)
.
-
-
-
Constructor Detail
-
AbstractIntegerDistribution
public AbstractIntegerDistribution()
-
-
Method Detail
-
probability
public double probability(int x0, int x1) throws NumberIsTooLargeException
The default implementation uses the identityP(x0 < X <= x1) = P(X <= x1) - P(X <= x0)
- Specified by:
probability
in interfaceorg.apache.commons.statistics.distribution.DiscreteDistribution
- Throws:
NumberIsTooLargeException
- Since:
- 4.0, was previously named cumulativeProbability
-
inverseCumulativeProbability
public int inverseCumulativeProbability(double p) throws OutOfRangeException
The default implementation returnsDiscreteDistribution.getSupportLowerBound()
forp = 0
,DiscreteDistribution.getSupportUpperBound()
forp = 1
, andsolveInverseCumulativeProbability(double, int, int)
for0 < p < 1
.
- Specified by:
inverseCumulativeProbability
in interfaceorg.apache.commons.statistics.distribution.DiscreteDistribution
- Throws:
OutOfRangeException
-
solveInverseCumulativeProbability
protected int solveInverseCumulativeProbability(double p, int lower, int upper)
This is a utility function used byinverseCumulativeProbability(double)
. It assumes0 < p < 1
and 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) < p
upper
- a value satisfyingp <= cumulativeProbability(upper)
- Returns:
- the smallest
p
-quantile of this distribution
-
logProbability
public double logProbability(int x)
The default implementation simply computes the logarithm of
probability(x)
.- Specified by:
logProbability
in interfaceorg.apache.commons.statistics.distribution.DiscreteDistribution
-
sample
public static int[] sample(int n, org.apache.commons.statistics.distribution.DiscreteDistribution.Sampler sampler)
Utility function for allocating an array and filling it withn
samples generated by the givensampler
.- Parameters:
n
- Number of samples.sampler
- Sampler.- Returns:
- an array of size
n
.
-
createSampler
public org.apache.commons.statistics.distribution.DiscreteDistribution.Sampler createSampler(org.apache.commons.rng.UniformRandomProvider rng)
- Specified by:
createSampler
in interfaceorg.apache.commons.statistics.distribution.DiscreteDistribution
-
-