Top Description Fields Constructors Methods
org.apache.commons.math3.distribution

public abstract Class AbstractIntegerDistribution

extends Object
implements IntegerDistribution, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.distribution.IntegerDistribution
Known Direct Subclasses
org.apache.commons.math3.distribution.BinomialDistribution, org.apache.commons.math3.distribution.EnumeratedIntegerDistribution, org.apache.commons.math3.distribution.GeometricDistribution, org.apache.commons.math3.distribution.HypergeometricDistribution, org.apache.commons.math3.distribution.PascalDistribution, org.apache.commons.math3.distribution.PoissonDistribution, org.apache.commons.math3.distribution.UniformIntegerDistribution, org.apache.commons.math3.distribution.ZipfDistribution
Imports
java.io.Serializable, org.apache.commons.math3.exception.MathInternalError, .NotStrictlyPositiveException, .NumberIsTooLargeException, .OutOfRangeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.random.RandomGenerator, org.apache.commons.math3.util.FastMath

Base class for integer-valued discrete distributions. Default implementations are provided for some of the methods that do not vary from distribution to distribution.

Field Summary

Modifier and TypeField and Description
protected final RandomGenerator
random

RNG instance used to generate samples from the distribution.

protected final RandomDataImpl
randomData

Deprecated As of 3.1, to be removed in 4.0. Please use the random instance variable instead.
RandomData instance used to generate samples from the distribution.
private static final long
serialVersionUID

Serializable version identifier

Constructor Summary

AccessConstructor and Description
protected
AbstractIntegerDistribution()
Deprecated As of 3.1, to be removed in 4.0.

protected
AbstractIntegerDistribution(RandomGenerator
Random number generator.
rng
)

Method Summary

Modifier and TypeMethod and Description
private double

Returns:

the cumulative probability
checkedCumulativeProbability
(int
input value
argument
)

Computes the cumulative probability function and checks for NaN values returned.

public double
cumulativeProbability(int
the exclusive lower bound
x0
,
int
the inclusive upper bound
x1
)

Implements org.apache.commons.math3.distribution.IntegerDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(x0 < X <= x1).

public int
inverseCumulativeProbability(final double
the cumulative probability
p
)

Implements org.apache.commons.math3.distribution.IntegerDistribution.inverseCumulativeProbability.

Computes the quantile function of this distribution.

public double

Returns:

the logarithm of the value of the probability mass function at x
logProbability
(int
the point at which the PMF is evaluated
x
)

For a random variable X whose values are distributed according to this distribution, this method returns log(P(X = x)), where log is the natural logarithm.

public void
reseedRandomGenerator(long
the new seed
seed
)

Implements org.apache.commons.math3.distribution.IntegerDistribution.reseedRandomGenerator.

Reseed the random generator used to generate samples.

public int
sample()

Implements org.apache.commons.math3.distribution.IntegerDistribution.sample.

Generate a random value sampled from this distribution.

public int[]
sample(int
the number of random values to generate
sampleSize
)

Implements org.apache.commons.math3.distribution.IntegerDistribution.sample.

Generate a random sample from the distribution.

protected int

Returns:

the smallest p-quantile of this distribution
solveInverseCumulativeProbability
(final double
the cumulative probability
p
,
int
a value satisfying cumulativeProbability(lower) < p
lower
,
int
a value satisfying p <= cumulativeProbability(upper)
upper
)

This is a utility function used by inverseCumulativeProbability(double).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

randomback to summary
protected final RandomGenerator random

RNG instance used to generate samples from the distribution.

Since
3.1
randomDataback to summary
protected final RandomDataImpl randomData

Deprecated

As of 3.1, to be removed in 4.0. Please use the random instance variable instead.

RandomData instance used to generate samples from the distribution.

Annotations
@Deprecated
serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier

Constructor Detail

AbstractIntegerDistributionback to summary
protected AbstractIntegerDistribution()

Deprecated

As of 3.1, to be removed in 4.0. Please use AbstractIntegerDistribution(RandomGenerator) instead.

