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_max for carry-in history and forward l_max for 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 run from the period’s own start to its carry-out end, and the estimand that fixes is a forward-looking one: a period’s increment is what moving its spend does to that period and to the dates after it. Under full-axis evaluation, selected for a node whose value depends on the whole series, the perturbation also moves dates before the period, and those moves are deliberately left out of the sum. Summing them would make the periods overlap in a quantity every caller reads as a decomposition, and it is not what “this period’s increment” is taken to mean. A date-reducing node is therefore evaluated on the whole series, as its value requires, and still attributed forwards.

Parameters:
windowslist of PeriodWindow

One per period, in period order.

max_windowint

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.

datespd.DatetimeIndex

The full fitted date axis the windows index into.

Methods

EvaluationWindows.__init__(windows, ...)

EvaluationWindows.build(*, periods, dates, ...)

Work out the window of each period, and which of its dates are summed.

EvaluationWindows.build_scenarios(*, ...)

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

windows

max_window

dates