bayesbay.prior.Prior

class bayesbay.prior.Prior(**kwargs)

Base class for defining the prior probability associated with a free parameter in the inference problem

Reference Details

name
add_hyper_params(hyper_params)

Sets the attributes from the given dict and checks for errors

Parameters:

hyper_params (Dict[str, Union[Number, np.ndarray]]) – dictionary of attributes to be set

get_hyper_param(hyper_param, position=None)

Retrieves the value corresponding to the specified attribute, which may be a function of position

Parameters:
  • hyper_param (str) – the name of the attribute

  • position (Union[np.ndarray, Number], optional) – the position (in the discretization domain) associated with the value, None by default

Returns:

value corresponding to the specified attribute

Return type:

Union[Number, np.ndarray]

get_perturb_std(position=None)

get the standard deviation of the Gaussian used to perturb the parameter, which may be dependent on the position in the discretization domain

Parameters:

position (Union[Number, np.ndarray], optional) – the position in the discretization domain at which the standard deviation of the Gaussian used to perturb the parameter is returned. Default is None

Returns:

standard deviation of the Gaussian used to perturb the parameter, possibly at the specified position

Return type:

Number

get_perturb_std_birth(position=None)

get the standard deviation of the Gaussian used to perturb the parameter at birth, which may be dependent on the position in the discretization domain

Parameters:

position (Union[Number, np.ndarray], optional) – the position in the discretization domain at which the standard deviation of the Gaussian used to perturb the parameter at birth is returned. Default is None

Returns:

standard deviation of the Gaussian used to perturb the parameter at birth, possibly at the specified position

Return type:

Number

has_hyper_param(hyper_param)

Whether or not the Prior instance has the specified attribute

Parameters:

hyper_param (str) – the name of the attribute

abstractmethod initialize(positions=None)

initializes the values of this (possibly position-dependent) parameter

This is the vectorized version of the method sample().

Parameters:

positions (np.ndarray, optional) – the position (in the discretization domain) associated with the value, None by default

Returns:

an array of values or one value corresponding to the prior probability (at the given positions)

Return type:

np.ndarray

abstractmethod log_prior(value, position=None)

calculates the log of the prior probability of occurrence of the given value, which may depend on the considered position

Parameters:
  • value (Number) – the value to calculate the probability density for

  • position (Number, optional) – the position (in the discretization domain) associated with the value, None by default

Returns:

the log prior probability density

Return type:

Number

abstractmethod perturb_value(value, position=None)

perturbs the given value, in a way that may depend on the position associated with such a parameter value, and calculates the log of the corresponding partial acceptance probability

\[\begin{split}\underbrace{\alpha_{p}}_{\begin{array}{c} \text{Partial} \\ \text{acceptance} \\ \text{probability} \end{array}} = \underbrace{\frac{p\left({\bf m'}\right)}{p\left({\bf m}\right)}}_{\text{Prior ratio}} \underbrace{\frac{q\left({\bf m} \mid {\bf m'}\right)}{q\left({\bf m'} \mid {\bf m}\right)}}_{\text{Proposal ratio}} \underbrace{\lvert \mathbf{J} \rvert}_{\begin{array}{c} \text{Jacobian} \\ \text{determinant} \end{array}},\end{split}\]
Parameters:
  • value (Number) – the current value to be perturbed from

  • position (Number, optional) – the position (in the discretization domain) associated with the value, None by default

Returns:

the perturbed value and \(\alpha_{p} = \log( \frac{p({\bf m'})}{p({\bf m})} \frac{q\left({\bf m} \mid {\bf m'}\right)}{q\left({\bf m'} \mid {\bf m}\right)} \lvert \mathbf{J} \rvert)\)

Return type:

Tuple[Number, Number]

abstractmethod sample(position=None)

sample a new value from the prior

Paramters

positionUnion[np.ndarray, Number], optional

the position (in the discretization domain) associated with the value, None by default

returns:

a value corresponding to the prior probability (at the given position)

rtype:

Number

set_custom_initialize(initialize_func)

sets a custom initialization function

Parameters:

initialize_func (Callable[["Prior", np.ndarray], np.ndarray]) – The function to use for initialization. This function should take a Prior instance and optionally an array of positions as input arguments, and produce an array of values as output.

Examples

def my_init(
    param: bb.prior.Prior,
    position: np.ndarray
) -> np.ndarray:
    print("This is my custom init!")
    return np.ones(len(position))

my_param.set_custom_initialize(my_init)

back to top