import mir.test: shouldApprox; 0.hypergeometricPMF(7, 4, 3).shouldApprox == 0.02857143; 1.hypergeometricPMF(7, 4, 3).shouldApprox == 0.3428571; 2.hypergeometricPMF(7, 4, 3).shouldApprox == 0.5142857; 3.hypergeometricPMF(7, 4, 3).shouldApprox == 0.1142857; // can also provide a template argument to change output type static assert(is(typeof(hypergeometricPMF!float(3, 7, 4, 3)) == float));
Alternate algorithms
import mir.test: shouldApprox; import mir.math.common: exp; // Can approximate hypergeometric with binomial distribution 20.hypergeometricPMF!"approxBinomial"(750_000, 250_000, 50).shouldApprox == exp(hypergeometricLPMF(20, 750_000, 250_000, 50)); // Can approximate hypergeometric with poisson distribution 20.hypergeometricPMF!"approxPoisson"(100_000, 100, 5_000).shouldApprox == exp(hypergeometricLPMF(20, 100_000, 100, 5_000)); // Can approximate hypergeometric with normal distribution 3_500.hypergeometricPMF!"approxNormal"(10_000, 7_500, 5_000).shouldApprox == exp(hypergeometricLPMF(3_500, 10_000, 7_500, 5_000)); // Can approximate hypergeometric with normal distribution (with continuity correction) 3_500.hypergeometricPMF!"approxNormalContinuityCorrection"(10_000, 7_500, 5_000).shouldApprox == exp(hypergeometricLPMF(3_500, 10_000, 7_500, 5_000));
Computes the hypergeometric probability mass function (PMF).
Additional algorithms may be provided for calculating PMF that allow trading off time and accuracy. If approxPoisson is provided, PoissonAlgo.gamma is assumed.