Priors

Prior distributions.

Probability Distribution Container

class eryn.prior.ProbDistContainer(priors_in, use_cupy=False, return_gpu=False)

Bases: object

Container for holding and generating prior info

Parameters:

priors_in (dict) – Dictionary with keys as int or tuple of int describing which parameters the prior takes. Values are probability distributions with logpdf and rvs methods.

priors_in

Dictionary with keys as int or tuple of int describing which parameters the prior takes. Values are probability distributions with logpdf and rvs methods.

Type:

dict

priors

list of indexes and their associated distributions arranged in a list.

Type:

list

ndim

Full dimensionality.

Type:

int

use_cupy

If True, use CuPy. If False use Numpy. (default: False)

Type:

bool, optional

return_gpu

If True, return CuPy array. If False, return Numpy array. (default: False)

Type:

bool, optional

Raises:

ValueError – Missing parameters or incorrect index keys.

property xp

Numpy or Cupy

logpdf(x, keys=None)

Get logpdf by summing logpdf of individual distributions

Parameters:
  • x (double np.ndarray[..., ndim]) – Input parameters to get prior values.

  • keys (list, optional) – List of keys related to which parameters to gather the logpdf for. They must exactly match the input keys for the priors_in dictionary for the __init__ function. Even when using this kwarg, must provide all ndim parameters as input. The prior will just not be calculated if its associated key is not included. Default is None.

Returns:

Prior values.

Return type:

np.ndarray[…]

ppf(x, groups=None)

Get logpdf by summing logpdf of individual distributions

Parameters:

x (double np.ndarray[..., ndim]) – Input parameters to get prior values.

Returns:

Prior values.

Return type:

np.ndarray[…]

rvs(size=1, keys=None)

Generate random values according to prior distribution

The user will have to be careful if there are prior functions that do not have an rvs method. This means that generated points may lay inside the prior of all input priors that have rvs methods, but outside the prior if priors without the rvs method are included.

Parameters:
  • size (int or tuple of ints, optional) – Output size for number of generated sources from prior distributions.

  • keys (list, optional) – List of keys related to which parameters to generate. They must exactly match the input keys for the priors_in dictionary for the __init__ function. If used, it will produce and output array of tuple(size) + (len(keys),). Default is None.

Returns:

Generated samples.

Return type:

np.ndarray[size + (self.ndim,)]

Raises:

ValueError – If size is not an int or tuple.

Available Probability Distributions

eryn.prior.uniform_dist(min, max, use_cupy=False, return_gpu=False)

Generate uniform distribution between min and max

Parameters:
  • min (double) – Minimum in the uniform distribution

  • max (double) – Maximum in the uniform distribution

  • use_cupy (bool, optional) – If True, use CuPy. If False use Numpy. (default: False)

  • return_gpu (bool, optional) – If True, return CuPy array. If False, return Numpy array. (default: False)

Returns:

Uniform distribution.

Return type:

UniformDistribution

eryn.prior.log_uniform(min, max)

Generate log-uniform distribution between min and max

Parameters:
  • min (double) – Minimum in the log-uniform distribution

  • max (double) – Maximum in the log-uniform distribution

Returns:

Log-uniform distribution built from

scipy.stats.uniform <https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.loguniform.html>_.

Return type:

scipy distribution object

class eryn.prior.MappedUniformDistribution(min, max, use_cupy=False, return_gpu=False)

Bases: object

Maps uniform distribution to zero to 1.

This is a modified uniform distribution that maps the input values to a range from zero to 1 by using min and max values input by user. This ensures the log of the prior value from this distribution is zero if the value is between min and max. and -np.inf if it is outside that range.

Parameters:
  • min (double) – Minimum in the uniform distribution

  • max (double) – Maximum in the uniform distribution

  • use_cupy (bool, optional) – If True, use CuPy. If False use Numpy. (default: False)

  • return_gpu (bool, optional) – If True, return CuPy array. If False, return Numpy array. (default: False)

Raises:

ValueError – If min is greater than max.

property xp

Numpy or Cupy

logpdf(x)

Get the log of the pdf value for this distribution.

Parameters:

x (double np.ndarray) – Input parameters to get prior values.

Returns:

Associated logpdf values of the input.

Return type:

np.ndarray

rvs(size=1)

Get the log of the pdf value for this distribution.

Parameters:

size (int or tuple of ints, optional) – Output size for number of generated sources from prior distributions.

Returns:

Generated values.

Return type:

np.ndarray