Transform#

class pymc_marketing.terms.Transform(inner, func)[source]#

Apply a pytensor function to a term’s output.

Delegates coordinates, data registration, and data updating to the inner expression. Covers link functions and arbitrary transformations without a separate link system.

Parameters:
innerAny

Inner expression accepted by build_param (ModelTerm, Sum, float, Prior, etc.).

funcCallable

A pytensor function applied to build_param(inner). E.g., pytensor.xtensor.math.exp, ptx.math.sigmoid.

Examples

import pytensor.xtensor as ptx

sigma = Transform(Intercept(name="sigma"), func=ptx.math.exp)

inner may be any expression, including custom ModelTerm subclasses and composed trees:

from pymc_extras.prior import Prior
from pymc_marketing.terms import Dot, Transform

effect = Transform(
    Dot(var_name="x", prior=Prior("Normal", dims="feature")),
    func=ptx.math.softplus,
)

Methods

Transform.__init__(inner, func)

Transform.add_coords(ds)

Add coordinates to the model during register_data.

Transform.create_variable()

Build func(build_param(inner)).

Transform.from_dict(data)

Reconstruct a transform from its serialized form.

Transform.get_coords(ds)

Collect coordinates from the inner expression.

Transform.register_data(ds)

Register shared data for the inner expression.

Transform.set_data(ds[, model])

Update shared data for the inner expression.

Transform.to_dict([_orig])

Attributes