gwkokab.utils.mathΒΆ
FunctionsΒΆ
Let \(\alpha\) and \(\beta\) be the shape parameters of a beta |
|
Let \(\mu\) and \(\sigma^2\) be the mean and variance of a beta |
|
|
Calculate the cumulative trapezoidal integration of y with respect to x. |
|
Compute \(\log(\exp(a) - \exp(b))\) in a numerically stable way. |
|
Compute the log probability density function of a truncated normal distribution. |
Module ContentsΒΆ
- gwkokab.utils.math.beta_dist_concentrations_to_mean_variance(alpha: jaxtyping.ArrayLike, beta: jaxtyping.ArrayLike, loc: jaxtyping.ArrayLike = 0.0, scale: jaxtyping.ArrayLike = 1.0) Tuple[jaxtyping.ArrayLike, jaxtyping.ArrayLike][source]ΒΆ
Let \(\alpha\) and \(\beta\) be the shape parameters of a beta distribution, \(a\) being the location and \(b\) being the scale. This function returns the mean and variance of the distribution. Then concentrations are given by:
\[\mu = a+b\frac{\alpha}{\alpha + \beta}\qquad \sigma^2 = b^2\frac{\alpha \beta}{(\alpha + \beta)^2 (\alpha + \beta + 1)}\]- Parameters:
alpha (ArrayLike) β The shape parameter \(\alpha\).
beta (ArrayLike) β The shape parameter \(\beta\).
loc (ArrayLike) β The location \(a\) of the beta distribution.
scale (ArrayLike) β The scale \(b\) of the beta distribution.
- Returns:
The mean \(\mu\) and variance \(\sigma^2\) of the beta distribution.
- Return type:
Tuple[ArrayLike, ArrayLike]
- gwkokab.utils.math.beta_dist_mean_variance_to_concentrations(mean: jaxtyping.ArrayLike, variance: jaxtyping.ArrayLike, loc: jaxtyping.ArrayLike = 0.0, scale: jaxtyping.ArrayLike = 1.0) Tuple[jaxtyping.ArrayLike, jaxtyping.ArrayLike][source]ΒΆ
Let \(\mu\) and \(\sigma^2\) be the mean and variance of a beta distribution, \(a\) being the location and \(b\) being the scale. This function returns the shape parameters \(\alpha\) and \(\beta\) of the distribution. Then concentrations are given by:
\[\alpha = -\frac{\mu-a}{b} \left(\left(\frac{\mu-a}{\sigma}\right)\left(\frac{\mu-a-b}{\sigma}\right)+1\right)\qquad \beta = \alpha\left(\frac{b}{\mu-a}-1\right)\]- Parameters:
mean (ArrayLike) β The mean \(\mu\) of the beta distribution.
variance (ArrayLike) β The variance \(\sigma^2\) of the beta distribution.
loc (ArrayLike) β The location \(a\) of the beta distribution.
scale (ArrayLike) β The scale \(b\) of the beta distribution.
- Returns:
The shape parameters \(\alpha\) and \(\beta\) of the beta distribution.
- Return type:
Tuple[ArrayLike, ArrayLike]
- gwkokab.utils.math.cumtrapz(y: jaxtyping.Array, x: jaxtyping.Array) jaxtyping.Array[source]ΒΆ
Calculate the cumulative trapezoidal integration of y with respect to x.
- Parameters:
y (Array) β array to integrate
x (Array) β array to integrate over
- Returns:
The result of the cumulative trapezoidal integration of y with respect to x.
- Return type:
Array
- gwkokab.utils.math.logsubexp(a: jaxtyping.ArrayLike, b: jaxtyping.ArrayLike) jaxtyping.ArrayLike[source]ΒΆ
Compute \(\log(\exp(a) - \exp(b))\) in a numerically stable way.
- Parameters:
a (ArrayLike) β input array
b (ArrayLike) β input array
- Returns:
The value of \(\log(\exp(a) - \exp(b))\).
- Return type:
ArrayLike
- gwkokab.utils.math.truncnorm_logpdf(xx: jaxtyping.ArrayLike, loc: jaxtyping.ArrayLike, scale: jaxtyping.ArrayLike, low: jaxtyping.ArrayLike, high: jaxtyping.ArrayLike) jaxtyping.ArrayLike[source]ΒΆ
Compute the log probability density function of a truncated normal distribution.
- Parameters:
xx (ArrayLike) β The input array.
loc (ArrayLike) β The mean of the distribution.
scale (ArrayLike) β The standard deviation of the distribution.
low (ArrayLike) β The lower bound of the distribution.
high (ArrayLike) β The upper bound of the distribution.
- Returns:
The log probability density function of the truncated normal distribution.
- Return type:
ArrayLike