Boost: Bernoulli distribution#
The following functions return the pmf, cdf, qtf or boost class of the Bernoulli distribution
The Bernoulli distribution is a discrete distribution of the outcome of a single trial with only two results, 0 (failure) or 1 (success), with a probability of success p.
The Bernoulli distribution is the simplest building block on which other discrete distributions of sequences of independent Bernoulli trials can be based.
The Bernoulli is the binomial distribution (k = 1, p) with only one trial.
The domain of the random variable is 0 and 1, and the useful supported range is only 0 or 1.
The support interval for \(k\) is \({0, 1}\), and \(0 \le q \le 1\).
The Bernoulli distribution is implemented here as a strict discrete distribution. If a generalised version, allowing k to be any real, is required then the binomial distribution with a single trial should be used, for example:
binomial_distribution(1, 0.25)
!!! The following references need to be updated: !!!
See also Wikipedia [1268], MathWorld [894], BoostMath [82] .
- Ctx.bernoulli_pmf(k, p)#
where
CtxisMath53orCtxBoost.Returns \(\text{pmf}(x)\), the value of the probability mass function (Pmf) of the Bernoulli distribution. It is calculated using the relation \(\text{pmf}(k) = 1 - p\) for \(k = 0\), else \(p\).
The following example shows both forms of the syntax:
>>> from mpfebnet import * >>> a = 0; b = 1; t = 0.3; x = 0.6; >>> print ("BernoulliPdf(x, a, b): ", BernoulliPdf(x, a, b)) >>> print ("dist_bernoulli(a, b).pdf(x): ", dist_bernoulli(a, b).pdf(x)) 6.3563523462564525615615615614561356E+00
- Ctx.bernoulli_cdf(k, p)#
where
CtxisMath53orCtxBoost.Returns \(\text{cdf}(x)\), the value of the cumulative distribution function (Cdf) of the Bernoulli distribution. It is calculated using the relation \(\text{cdf}(k) = 1 - p\) for \(k = 0\), else \(1\).
The following example shows both forms of the syntax:
>>> from mpfebnet import * >>> a = 0; b = 1; t = 0.3; x = 0.6; >>> print ("BernoulliCdf(x, a, b): ", BernoulliCdf(x, a, b)) >>> print ("dist_bernoulli(a, b).cdf(x): ", dist_bernoulli(a, b).cdf(x)) 6.3563523462564525615615615614561356E+00
- Ctx.bernoulli_qtf(q, p)#
where
CtxisMath53orCtxBoost.Returns \(\text{qtf}(q)\), the value of the quantile function (Qtf) of the Bernoulli distribution. It is calculated using the relation \(\text{qtf}(k) = 0\) for \(k \le (1-p)\), else \(1\).
The following example shows both forms of the syntax:
>>> from mpfebnet import * >>> a = 0; b = 1; t = 0.3; q = 0.6; >>> print ("BernoulliQtf(q, a, b): ", BernoulliQtf(q, a, b)) >>> print ("dist_bernoulli(a, b).qtf(q): ", dist_bernoulli(a, b).qtf(q)) 6.3563523462564525615615615614561356E+00
- CtxBoost.dist_bernoulli(p)#
Returns an
dist_bernoulliobject, which gives access to the functions descibed below:>>> from mpfebnet import SReal, FReal, XReal, QReal, CReal, OReal >>> a = 0; b = 1; >>> Ctx = SReal >>> dist_bernoulli = Ctx.dist_bernoulli(a, b) >>> print ("Dist.qtf(q=0.5): ", Dist.qtf(q=0.5)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.pmf(x)#
Returns \(\text{pdf}(x)\), the value of the probability density function of the Bernoulli distribution. See Ctx.BernoulliPmf for formulas and examples.
- dist_bernoulli.cdf(x)#
Returns \(\text{cdf}(x)\), the value of the cumulative distribution function of the Bernoulli distribution. See Ctx.BernoulliCdf for formulas and examples.
- dist_bernoulli.qtf(q)#
Returns \(\text{qtf}(q)\), the value of the quantile function of the Bernoulli distribution. See Ctx.BernoulliQtf for formulas and examples.
- dist_bernoulli.sf(x)#
Returns \(\text{sf}(x)\), the value of the survival function (Sf) of the Bernoulli distribution. It is calculated using the relation \(\text{sf}(k) = p\) for \(k = 0\), else \(0\).
>>> # continued from above >>> print ("Dist.sf(x=0.5): ", Dist.qtf(x=0.5)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.isf(q)#
Returns \(\text{isf}(q)\), the value of the inverse survival function (Isf) of the Bernoulli distribution. It is calculated using the relation \(\text{qtf}(k) = 1\) for \(k \le (1-p)\), else \(0\).
>>> # continued from above >>> print ("Dist.isf(x=0.5): ", Dist.isf(x=0.5)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.hf(x)#
Returns \(\text{hazard}(x)\), the value of the hazard function (Hf) of the Bernoulli distribution.
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.chf(x)#
Returns \(\text{chf}(x)\), the value of the cumulative hazard function (Chf) of the Bernoulli distribution.
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.mode()#
Returns the mode of the Bernoulli distribution, which is \(0\) if \((p < 0.5)\) else \(1\).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.median()#
Returns the median of the Bernoulli distribution. Calculated as \(\displaystyle tbd\).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.mean()#
Returns the mean (expected value) of the Bernoulli distribution, which is \(p\).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.variance()#
Returns the variance of the Bernoulli distribution. Calculated as \(\displaystyle p (1-p)\).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.stdev()#
Returns the standard deviation of the Bernoulli distribution. Calculated as \(\displaystyle \sqrt{p (1-p)}\).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.skewness()#
Returns the skewness of the Bernoulli distribution. Calculated as \(\displaystyle (1-2p)/\sqrt{p(1-p)}\).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.kurtosis()#
Returns the ‘proper’ kurtosis (normalized fourth moment) of the Bernoulli distribution. Calculated as \(\displaystyle 3+(1-6p(1-p))/(p(1-p))\).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.kurtosis_excess()#
Returns the kurtosis excess of the Bernoulli distribution. Calculated as \(\displaystyle (1-6p(1-p))/(p(1-p))\).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.support_lower_endpoint()#
Returns the support of the Bernoulli distribution as a tuple (left, right).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_bernoulli.support_upper_endpoint()#
Returns the support of the Bernoulli distribution as a tuple (left, right).
>>> from mpfebnet import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00