pcntoolkit.math_functions.prior#
Attributes#
Classes#
Helper class that provides a standard way to create an ABC using |
|
A random effect drawn directly at the group scale. |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
Functions#
|
Build a prior from keyword arguments. |
|
Module Contents#
- class BasePrior(name: str = 'theta', dims: Tuple[str, ...] | str | None = None, mapping: str = 'identity', mapping_params: tuple = None, **kwargs)#
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- apply_mapping(x: Any) Any#
- compile(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray) Any#
- to_dict()#
- abstractmethod update_data(model, X, be, be_maps, Y)#
- property dims#
- mapping = 'identity'#
- mapping_params = (0, 1)#
- name = 'theta'#
- sample_dims = ()#
- class CenteredRandomPrior(mu: BasePrior | None = None, sigma: BasePrior | None = None, name: str = 'theta', dims: Tuple[str, ...] | str | None = None, mapping: str = 'identity', mapping_params: tuple[float, ...] = None, **kwargs)#
Bases:
RandomPriorA random effect drawn directly at the group scale.
Differs from
RandomPrioronly in how the offsets are sampled: here they are drawn at the group’s own scale, rather than at unit scale and then multiplied by it. The two describe the same model but sample differently.- transfer(idata: xarray.DataTree, **kwargs) CenteredRandomPrior#
- class LinearPrior(slope: BasePrior | None = None, intercept: BasePrior | None = None, name: str = 'theta', dims: Tuple[str, ...] | str | None = None, mapping: str = 'identity', mapping_params: tuple[float, ...] = None, basis_function: pcntoolkit.math_functions.basis_function.BasisFunction = LinearBasisFunction(), **kwargs)#
Bases:
BasePriorHelper class that provides a standard way to create an ABC using inheritance.
- classmethod from_dict(dict: LinearPrior.from_dict.dict, version: str | None = None) LinearPrior#
- set_name(name)#
- to_dict()#
- transfer(idata: xarray.DataTree, **kwargs) LinearPrior#
- update_data(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray)#
- basis_function#
- property dims#
- property has_random_effect#
- intercept#
- sample_dims = ('observations',)#
- slope#
- class Prior(name: str = 'theta', dims: Tuple[str, ...] | str | None = None, mapping: str = 'identity', mapping_params: tuple[float, ...] = None, dist_name: str = 'Normal', dist_params: Tuple[float | int | list[float | int], ...] = None, **kwargs)#
Bases:
BasePriorHelper class that provides a standard way to create an ABC using inheritance.
- to_dict()#
- update_data(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray)#
- dist_name = 'Normal'#
- dist_params = (0, 10.0)#
- property has_random_effect#
- sample_dims = ()#
- class RandomPrior(mu: BasePrior | None = None, sigma: BasePrior | None = None, name: str = 'theta', dims: Tuple[str, ...] | str | None = None, mapping: str = 'identity', mapping_params: tuple[float, ...] = None, **kwargs)#
Bases:
BasePriorHelper class that provides a standard way to create an ABC using inheritance.
- classmethod from_dict(dict: RandomPrior.from_dict.dict, version: str | None = None) RandomPrior#
- to_dict()#
- transfer(idata: xarray.DataTree, **kwargs) RandomPrior#
- update_data(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray)#
- property dims#
- property has_random_effect#
- mu#
- offsets#
- sample_dims = ('observations',)#
- scaled_offsets#
- sigma#
- sigmas#
- make_prior(name: str = 'theta', **kwargs) BasePrior#
Build a prior from keyword arguments.
- Parameters:
name (
str) – Name of the prior.linear (
bool) – Build a LinearPrior (a slope/intercept pair through a basis function).random (
bool) – Build a random-effect prior, i.e. a per-batch-effect offset around a shared mean.centered (
bool) –Only meaningful together with random. Selects how the random effect is parameterised - the two forms describe the same model but give the samplers different geometry:
False (default) - non-centered: the offsets are drawn at unit scale and multiplied by the group scale, offset = sigma * ZeroSumNormal(1). This is the standard choice for NUTS, which mixes better when the scale and the offsets are a priori independent.
True - centered: the offsets are drawn directly at the group scale, offset ~ ZeroSumNormal(sigma). Prefer this for mode-based approximations (inference_method=”laplace”).
- prior_from_args(name: str, args: Dict[str, Any], dims: Tuple[str, ...] | str | None = None) BasePrior#
- DEFAULT_PRIOR_ARGS#
- PM_DISTMAP#