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_param produces the value and pmd.Deterministic stores it under name. 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 / Prior with xdist=True or pytensor.xtensor expressions.

Parameters:
  • name (str) – Name of the deterministic variable.

  • expr (Any) – Inner expression accepted by build_param.

  • dims (str | Sequence[str] | None) – Dimensions for the deterministic variable. These align the built value onto dims (pmd.Deterministic transposes), so they must be a permutation of the inner value’s dims, not a new declaration - a value without those dims raises ValueError.

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.

Named.create_variable()

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.

Named.register_data(ds)

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

Named.data_vars

Dataset variables this term reads as shared data.

Named.dims

Named.frozen_deterministics

Deterministics this term freezes for out-of-sample evaluation.

Named.name

Named.expr