GeometricDistribution

Represents the geometric distribution, which models the number of failures before the first success in a series of independent Bernoulli trials.

This distribution uses the 0-indexed convention: k = 0 means success occurred on the very first trial (zero failures), k = 1 means one failure before the first success, and so on. The support is {0, 1, 2, ...} (all non-negative integers).

The geometric distribution is memoryless -- the probability of needing at least m more failures is the same regardless of how many failures have already occurred. It is also a special case of the negative binomial distribution with successes = 1.

Common applications include modeling the number of defective items inspected before finding a good one, the number of unsuccessful sales calls before a sale, or the number of coin flips before landing heads.

Example:

val dist = GeometricDistribution(probability = 0.3)
dist.pmf(0) // 0.3 (success on first trial)
dist.pmf(2) // 0.147 (two failures, then success)
dist.cdf(3) // 0.7599 (at most 3 failures)
dist.mean // 2.3333 (expected number of failures)
dist.quantileInt(0.5) // 2 (median number of failures)
dist.sample(Random(42)) // a single random draw

Constructors

Link copied to clipboard
constructor(probability: Double)

Properties

Link copied to clipboard
open override val entropy: Double

The Shannon entropy of this distribution in nats. Returns zero when probability is 1.0 (degenerate case).

Link copied to clipboard
open override val kurtosis: Double

The excess kurtosis of this distribution.

Link copied to clipboard
open override val mean: Double

The mean (expected number of failures before the first success).

Link copied to clipboard

the probability of success on each trial. Must be in (0, 1].

Link copied to clipboard
open override val skewness: Double

The skewness of this distribution.

Link copied to clipboard
open override val variance: Double

The variance of the number of failures before the first success.

Functions

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

Returns the cumulative distribution function value at k.

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

Returns the natural logarithm of the probability mass at k.

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

Returns the probability mass at k, the probability of exactly k failures before the first success.

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

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

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

Draws a single random value from this geometric distribution using inverse transform sampling.

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

Returns the survival function value at k.