Annotations
@Deprecated
AbstractIntegerDistributionback to summary
protected AbstractIntegerDistribution(RandomGenerator rng)
Parameters
rng:RandomGenerator

Random number generator.

Since
3.1

Method Detail

checkedCumulativeProbabilityback to summary
private double checkedCumulativeProbability(int argument) throws MathInternalError

Computes the cumulative probability function and checks for NaN values returned. Throws MathInternalError if the value is NaN. Rethrows any exception encountered evaluating the cumulative probability function. Throws MathInternalError if the cumulative probability function returns NaN.

Parameters
argument:int

input value

Returns:double

the cumulative probability

Exceptions
MathInternalError:
if the cumulative probability is NaN
cumulativeProbabilityback to summary
public double cumulativeProbability(int x0, int x1) throws NumberIsTooLargeException

Implements org.apache.commons.math3.distribution.IntegerDistribution.cumulativeProbability.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(x0 < X <= x1). The default implementation uses the identity

P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)

Parameters
x0:int

the exclusive lower bound

x1:int

the inclusive upper bound

Returns:double

the probability that a random variable with this distribution will take a value between x0 and x1, excluding the lower and including the upper endpoint

Exceptions
NumberIsTooLargeException:
if x0 > x1
inverseCumulativeProbabilityback to summary
public int inverseCumulativeProbability(final double p) throws OutOfRangeException

Implements org.apache.commons.math3.distribution.IntegerDistribution.inverseCumulativeProbability.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.inverseCumulativeProbability.

Computes the quantile function of this distribution. For a random variable X distributed according to this distribution, the returned value is

  • inf{x in Z | P(X<=x) >= p} for 0 < p <= 1,
  • inf{x in Z | P(X<=x) > 0} for p = 0.
If the result exceeds the range of the data type int, then Integer.MIN_VALUE or Integer.MAX_VALUE is returned. The default implementation returns
Parameters
p:double

the cumulative probability

Returns:int

the smallest p-quantile of this distribution (largest 0-quantile for p = 0)

Exceptions
OutOfRangeException:
if p < 0 or p > 1
logProbabilityback to summary
public double logProbability(int x)

For a random variable X whose values are distributed according to this distribution, this method returns log(P(X = x)), where log is the natural logarithm. In other words, this method represents the logarithm of the probability mass function (PMF) for the distribution. Note that due to the floating point precision and under/overflow issues, this method will for some distributions be more precise and faster than computing the logarithm of probability(int).

The default implementation simply computes the logarithm of probability(x).

Parameters
x:int

the point at which the PMF is evaluated

Returns:double

the logarithm of the value of the probability mass function at x

reseedRandomGeneratorback to summary
public void reseedRandomGenerator(long seed)

Implements org.apache.commons.math3.distribution.IntegerDistribution.reseedRandomGenerator.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.reseedRandomGenerator.

Reseed the random generator used to generate samples.

Parameters
seed:long

the new seed

sampleback to summary
public int sample()

Implements org.apache.commons.math3.distribution.IntegerDistribution.sample.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.sample.

Generate a random value sampled from this distribution. The default implementation uses the inversion method.

Returns:int

a random value

sampleback to summary
public int[] sample(int sampleSize)

Implements org.apache.commons.math3.distribution.IntegerDistribution.sample.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.sample.

Generate a random sample from the distribution. The default implementation generates the sample by calling sample() in a loop.

Parameters
sampleSize:int

the number of random values to generate

Returns:int[]

an array representing the random sample

solveInverseCumulativeProbabilityback to summary
protected int solveInverseCumulativeProbability(final double p, int lower, int upper)

This is a utility function used by inverseCumulativeProbability(double). It assumes 0 < p < 1 and that the inverse cumulative probability lies in the bracket (lower, upper]. The implementation does simple bisection to find the smallest p-quantile inf{x in Z | P(X<=x) >= p}.

Parameters
p:double

the cumulative probability

lower:int

a value satisfying cumulativeProbability(lower) < p

upper:int

a value satisfying p <= cumulativeProbability(upper)

Returns:int

the smallest p-quantile of this distribution