Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.stat.distribution.bernoulli

This module contains algorithms for the Bernoulli Distribution.
License:
Authors:
John Michael Hall
pure nothrow @nogc @safe T bernoulliPMF(T)(const bool x, const T p)
if (isFloatingPoint!T);
Computes the bernoulli probability mass function (PMF).
Parameters:
bool x value to evaluate PMF
T p true probability
Examples:
import mir.math.common: approxEqual;

assert(true.bernoulliPMF(0.5) == 0.5);
assert(false.bernoulliPMF(0.5) == 0.5);

assert(true.bernoulliPMF(0.7).approxEqual(0.7));
assert(false.bernoulliPMF(0.7).approxEqual(0.3));
pure nothrow @nogc @safe T bernoulliCDF(T)(const bool x, const T p)
if (isFloatingPoint!T);
Computes the bernoulli cumulatve distribution function (CDF).
Parameters:
bool x value to evaluate CDF
T p true probability
Examples:
import mir.math.common: approxEqual;

assert(true.bernoulliCDF(0.5) == 1);
assert(false.bernoulliCDF(0.5) == 0.5);

assert(true.bernoulliCDF(0.7) == 1);
assert(false.bernoulliCDF(0.7).approxEqual(0.3));
pure nothrow @nogc @safe T bernoulliCCDF(T)(const bool x, const T p)
if (isFloatingPoint!T);
Computes the bernoulli complementary cumulative distribution function (CCDF).
Parameters:
bool x value to evaluate CCDF
T p true probability
Examples:
import mir.math.common: approxEqual;

assert(true.bernoulliCCDF(0.5) == 0);
assert(false.bernoulliCCDF(0.5) == 0.5);

assert(true.bernoulliCCDF(0.7) == 0);
assert(false.bernoulliCCDF(0.7).approxEqual(0.7));
pure nothrow @nogc @safe bool bernoulliInvCDF(T)(const T q, const T p)
if (isFloatingPoint!T);
Computes the bernoulli inverse cumulative distribution function (InvCDF).
Parameters:
T q value to evaluate InvCDF
T p true probability
Examples:
assert(0.25.bernoulliInvCDF(0.5) == false);
assert(0.5.bernoulliInvCDF(0.5) == false);
assert(0.75.bernoulliInvCDF(0.5) == true);

assert(0.3.bernoulliInvCDF(0.7) == false);
assert(0.7.bernoulliInvCDF(0.7) == false);
assert(0.9.bernoulliInvCDF(0.7) == true);
pure nothrow @nogc @safe T bernoulliLPMF(T)(const bool x, const T p)
if (isFloatingPoint!T);
Computes the bernoulli log probability mass function (LPMF).
Parameters:
bool x value to evaluate LPDF
T p true probability
Examples:
import mir.math.common: approxEqual, log;

assert(true.bernoulliLPMF(0.5).approxEqual(log(bernoulliPMF(true, 0.5))));
assert(false.bernoulliLPMF(0.5).approxEqual(log(bernoulliPMF(false, 0.5))));

assert(true.bernoulliLPMF(0.7).approxEqual(log(bernoulliPMF(true, 0.7))));
assert(false.bernoulliLPMF(0.7).approxEqual(log(bernoulliPMF(false, 0.7))));