BernoulliDistribution

Represents the Bernoulli distribution, the simplest discrete probability distribution.

The Bernoulli distribution models a single trial with exactly two outcomes: success (1) with probability probability, or failure (0) with the complementary probability. It is the building block for many other discrete distributions -- a coin flip is the classic example, and a sequence of independent Bernoulli trials gives rise to the binomial distribution. In fact, the Bernoulli distribution is a special case of the binomial with trials = 1.

The support of this distribution is {0, 1}. The PMF returns probability at k = 1 and 1 - probability at k = 0, and zero for any other value.

Example:

val coin = BernoulliDistribution(probability = 0.6)
coin.pmf(1) // 0.6 (probability of success)
coin.pmf(0) // 0.4 (probability of failure)
coin.cdf(0) // 0.4 (probability of 0 or fewer)
coin.mean // 0.6
coin.variance // 0.24
coin.quantileInt(0.5) // 1 (median)
coin.sample(Random(42)) // 0 or 1

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 for degenerate cases where probability is 0 or 1.

Link copied to clipboard
open override val kurtosis: Double

The excess kurtosis of this distribution. Returns Double.NaN when probability is 0 or 1.

Link copied to clipboard
open override val mean: Double

The mean of this distribution, equal to probability.

Link copied to clipboard

the probability of success (outcome = 1). Must be in [0, 1].

Link copied to clipboard
open override val skewness: Double

The skewness of this distribution. Returns Double.NaN when probability is 0 or 1.

Link copied to clipboard
open override val variance: Double

The variance of this distribution, equal to probability * (1 - probability).

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.

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 Bernoulli distribution.