Boost: Geometric distribution#
The following functions return the pmf, cdf, qtf or boost class of the geometric distribution with parameter \(p, 0 \le p \le 1\) (\(p\) is the probability that any one trial will be successful, it is also known as “success fraction”). The function returns the probability of obtaining exactly \(k\) failures from \(k\) trials with success fraction \(p\). For this implementation, the set of trials includes zero (unlike another definition where the set of trials starts at one, sometimes named shifted), so the support interval for \(k\) is \((0, \infty)\), and \(0 \le q \le 1\).
See also Wikipedia [1268], MathWorld [894], BoostMath [82] .
- Ctx.geometric_pmf(k, p)#
where
CtxisMath53orCtxBoost.Returns \(\text{pmf}(x)\), the value of the probability mass function (Pmf) of the geometric distribution:
\[\text{pmf}_X(k) = p (1-p)^k = p \cdot \exp\left(k \text{log1p}(-p)\right).\]The following example shows both forms of the syntax:
>>> from mpfebnet import * >>> a = 0; b = 1; t = 0.3; x = 0.6; >>> print ("GeometricPdf(x, a, b): ", GeometricPdf(x, a, b)) >>> print ("dist_geometric(a, b).pdf(x): ", dist_geometric(a, b).pdf(x)) 6.3563523462564525615615615614561356E+00
- Ctx.geometric_cdf(k, p)#
where
CtxisMath53orCtxBoost.Returns \(\text{cdf}(x)\), the value of the cumulative distribution function (Cdf) of the geometric distribution. The cumulative distribution function returns the probability of obtaining \(k\) failures or fewer from \(k\) trials with success fraction \(p\) and success on the last trial.
\[\text{cdf}(x) = 1 - (1-p)^{k+1} = -\text{expm1}\left(\text{log1p}(-p) (k+1)\right).\]The following example shows both forms of the syntax:
>>> from mpfebnet import * >>> a = 0; b = 1; t = 0.3; x = 0.6; >>> print ("GeometricCdf(x, a, b): ", GeometricCdf(x, a, b)) >>> print ("dist_geometric(a, b).cdf(x): ", dist_geometric(a, b).cdf(x)) 6.3563523462564525615615615614561356E+00
- Ctx.geometric_qtf(q, p)#
where
CtxisMath53orCtxBoost.Returns \(\text{qtf}(q)\), the value of the quantile function (Qtf) of the geometric distribution. The quantile function returns the greatest number of failures \(k\) expected to be observed from \(k\) trials with success fraction \(p\), at probability \(q\). Note that the value returned is a real-number, and not an integer. Depending on the use case you may want to take either the floor or ceiling of the real result.
\[\text{qtf}(q) = \frac{\text{log1p}(-q)}{\text{log1p}(-p)} -1.\]The following example shows both forms of the syntax:
>>> from mpfebnet import * >>> a = 0; b = 1; t = 0.3; q = 0.6; >>> print ("GeometricQtf(q, a, b): ", GeometricQtf(q, a, b)) >>> print ("dist_geometric(a, b).qtf(q): ", dist_geometric(a, b).qtf(q)) 6.3563523462564525615615615614561356E+00
- class ctx.dist_geometric(p)#
where
ctxisfpm,mpm,ipm,dec,gmporapm.The geometric distribution is a (discrete or continuous) probability distribution with parameter \(p, 0 \le p \le 1\) (\(p\) is the probability that any one trial will be successful, it is also known as “success fraction”). The function returns the probability of obtaining exactly \(k\) failures from \(k\) trials with success fraction \(p\). For this implementation, the set of trials includes zero (unlike another definition where the set of trials starts at one, sometimes named shifted), so the support interval for \(k\) is \((0, \infty)\). See also Wikipedia [1268], MathWorld [894], BoostMath [82] , and Witkovský [1637], R (Statistical System) [557].
- dist_geometric.pmf(x)#
Returns \(\text{pmf}_X(x)\), the probability mass function (pmf) of a random variable \(X\), following an geometric distribution:
\[\text{pmf}_X(k) = p (1-p)^k = p \cdot \exp\left(k \text{log1p}(-p)\right)\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; x = 3; >>> print ("pmf: ", geometric(mu, sigma).pmf(x)) 6.3563523462564525615615615614561356E-20
- dist_geometric.cdf(x)#
Returns \(\text{cdf}_X(x)\), the cumulative distribution function (cdf) of a random variable \(X\), following an geometric distribution:
\[\text{cdf}_X(x) = 1 - (1-p)^{k+1} = -\text{expm1}\left(\text{log1p}(-p) (k+1)\right)\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; x = 3; >>> print ("cdf: ", geometric(mu, sigma).pmf(x)) 6.3563523462564525615615615614561356E-20
- dist_geometric.sf(x)#
Returns \(\text{sf}_X(x)\), the survival function (sf) of a random variable \(X\), following an geometric distribution:
\[\text{sf}_X(x) = (1-p)^{k+1} = \exp\left(\text{log1p}(-p) (k+1)\right)\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; x = 3; >>> print (" sf: ", geometric(mu, sigma).pmf(x)) sf: 6.3563523462564525615615615614561356E-20
- dist_geometric.qtf(q)#
Returns \(\text{qtf}_X(x)\), the quantile function (qtf) of a random variable \(X\), following an geometric distribution:
\[\text{qtf}_X(q) = \frac{\text{log1p}(-q)}{\text{log1p}(-p)} -1\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; q = 0.3; >>> print ("qtf: ", geometric(mu, sigma).qtf(q)) qtf: 6.3563523462564525615615615614561356E+00
- dist_geometric.isf(q)#
Returns \(\text{isf}_X(q)\), the inverse survival function (isf) of a random variable \(X\), following an geometric distribution:
\[\text{isf}_X(q) = \frac{\log(q)}{\text{log1p}(-p)} -1\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; q = 0.3; >>> print ("isf: ", geometric(mu, sigma).isf(q)) 6.3563523462564525615615615614561356E+00
- dist_geometric.c_x(t)#
Returns \(C_X(t)\), the characteristic function of a random variable \(X\), following an geometric distribution:
\[C_X(t) = ??.\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", geometric(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_geometric.m_x(t)#
Returns \(M_X(t)\), the moment generating function of a random variable \(X\), following an geometric distribution:
\[M_X(t) = ??.\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("m_x: ", geometric(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_geometric.k_x(t, k=0)#
Returns \(K_X(t)\), the cumulant generating function of a random variable \(X\), following an geometric distribution:
\[K_X(t) = ??.\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; k = 6; >>> print ("c_x: ", geometric(mu, sigma).k_x(t, k)) 6.3563523462564525615615615614561356E+00
- dist_geometric.moments(k)#
Returns the first \(j\) central moments, \(\mu_j, j = 1 \ldots k\), of a random variable \(X\), following an geometric distribution (Wikipedia). The raw moments are calculated from the central moments.
\[\mu_{X}(n) = ??\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; k = 6; >>> print ("saddlepoint: ", geometric(mu, sigma).moments(k)) 6.3563523462564525615615615614561356E+00
- dist_geometric.cumulants(k)#
Returns the first \(j\) cumulants, \(\kappa_j, j = 1 \ldots k\), of a random variable \(X\), following an geometric distribution. The cumulants are calculated from the moments.
>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; k = 6; >>> print ("saddlepoint: ", geometric(mu, sigma).cumulants(k)) 6.3563523462564525615615615614561356E+00
The geometric distribution is used when there are exactly two mutually exclusive outcomes of a Bernoulli trial: these outcomes are labelled “success” and “failure”. For Bernoulli trials each with success fraction \(p\), the geometric distribution gives the probability of observing \(k\) trials (failures, events, occurrences, or arrivals) before the first success.
The pmf of a variable following a geometric distribution with parameter \(p\) is given by
The CDF of a variable following a geometric distribution with parameter \(p\) is given by
The ICDF of a variable following a geometric distribution with parameter \(p\) is given by