gwkokab.utils.mathΒΆ

FunctionsΒΆ

beta_dist_concentrations_to_mean_variance(...)

Let \(\alpha\) and \(\beta\) be the shape parameters of a beta

beta_dist_mean_variance_to_concentrations(...)

Let \(\mu\) and \(\sigma^2\) be the mean and variance of a beta

cumtrapz(β†’ jaxtyping.Array)

Calculate the cumulative trapezoidal integration of y with respect to x.

logsubexp(β†’ jaxtyping.ArrayLike)

Compute \(\log(\exp(a) - \exp(b))\) in a numerically stable way.

truncnorm_logpdf(β†’ jaxtyping.ArrayLike)

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