algorithm for calculating CDF (default: BinomialAlgo.direct)
algorithm for poisson approximation (default: PoissonAlgo.gamma)
import mir.math.common: approxEqual, pow; assert(4.binomialCDF(6, 2.0 / 3).approxEqual(binomialPMF(0, 6, 2.0 / 3) + binomialPMF(1, 6, 2.0 / 3) + binomialPMF(2, 6, 2.0 / 3) + binomialPMF(3, 6, 2.0 / 3) + binomialPMF(4, 6, 2.0 / 3))); // For large values of `n` with `p` not too extreme, can approximate with normal distribution assert(550_000.binomialCDF!"approxNormal"(1_000_000, 0.55).approxEqual(0.5)); // Or closer with continuity correction assert(550_000.binomialCDF!"approxNormalContinuityCorrection"(1_000_000, 0.55).approxEqual(0.500401)); // Poisson approximation is better when `p` is low assert(10_000.binomialCDF!"approxPoisson"(1_000_000, 0.01).approxEqual(0.5026596));
Computes the binomial cumulative distribution function (CDF).
Additional algorithms may be provided for calculating CDF that allow trading off time and accuracy. If approxPoisson is provided, the default is PoissonAlgo.gamma