2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Add formulas for logcdf and logpdf to the tables

This commit is contained in:
Matt Borland
2024-08-13 10:01:08 -04:00
parent d892e03070
commit 65096bee14
14 changed files with 26 additions and 2 deletions

View File

@@ -74,7 +74,9 @@ In the following table [lambda] is the parameter lambda of the distribution,
[table
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = [lambda] * exp(-[lambda] * x) ]]
[[logpdf][log(pdf) = -expm1(-x * [lambda]) ]]
[[cdf][Using the relation: p = 1 - exp(-x * [lambda]) = -expm1(-x * [lambda]) ]]
[[logcdf][log(cdf) = log1p(-exp(-x * [lambda])) ]]
[[cdf complement][Using the relation: q = exp(-x * [lambda]) ]]
[[quantile][Using the relation: x = -log(1-p) / [lambda] = -log1p(-p) / [lambda]]]
[[quantile from the complement][Using the relation: x = -log(q) / [lambda]]]

View File

@@ -99,7 +99,9 @@ In the following table:
[table
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = exp((a-x)/b) * exp(-exp((a-x)/b)) / b ]]
[[logpdf][log(pdf) = log(1/b) + e - exp(e) ]]
[[cdf][Using the relation: p = exp(-exp((a-x)/b)) ]]
[[logcdf][log(cdf) = -exp((a-x)/b) ]]
[[cdf complement][Using the relation: q = -expm1(-exp((a-x)/b)) ]]
[[quantile][Using the relation: a - log(-log(p)) * b]]
[[quantile from the complement][Using the relation: a - log(-log1p(-q)) * b]]

View File

@@ -118,6 +118,7 @@ and /q = 1-p/.
[table
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = __gamma_p_derivative(k, x / [theta]) / [theta] ]]
[[logpdf][log(pdf) = -k*log([theta]) + (k-1)*log(x) - lgamma(k) - (x/[theta]) ]]
[[cdf][Using the relation: p = __gamma_p(k, x / [theta]) ]]
[[cdf complement][Using the relation: q = __gamma_q(k, x / [theta]) ]]
[[quantile][Using the relation: x = [theta] * __gamma_p_inv(k, p) ]]

View File

@@ -325,6 +325,7 @@ the expected number of failures using the quantile.
[[Function][Implementation Notes]]
[[pdf][pdf = p * pow(q, k)]]
[[cdf][cdf = 1 - q[super k=1]]]
[[logcdf][log(cdf) = log1p(-exp(log1p(-p) * (k+1)))]]
[[cdf complement][exp(log1p(-p) * (k+1))]]
[[quantile][k = log1p(-x) / log1p(-p) -1]]
[[quantile from the complement][k = log(x) / log1p(-p) -1]]

View File

@@ -102,12 +102,13 @@ But in general, inverse_gamma results are accurate to a few epsilon,
[h4 Implementation]
In the following table [alpha] is the shape parameter of the distribution,
[alpha] is its scale parameter, /x/ is the random variate, /p/ is the probability
[beta] is its scale parameter, /x/ is the random variate, /p/ is the probability
and /q = 1-p/.
[table
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = __gamma_p_derivative([alpha], [beta]/ x, [beta]) / x * x ]]
[[logpdf][log(pdf) = [alpha] * log([beta]) + (-[alpha]-1)*log(x) - lgamma([alpha]) - ([beta]/x) ]]
[[cdf][Using the relation: p = __gamma_q([alpha], [beta] / x) ]]
[[cdf complement][Using the relation: q = __gamma_p([alpha], [beta] / x) ]]
[[quantile][Using the relation: x = [beta]/ __gamma_q_inv([alpha], p) ]]

View File

@@ -137,6 +137,7 @@ are used for the inverse gaussian function.
[table
[[Function] [Implementation Notes] ]
[[pdf] [ [sqrt]([lambda]/ 2[pi]x[super 3]) e[super -[lambda](x - [mu])[sup2]/ 2[mu][sup2]x]]]
[[logpdf] [log(pdf) = (-[lambda]*pow([mu]-x, 2)/(x*[mu][super 2]) + log([lambda]) - 3*log(x) - log(2*[pi])) / 2 ]]
[[cdf][ [Phi]{[sqrt]([lambda]/x) (x/[mu]-1)} + e[super 2[mu]/[lambda]] [Phi]{-[sqrt]([lambda]/[mu]) (1+x/[mu])} ]]
[[cdf complement] [using complement of [Phi] above.] ]
[[quantile][No closed form known. Estimated using a guess refined by Newton-Raphson iteration.]]

View File

@@ -93,11 +93,19 @@ and its complement /q = 1-p/.
[table
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = e[super -abs(x-[mu]) \/ [sigma]] \/ (2 * [sigma]) ]]
[[logpdf][log(pdf) = -abs(x-[mu])/[sigma] - log([sigma]) - log(2) ]]
[[cdf][Using the relations:
x < [mu] : p = e[super (x-[mu])/[sigma] ] \/ [sigma]
x >= [mu] : p = 1 - e[super ([mu]-x)/[sigma] ] \/ [sigma]
]]
[[logcdf][log(cdf) =
x < [mu] : p = ((x - [mu]) / [sigma]) - ln(2)
x >= [mu] : p = log1p(-exp(([mu]-x) / [sigma]) / 2)
]]
[[cdf complement][Using the relation:

View File

@@ -85,6 +85,7 @@ in such cases, only a low /absolute error/ can be guaranteed.
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = e[super -(x-u)/s] / (s*(1+e[super -(x-u)/s])[super 2])]]
[[cdf][Using the relation: p = 1/(1+e[super -(x-u)/s])]]
[[logcdf][log(cdf) = -log1p(exp((u-x)/s)) ]]
[[cdf complement][Using the relation: q = 1/(1+e[super (x-u)/s])]]
[[quantile][Using the relation: x = u - s*log(1/p-1)]]
[[quantile from the complement][Using the relation: x = u + s*log(p/1-p)]]

