The OpenD Programming Language

binomialLPMF

Computes the binomial log probability mass function (LPMF)

T
binomialLPMF
(
T
)
(
const size_t k
,
const size_t n
,
const T p
)
if (
isFloatingPoint!T
)

Parameters

k size_t

value to evaluate LPMF (e.g. number of "heads")

n size_t

number of trials

p T

true probability

Examples

import mir.math.common: approxEqual, exp;

for (size_t i; i <= 5; i++) {
    assert(i.binomialLPMF(5, 0.5).exp.approxEqual(binomialPMF(i, 5, 0.5)));
    assert(i.binomialLPMF(5, 0.75).exp.approxEqual(binomialPMF(i, 5, 0.75)));
}

Accurate values for large values of n

import mir.bignum.fp: Fp, fp_log;
import mir.math.common: approxEqual;

assert(1.binomialLPMF(1_000_000, 0.75).approxEqual(fp_binomialPMF(1, 1_000_000, Fp!128(0.75)).fp_log!double));

See Also

Meta