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 1Properties
The Shannon entropy of this distribution in nats. Returns zero for degenerate cases where probability is 0 or 1.
The excess kurtosis of this distribution. Returns Double.NaN when probability is 0 or 1.
The mean of this distribution, equal to probability.
the probability of success (outcome = 1). Must be in [0, 1].
The skewness of this distribution. Returns Double.NaN when probability is 0 or 1.