View File

@@ -97,6 +97,7 @@ and /s/ is its standard deviation.
[table
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = e[super -(x-m)[super 2]\/(2s[super 2])] \/ (s * sqrt(2*pi)) ]]
[[logpdf][log(pdf) = -log(s) - log(2*[pi])/2 - (x-mean)[super 2]/(2*s[super 2]) ]]
[[cdf][Using the relation: p = 0.5 * __erfc(-(x-m)/(s*sqrt(2))) ]]
[[cdf complement][Using the relation: q = 0.5 * __erfc((x-m)/(s*sqrt(2))) ]]
[[quantile][Using the relation: x = m - s * sqrt(2) * __erfc_inv(2*p)]]

View File

@@ -94,6 +94,7 @@ and its complement /q = 1-p/.
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf p = [alpha][beta][super [alpha]]/x[super [alpha] +1] ]]
[[cdf][Using the relation: cdf p = 1 - ([beta] / x)[super [alpha]] ]]
[[logcdf][log(cdf) = log1p(-pow([beta]/x, [alpha])) ]]
[[cdf complement][Using the relation: q = 1 - p = -([beta] / x)[super [alpha]] ]]
[[quantile][Using the relation: x = [beta] / (1 - p)[super 1/[alpha]] ]]
[[quantile from the complement][Using the relation: x = [beta] / (q)[super 1/[alpha]] ]]

View File

@@ -84,6 +84,7 @@ In the following table [lambda] is the mean of the distribution,
[table
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = e[super -[lambda]] [lambda][super k] \/ k! ]]
[[logpdf][log(pdf) = -lgamma(k+1) + k*log([lambda]) - [lambda] if k > 0 and [lambda] > 0 ]]
[[cdf][Using the relation: p = [Gamma](k+1, [lambda]) \/ k! = __gamma_q(k+1, [lambda])]]
[[cdf complement][Using the relation: q = __gamma_p(k+1, [lambda]) ]]
[[quantile][Using the relation: k = __gamma_q_inva([lambda], p) - 1]]

View File

@@ -95,7 +95,9 @@ In the following table [sigma] is the sigma parameter of the distribution,
[table
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = x * exp(-x[super 2])/2 [sigma][super 2] ]]
[[logpdf][log(pdf) = -(x[super 2])/(2*[sigma][super 2]) - 2*log([sigma]) + log(x) ]]
[[cdf][Using the relation: p = 1 - exp(-x[super 2]/2) [sigma][super 2]= -__expm1(-x[super 2]/2) [sigma][super 2]]]
[[logcdf][log(cdf) = log1p(-exp(-x[super 2] / (2*[sigma][super 2]))) ]]
[[cdf complement][Using the relation: q = exp(-x[super 2]/ 2) * [sigma][super 2] ]]
[[quantile][Using the relation: x = sqrt(-2 * [sigma] [super 2]) * log(1 - p)) = sqrt(-2 * [sigma] [super 2]) * __log1p(-p))]]
[[quantile from the complement][Using the relation: x = sqrt(-2 * [sigma] [super 2]) * log(q)) ]]

View File

@@ -107,7 +107,9 @@ and /q = 1-p/.
[table
[[Function][Implementation Notes]]
[[pdf][Using the relation: pdf = [alpha][beta][super -[alpha] ]x[super [alpha] - 1] e[super -(x/beta)[super alpha]] ]]
[[logpdf][log(pdf) = log([alpha]) - [alpha] * log([beta]) + log(x) * ([alpha]-1) - pow(x/[beta], [alpha]) ]]
[[cdf][Using the relation: p = -__expm1(-(x\/[beta])[super [alpha]]) ]]
[[logcdf][log(cdf) = log1p(-exp(-pow(x / [beta], [alpha]))) ]]
[[cdf complement][Using the relation: q = e[super -(x\/[beta])[super [alpha]]] ]]
[[quantile][Using the relation: x = [beta] * (-__log1p(-p))[super 1\/[alpha]] ]]
[[quantile from the complement][Using the relation: x = [beta] * (-log(q))[super 1\/[alpha]] ]]

View File

@@ -182,7 +182,7 @@ BOOST_MATH_GPU_ENABLED inline RealType logpdf(const laplace_distribution<RealTyp
const RealType mu = dist.scale();
const RealType b = dist.location();
// if b is 0 avoid divde by 0 error
// if b is 0 avoid divide by 0 error
if(abs(b) < boost::math::numeric_limits<RealType>::epsilon())
{
result = log(pdf(dist, x));