Named#
- class pymc_marketing.terms.Named(name, expr, dims=None)[source]#
Compose an expression into a named deterministic variable.
The inner expression is built lazily within the model context:
build_paramproduces the value andpmd.Deterministicstores it undername. Coordinates, data registration, and data updating delegate to the inner expression. Useful for naming intermediate effects (scales, link outputs) that should appear in the posterior.The expression leaves must be dims-native:
Parameter/Priorwithxdist=Trueorpytensor.xtensorexpressions.- Parameters:
name (
str) – Name of the deterministic variable.expr (
Any) – Inner expression accepted bybuild_param.dims (
str|Sequence[str] |None) – Dimensions for the deterministic variable. These align the built value ontodims(pmd.Deterministictransposes), so they must be a permutation of the inner value’s dims, not a new declaration - a value without those dims raisesValueError.
Examples
from pymc_extras.prior import Prior from pymc_marketing.terms import Named, Parameter, Ref scale = Named( "scale", Parameter("scale_raw", prior=Prior("HalfNormal", dims="product")), dims="product", ) # an effect that references another built variable: build once with # ``Named``, reference afterwards with ``Ref`` effect = Named( "effect", Ref("scale") * Parameter("kappa", prior=Prior("Normal", dims="product")), dims="product", )
Methods
Named.__init__(name, expr[, dims])Named.add_coords(ds)Add coordinates to the model during
register_data.Build the named deterministic from the inner expression.
Named.from_dict(data)Reconstruct a named term from its serialized form.
Named.get_coords(ds)Collect coordinates from the inner expression.
Named.named(name[, dims])Record this expression as a named deterministic model variable.
Register shared data for the inner expression.
Named.set_data(ds[, model])Update shared data for the inner expression.
Named.sum(dim)Sum this expression over one named dimension.
Named.to_dict([_orig])Attributes
Dataset variables this term reads as shared data.
Deterministics this term freezes for out-of-sample evaluation.