EvaluationWindows#
- class pymc_marketing.mmm.counterfactual.EvaluationWindows(windows, max_window, dates)[source]#
Per-period evaluation windows, and the cutting of arrays to fit them.
A counterfactual is evaluated on a window around each period rather than on the whole date axis, because the alternative is re-evaluating the entire series once per (period, channel) pair. The window reaches back
l_maxfor carry-in history and forwardl_maxfor carry-out, and is clamped to the fitted dates rather than padded out to those ideal bounds. Clamping is what makes a windowed evaluation agree with a full-axis one on every evaluated date: at the start of the data there is no history to supply, the graph’s own adstock already pads with zeros there, and padding instead would inject synthetic history – inert for spend, but not for an effect whose contribution at zero spend is its own intercept.The dates that are summed follow the adstock’s convolution mode. Trailing decay is attributed from the period forward, leading effects from the period backward, and overlap effects to both sides. Under full-axis evaluation,
Afterdeliberately still excludes moves before the period: those can be caused by a date-reducing node rather than adstock kernel mass, and including them would make periods overlap in a quantity callers read as a decomposition. ForBeforeandOverlap, however, dates before the period contain real leading kernel mass and are included in the sum.- Parameters:
- windows
listofPeriodWindow One per period, in period order.
- max_window
int Longest window. Shorter ones are right-padded to it so they stack for batched evaluation; a causal filter cannot reach back into that padding from any evaluated date.
- dates
pd.DatetimeIndex The full fitted date axis the windows index into.
- windows
Methods
EvaluationWindows.__init__(windows, ...)EvaluationWindows.build(*, periods, dates, ...)Work out the window of each period, and which of its dates are summed.
Build the perturbed spend arrays that have to be evaluated.
EvaluationWindows.cut(values, dtype)Cut a date-first array into one padded window per period.
EvaluationWindows.time_index(dtype)Build the positions along the fitted axis that each window covers.
Attributes