nifty.re.num.stats_distributions module#

interpolator(func: Callable, xmin: float, xmax: float, *, step: float | None = None, num: int | None = None, table_func: Callable | None = None, inv_table_func: Callable | None = None, return_inverse: bool | None = False)[source]#

Evaluate a function point-wise by interpolation. Can be supplied with a table_func to increase the interpolation accuracy, Best results are achieved when lambda x: table_func(func(x)) is roughly linear.

Parameters:
  • func (function) – Function to interpolate.

  • xmin (float) – The smallest value for which func will be evaluated.

  • xmax (float) – The largest value for which func will be evaluated.

  • step (float) – Distance between sampling points for linear interpolation. Either of step or num must be specified.

  • num (int) – The number of interpolation points. Either of step of num must be specified.

  • table_func (function) – Non-linear function applied to the tabulated function in order to transform the table to a more linear space.

  • inv_table_func (function) – Inverse of table_func.

  • return_inverse (bool) – Whether to also return the interpolation of the inverse of func. Only sensible if func is invertible.

invgamma_invprior(a, scale, loc=0.0, step=0.01) → Callable[source]#

Get the inverse transformation to invgamma_prior.

invgamma_prior(a, scale, loc=0.0, step=0.01) → Callable[source]#

Transform a standard normal into an inverse gamma distribution.

The pdf of the inverse gamma distribution is defined as follows using \(q\) to denote the scale:

\[P(x|q, a) = \frac{q^a}{\Gamma(a)}x^{-a -1} \exp \left(-\frac{q}{x}\right)\]

That means that for large x the pdf falls off like \(x^{(-a -1)}\). The mean of the pdf is at \(q / (a - 1)\) if \(a > 1\). The mode is \(q / (a + 1)\).

This transformation is implemented as a linear interpolation which maps a Gaussian onto an inverse gamma distribution.

Parameters:
  • a (float) – The shape-parameter of the inverse-gamma distribution.

  • scale (float) – The scale-parameter of the inverse-gamma distribution.

  • loc (float) – An option shift of the whole distribution.

  • step (float) – Distance between sampling points for linear interpolation.

laplace_prior(alpha) → Partial[source]#

Takes random normal samples and outputs samples distributed according to

\[P(x|a) = exp(-|x|/a)/a/2\]
lognormal_invprior(mean, std, *, _log_mean=None, _log_std=None) → Partial[source]#

Get the inverse transform to lognormal_prior.

lognormal_moments(mean, std)[source]#

Compute the cumulants a log-normal process would need to comply with the provided mean and standard-deviation std

lognormal_prior(mean, std, *, _log_mean=None, _log_std=None) → Partial[source]#

Moment-match standard normally distributed random variables to log-space

Takes random normal samples and outputs samples distributed according to

\[P(xi|mu,sigma) \propto exp(mu + sigma * xi)\]

such that the mean and standard deviation of the distribution matches the specified values.

normal_invprior(mean, std) → Partial[source]#

Get the inverse transform to normal_prior.

normal_prior(mean, std) → Partial[source]#

Match standard normally distributed random variables to non-standard variables.

uniform_prior(a_min=0.0, a_max=1.0) → Partial[source]#

Transform a standard normal into a uniform distribution.

Parameters:
  • a_min (float) – Minimum value.

  • a_max (float) – Maximum value.