DiscreteDistribution

Common interface for discrete probability distributions.

A discrete distribution assigns probabilities to individual integer outcomes via a probability mass function (PMF). Implementations provide methods to evaluate the mass, log-mass, cumulative probability, quantiles, and random sampling.

Extends Distribution, which provides shared statistical properties such as mean, variance, standardDeviation, and the sf survival function. The cdf and sf methods are available in both Int and Double overloads — the Double variants delegate to the Int versions via truncation.

Example:

val dist: DiscreteDistribution = BinomialDistribution(trials = 10, probability = 0.3)
dist.pmf(3) // 0.2668... (probability of exactly 3 successes)
dist.logPmf(3) // -1.3218... (log of the mass)
dist.cdf(3) // 0.6496... (probability of 3 or fewer successes)
dist.quantileInt(0.5) // 3 (median as Int)
dist.quantile(0.5) // 3.0 (median as Double, for Distribution compatibility)
dist.sample(Random(42)) // a single random draw
dist.sample(5, Random(42)) // five random draws

See also

for inherited statistical properties and survival function.

for the continuous counterpart.

Inheritors

Properties

Link copied to clipboard
open override val entropy: Double

Returns the Shannon entropy of this distribution in nats (natural logarithm units).

Link copied to clipboard
open override val kurtosis: Double

Returns the excess kurtosis (Fisher definition) of this distribution.

Link copied to clipboard
open override val skewness: Double

Returns the skewness of this distribution.

Functions

Link copied to clipboard
open override fun cdf(x: Double): Double

Returns the CDF value at x, bridging to the integer cdf overload.

abstract fun cdf(k: Int): Double

Returns the cumulative distribution function (CDF) value at integer k.

Link copied to clipboard
abstract fun logPmf(k: Int): Double

Returns the natural logarithm of the probability mass at k.

Link copied to clipboard
abstract fun pmf(k: Int): Double

Returns the probability mass at k.

Link copied to clipboard
open override fun quantile(p: Double): Double

Returns the quantile (inverse CDF) for the given probability p as a Double.

Link copied to clipboard
abstract fun quantileInt(p: Double): Int

Returns the quantile (inverse CDF) for the given probability p as an Int.

Link copied to clipboard
abstract fun sample(random: Random): Int

Draws a single random integer value from this distribution.

open fun sample(n: Int, random: Random): IntArray

Draws n independent random integer values from this distribution.

Link copied to clipboard
open override fun sf(x: Double): Double

Returns the SF value at x, bridging to the integer sf overload.

open fun sf(k: Int): Double

Returns the survival function value at integer k.