MediaVariable.from_model#

classmethod MediaVariable.from_model(model, name, *, num_periods, adstock_periods, mask=None, carry_in_values=None, carry_in_periods=0, scales=1.0, date_dim='date', **kwargs)[source]#

Build a monetary variable by reading a named node’s dims off a model.

The media budgets are one instance of a monetary decision; a lower-funnel spend, or the reach an impression budget buys, is another. What distinguishes them is which node they substitute and over which dims they are decided, and both already live in the model, so callers name the node and this reads the rest.

Parameters:
modelModel

The model holding the node.

namestr

Name of the monetary node to optimize. Must carry named dims, including date_dim.

num_periods, adstock_periodsint

Decision and carry-over period counts for the window.

maskDataArray or None

Which cells to optimize, over the node’s non-date dims. Defaults to all of them.

carry_in_valuesnp.ndarray or None

Spend already made before the window, one leading period per row.

carry_in_periodsint

Read that many leading periods off the node itself when carry_in_values is not given. Read after the name is validated, so a typo is reported as a typo.

scalesfloat or np.ndarray

Scale factors converting monetary amounts into the node’s units.

date_dimstr

The model’s date dimension, which the node must vary over.

**kwargs

Passed through to the constructor.

Returns:
MediaVariable

A monetary variable over name.

Raises:
ValueError

If name has no named dims, or does not vary over date_dim.