LeverVariable#
- class pymc_marketing.mmm.optimization_variables.LeverVariable(name, dim, coords, bounds, initial_value, flat_dim='budgets_flat')[source]#
A non-media decision variable: one
pm.Datanode in native units.Where
MediaVariableconverts monetary budgets into channel data, a lever is optimized directly in whatever units the model already uses for it (a discount fraction, a price index), so the forward map is the identity up to relabelling the flat dimension.A lever only moves if the optimizer’s
response_variablecan reach it. The defaulttotal_media_contribution_original_scaleis built from the channel contribution alone, so a lever acting through aMuEffectis invisible to it; score againsttotal_response_original_scale, which anMMMwith mu effects registers.Levers do not participate in the default budget-sum constraint, which sums the media tensor alone: a discount depth is not money drawn from a shared pool. To constrain one, write a custom
Constraintand reach its segment of the flat vector throughoptimizer.optimization_variables.variable_slice(name).- Parameters:
- name
str Name of the model’s
pm.Datanode this lever substitutes.- dim
str The node’s single dimension, which must not be the date dim.
- coords
list Coordinates of
dim, in the model’s order.- bounds
Sequence[tuple] orNone Declared
(low, high)bounds per entry in the lever’s native units, or None to leave it unbounded.- initial_value
np.ndarray The node’s current value in the model, used as the warm start. It is read once, when the optimizer is constructed, which matches the rest of the optimizer: the objective graph is built and frozen at construction too, and this node is substituted out of it entirely. Updating the
pm.Datanode afterwards therefore changes neither the objective nor the warm start; rebuild the optimizer to pick up a new value.- flat_dim
str Name of the flat decision vector’s dimension.
- name
Methods
LeverVariable.__init__(name, dim, coords, ...)Monetary amount this variable draws from the shared budget.
LeverVariable.default_bounds(total_budget)Return the declared native-unit bounds, or unbounded.
LeverVariable.default_x0(total_budget)Warm start at the lever's current model value, clipped to bounds.
LeverVariable.from_model(model, name[, ...])Build a lever by reading a named node's dim, coords and value off a model.
Flatten labelled lever values into flat-vector order.
Relabel the flat slice with the lever's own dim.
Label a flat solution slice with the lever's dim and coords.
Attributes
sizeNumber of lever entries, the length of its dim.
namedimscoordsflat_dim