Class AbstractIntegerDistribution

All Implemented Interfaces:
Serializable, IntegerDistribution
Direct Known Subclasses:
BinomialDistribution, EnumeratedIntegerDistribution, GeometricDistribution, HypergeometricDistribution, PascalDistribution, PoissonDistribution, UniformIntegerDistribution, ZipfDistribution

public abstract class AbstractIntegerDistribution extends Object implements IntegerDistribution, 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:
  • Constructor Details

    • AbstractIntegerDistribution

      public AbstractIntegerDistribution()
      Empty constructor.

      This constructor is not strictly necessary, but it prevents spurious javadoc warnings with JDK 18 and later.

  • Method Details

    • probability

      public double probability(int x0, int x1) throws MathIllegalArgumentException
      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)

      Specified by:
      probability in interface IntegerDistribution
      x0 - the exclusive lower bound
      x1 - the inclusive upper bound
      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
      MathIllegalArgumentException - if x0 > x1
    • inverseCumulativeProbability

      public int inverseCumulativeProbability(double p) throws MathIllegalArgumentException
      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
      Specified by:
      inverseCumulativeProbability in interface IntegerDistribution
      p - the cumulative probability
      the smallest p-quantile of this distribution (largest 0-quantile for p = 0)
      MathIllegalArgumentException - if p < 0 or p > 1
    • solveInverseCumulativeProbability

      protected int solveInverseCumulativeProbability(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}.
      p - the cumulative probability
      lower - a value satisfying cumulativeProbability(lower) < p
      upper - a value satisfying p <= cumulativeProbability(upper)
      the smallest p-quantile of this distribution
    • logProbability

      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 IntegerDistribution.probability(int).

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

      Specified by:
      logProbability in interface IntegerDistribution
      x - the point at which the PMF is evaluated
      the logarithm of the value of the probability mass function at x