MediaVariable#
- class pymc_marketing.mmm.optimization_variables.MediaVariable(name, mask, num_periods, adstock_periods, channel_scales, dtype, scales_dims=('channel',), date_dim='date', budget_distribution_over_period_tensor=None, cost_per_unit_tensor=None, carry_in_values=None, flat_dim='budgets_flat')[source]#
The media-budget decision variable.
Owns the forward map from flat monetary budgets to the model’s channel data tensor: scatter through the optimization mask, spread over
num_periods(uniformly or via a fixed temporal distribution), divide bychannel_scales, convert monetary units viacost_per_unit, and zero-padadstock_periodsfor carry-over, and the inverse map from a flat solution back to a labelled monetaryDataArray.- Parameters:
- name
str Name of the model’s channel data variable.
- mask
DataArray Boolean mask over the budget dims selecting cells to optimize, already reindexed and transposed to the model’s coordinate and dimension order. That alignment is load-bearing: the mask is consumed positionally by the forward map (scatter into the model’s tensor layout) and supplies the labels for the inverse map, so a mask in a different coordinate order would silently attribute each value to the wrong cell.
- num_periods
int Number of periods budget is allocated over.
- adstock_periods
int Number of zero-padded carry-over periods appended after the allocation window.
- channel_scales
floatornp.ndarray Per-channel scale factors converting monetary budgets to model units.
- dtype
str dtype of the model’s channel data variable. Must be a float dtype.
- date_dim
str Name of the date dimension.
- budget_distribution_over_period_tensor
XTensorVariableorNone Pre-processed masked temporal distribution factors with dims
(date_dim, flat_dim), or None for uniform spread.- cost_per_unit_tensor
XTensorVariableorNone Pre-processed cost-per-unit tensor with dims
(date_dim, *mask.dims), or None for no conversion.- flat_dim
str Name of the flat dimension of the decision vector.
- name
Methods
MediaVariable.__init__(name, mask, ...[, ...])Media spends its whole slice, already in monetary units.
MediaVariable.default_bounds(total_budget)Default
[0, total_budget]bounds per optimized cell.MediaVariable.default_x0(total_budget)Spread the total budget uniformly over the optimized cells.
MediaVariable.from_model(model, name, *, ...)Build a monetary variable by reading a named node's dims off a model.
Flatten a labelled allocation into this variable's flat-vector order.
Scatter the flat slice into the full budget-dims tensor.
Build the channel-data substitution tensor from the flat slice.
Scatter a flat solution back into a labelled monetary
DataArray.Attributes
shapeShape of the full (unmasked) budget tensor.
sizeNumber of optimized budget cells.
namedimscoordsflat_dim