Special priors

Import specialised variable factories from abacus.special_priors. They can be used where the selected model or transform accepts the corresponding variable-factory contract. Estimator-specific prior restrictions still apply.

Public typeParameters and behaviour
SpecialPriorAbstract base for specialised priors; takes dims, centered=True and distribution parameters
LogNormalPriorRequires positive-scale mean and std; accepts scalar, array or nested prior parameters
LaplacePriorRequires location mu and positive scale b; supports centred and non-centred construction
MaskedPriorWraps a Prior and an xarray.DataArray mask; creates variables only at active entries

Parameterisation

LogNormalPrior computes log-scale parameters from the supplied positive-scale mean and standard deviation. These are different from Prior("LogNormal", mu=..., sigma=...), whose parameters are on the log scale. When parameters themselves are random, the moments describe the conditional distribution.

LogNormalPrior and LaplacePrior default to centered=True. Setting it to False changes the latent construction. Assess the resulting posterior geometry rather than assuming that either construction always samples better.

from pymc_extras.deserialize import deserialize

from abacus.special_priors import LaplacePrior, LogNormalPrior

positive_prior = LogNormalPrior(mean=1.0, std=0.5, dims=("channel",))
shrinkage_prior = LaplacePrior(mu=0, b=1, dims=("channel",), centered=False)
restored_prior = deserialize(positive_prior.to_dict())

Within a PyMC model context, create_variable(name) returns the constructed variable. sample_prior(coords=None, name="variable", **kwargs) creates a standalone prior sample and returns an xarray.Dataset. Keywords are passed to PyMC prior predictive sampling. Supply coordinates for named dimensions.

Masks

MaskedPrior(prior, mask, active_dim=None) is experimental and emits a warning on construction. Mask dimensions must match prior.dims in the same order. Supply a boolean mask with the intended shape and model coordinates.

import pymc as pm
import xarray as xr
from pymc_extras.prior import Prior

from abacus.special_priors import MaskedPrior

coords = {"channel": ["tv", "search"]}
mask = xr.DataArray([True, False], dims="channel", coords=coords)
prior = Prior("Normal", mu=0, sigma=1, dims="channel")
with pm.Model(coords=coords) as model:
    coefficient = MaskedPrior(prior, mask).create_variable("coefficient")

Inactive entries are exactly zero. An all-false mask produces deterministic zeros. active_dim names the coordinate for the active subset; by default it is derived from the prior dimensions. The implementation can add a length suffix if that coordinate already exists with a different size.

create_likelihood_variable(name, *, mu, observed) selects the active observed entries and returns an expansion over the original dimensions. Inactive entries do not contribute an observed likelihood term.

Serialisation and extension

SpecialPrior.to_dict() records the concrete class, parameters, dimensions and centring choice. Concrete classes support from_dict(...); the public pymc_extras.deserialize.deserialize(...) dispatcher restores registered representations after importing abacus.special_priors.

MaskedPrior.to_dict() and MaskedPrior.from_dict(...) retain the base prior, mask values, dimension names and active dimension. They do not retain mask coordinate labels. Restore any required coordinate labels in the surrounding model context.

A SpecialPrior subclass must implement _checks() and create_variable(). These underscore methods describe the extension contract; application examples should use the public construction and serialisation methods above.