pcntoolkit.math_functions.likelihood#

Classes#

BetaLikelihood

Helper class that provides a standard way to create an ABC using

Likelihood

Helper class that provides a standard way to create an ABC using

NormalLikelihood

Helper class that provides a standard way to create an ABC using

SHASHbLikelihood

Helper class that provides a standard way to create an ABC using

SHASHo2Likelihood

Helper class that provides a standard way to create an ABC using

SHASHoLikelihood

Helper class that provides a standard way to create an ABC using

ZeroInflatedNegativeBinomialLikelihood

Helper class that provides a standard way to create an ABC using

Functions#

get_default_normal_likelihood(→ NormalLikelihood)

Module Contents#

class BetaLikelihood(alpha: pcntoolkit.math_functions.prior.BasePrior, beta: pcntoolkit.math_functions.prior.BasePrior)#

Bases: Likelihood

Helper class that provides a standard way to create an ABC using inheritance.

backward(*args, **kwargs)#
compile_params(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray) → dict[str, Any]#
forward(*args, **kwargs)#
get_var_names() → List[str]#
has_random_effect() → bool#
to_dict() → Dict[str, Any]#
transfer(idata: xarray.DataTree, **kwargs) → BetaLikelihood#
yhat(*args, **kwargs)#
alpha#
beta#
class Likelihood(name: str)#

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

abstractmethod backward(*args, **kwargs)#
compile(X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray) → pymc.Model#
abstractmethod compile_params(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray) → dict[str, Any]#
create_model_with_data(X, be, be_maps, Y) → pymc.Model#
abstractmethod forward(*args, **kwargs)#
static from_args(args: Dict[str, Any]) → Likelihood#
static from_dict(dct: Dict[str, Any], version: str | None = None) → Likelihood#
abstractmethod has_random_effect() → bool#
abstractmethod to_dict() → Dict[str, Any]#
abstractmethod transfer(idata: xarray.DataTree, **kwargs) → Likelihood#
update_data(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray)#
abstractmethod yhat(*args, **kwargs)#
name#
class NormalLikelihood(mu: pcntoolkit.math_functions.prior.BasePrior, sigma: pcntoolkit.math_functions.prior.BasePrior)#

Bases: Likelihood

Helper class that provides a standard way to create an ABC using inheritance.

backward(*args, **kwargs)#
compile_params(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray) → dict[str, Any]#
forward(*args, **kwargs)#
has_random_effect() → bool#
to_dict() → Dict[str, Any]#
transfer(idata: xarray.DataTree, **kwargs) → Likelihood#
yhat(*args, **kwargs)#
mu#
sigma#
class SHASHbLikelihood(mu: pcntoolkit.math_functions.prior.BasePrior, sigma: pcntoolkit.math_functions.prior.BasePrior, epsilon: pcntoolkit.math_functions.prior.BasePrior, delta: pcntoolkit.math_functions.prior.BasePrior)#

Bases: Likelihood

Helper class that provides a standard way to create an ABC using inheritance.

backward(*args, **kwargs)#
compile_params(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray) → dict[str, Any]#
forward(*args, **kwargs)#
get_var_names() → List[str]#
has_random_effect() → bool#
to_dict() → Dict[str, Any]#
transfer(idata: xarray.DataTree, **kwargs) → SHASHbLikelihood#
yhat(*args, **kwargs)#
delta#
epsilon#
mu#
sigma#
class SHASHo2Likelihood(mu: pcntoolkit.math_functions.prior.BasePrior, sigma: pcntoolkit.math_functions.prior.BasePrior, epsilon: pcntoolkit.math_functions.prior.BasePrior, delta: pcntoolkit.math_functions.prior.BasePrior)#

Bases: Likelihood

Helper class that provides a standard way to create an ABC using inheritance.

backward(*args, **kwargs)#
forward(*args, **kwargs)#
get_var_names() → List[str]#
has_random_effect() → bool#
to_dict() → Dict[str, Any]#
delta#
epsilon#
mu#
sigma#
class SHASHoLikelihood(mu: pcntoolkit.math_functions.prior.BasePrior, sigma: pcntoolkit.math_functions.prior.BasePrior, epsilon: pcntoolkit.math_functions.prior.BasePrior, delta: pcntoolkit.math_functions.prior.BasePrior)#

Bases: Likelihood

Helper class that provides a standard way to create an ABC using inheritance.

backward(*args, **kwargs)#
forward(*args, **kwargs)#
get_var_names() → List[str]#
has_random_effect() → bool#
to_dict() → Dict[str, Any]#
delta#
epsilon#
mu#
sigma#
class ZeroInflatedNegativeBinomialLikelihood(mu: pcntoolkit.math_functions.prior.BasePrior, alpha: pcntoolkit.math_functions.prior.BasePrior, psi: pcntoolkit.math_functions.prior.BasePrior)#

Bases: Likelihood

Helper class that provides a standard way to create an ABC using inheritance.

backward(*args, **kwargs)#

Map Z-space back to counts.

Inverts the mapping applied by forward: the Z-score is turned into a probability between 0 and 1, and the smallest count whose CDF reaches that probability is returned.

Probabilities at or below F(0) map to zero; above it the structural zero mass is removed and the remainder rescaled onto the negative binomial component before inverting it.

Unlike forward this mapping is deterministic, so centiles derived from it are reproducible.

Parameters:

Z (array_like) – Z-scores to map back to count space.

Returns:

Y – Non-negative integer-valued counts, as floats.

Return type:

ndarray

compile_params(model: pymc.Model, X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray) → dict[str, Any]#
forward(*args, **kwargs)#

Map counts to Z-space using randomized quantile residuals.

The ZINB distribution is discrete, so each count y is actually an interval of probability rather than a single value: everything between F(y-1) and F(y), where F is the CDF – the fraction of people scoring at or below y.

Because we want Z to be a distribution rather than a handful of single points – and y being an interval is what allows that – we draw uniformly from the interval (=randomized quantile residuals) and map the result to Z through the inverse normal CDF.

This makes forward stochastic: the same count maps to a slightly different Z on each call. backward remains deterministic, so centiles are unaffected.

Parameters:

Y (array_like) – Observed counts, non-negative integers.

Returns:

Z-scores

Return type:

ndarray

get_var_names() → List[str]#
has_random_effect() → bool#
to_dict() → Dict[str, Any]#
transfer(idata: xarray.DataTree, **kwargs) → Likelihood#
yhat(*args, **kwargs)#
alpha#
mu#
psi#
get_default_normal_likelihood() → NormalLikelihood#