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));
Computes the binomial log probability mass function (LPMF)