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.geometric

This module contains algorithms for the Geometric Distribution.
License:
Authors:
John Michael Hall
pure nothrow @nogc @safe T geometricPMF(T)(const size_t k, const T p)
if (isFloatingPoint!T);
Computes the geometric probability density function (PMF).
Parameters:
size_t k value to evaluate PMF
T p true probability
Examples:
import mir.test: shouldApprox;

0.geometricPMF(0.5).shouldApprox == 0.5;
1.geometricPMF(0.5).shouldApprox == 0.25;
2.geometricPMF(0.25).shouldApprox == 0.140625;
pure nothrow @nogc @safe T geometricCDF(T)(const size_t k, const T p)
if (isFloatingPoint!T);

pure nothrow @nogc @safe T geometricCDF(T)(const T x, const T p)
if (isFloatingPoint!T);
Computes the geometric cumulative density function (CDF).
Parameters:
size_t k value to evaluate CDF
T p true probability
Examples:
import mir.test: shouldApprox;

geometricCDF(-1.0, 0.5).shouldApprox == 0; // UFCS chaining deduces this as size_t instead of a floating point type
0.geometricCDF(0.5).shouldApprox == 0.5;
1.geometricCDF(0.5).shouldApprox == 0.75;
2.geometricCDF(0.5).shouldApprox == 0.875;

geometricCDF(-1.0, 0.25).shouldApprox == 0; // UFCS chaining deduces this as size_t instead of a floating point type
0.geometricCDF(0.25).shouldApprox == 0.25;
1.geometricCDF(0.25).shouldApprox == 0.4375;
2.geometricCDF(0.25).shouldApprox == 0.578125;
2.5.geometricCDF(0.25).shouldApprox == 0.578125;
pure nothrow @nogc @safe T geometricCCDF(T)(const size_t k, const T p)
if (isFloatingPoint!T);

pure nothrow @nogc @safe T geometricCCDF(T)(const T x, const T p)
if (isFloatingPoint!T);
Computes the geometric complementary cumulative density function (CCDF).
Parameters:
size_t k value to evaluate CCDF
T p true probability
Examples:
import mir.test: shouldApprox;

geometricCCDF(-1.0, 0.5).shouldApprox == 1.0; // UFCS chaining deduces this as size_t instead of a floating point type
0.geometricCCDF(0.5).shouldApprox == 0.5;
1.geometricCCDF(0.5).shouldApprox == 0.25;
2.geometricCCDF(0.5).shouldApprox == 0.125;

geometricCCDF(-1.0, 0.25).shouldApprox == 1.0; // UFCS chaining deduces this as size_t instead of a floating point type
0.geometricCCDF(0.25).shouldApprox == 0.75;
1.geometricCCDF(0.25).shouldApprox == 0.5625;
2.geometricCCDF(0.25).shouldApprox == 0.421875;
2.5.geometricCCDF(0.25).shouldApprox == 0.421875;
pure nothrow @nogc @safe T geometricInvCDF(T)(const T q, const T p)
if (isFloatingPoint!T);
Computes the geometric inverse cumulative distribution function (InvCDF).
Parameters:
T q value to evaluate InvCDF
T p true probability
Examples:
import mir.test: should;

0.geometricInvCDF(0.5).should == -1;
0.5.geometricInvCDF(0.5).should == 0;
0.75.geometricInvCDF(0.5).should == 1;
0.875.geometricInvCDF(0.5).should == 2;
0.95.geometricInvCDF(0.5).should == 4;

0.geometricInvCDF(0.25).should == -1;
0.25.geometricInvCDF(0.25).should == 0;
0.4375.geometricInvCDF(0.25).should == 1;
0.578125.geometricInvCDF(0.25).should == 2;
0.95.geometricInvCDF(0.25).should == 10;

0.5.geometricInvCDF(1).should == 0;
1.geometricInvCDF(0.5).should == double.infinity;
pure nothrow @nogc @safe T geometricLPMF(T)(const size_t k, const T p)
if (isFloatingPoint!T);
Computes the geometric log probability density function (LPMF).
Parameters:
size_t k value to evaluate LPMF
T p true probability
Examples:
import mir.math.common: exp;
import mir.test: shouldApprox;

0.geometricLPMF(0.5).exp.shouldApprox == 0.geometricPMF(0.5);
1.geometricLPMF(0.5).exp.shouldApprox == 1.geometricPMF(0.5);
2.geometricLPMF(0.25).exp.shouldApprox == 2.geometricPMF(0.25);