CounterfactualEvaluator.evaluate_counterfactual#

CounterfactualEvaluator.evaluate_counterfactual(scenarios, *, windows, batch_size=None)[source]#

Evaluate every node on all counterfactual scenarios.

Auxiliary date-indexed inputs are cut here rather than by the caller, then broadcast from per-period to per-scenario through CounterfactualScenarios.period_index.

Scenarios are evaluated in batches. The graph’s intermediates are what makes the difference: an adstock of length l_max materializes a lagged copy per lag, so a batch’s working set is a multiple of its output, and a mediated per-channel run over many periods can ask for far more of that at once than it has to. Batches are concatenated in scenario order, so CounterfactualScenarios.rows keeps addressing the same results.

Parameters:
scenariosCounterfactualScenarios

Perturbed spend and its scenario bookkeeping.

windowsEvaluationWindows

The windows the scenarios were built for.

batch_sizeint, optional

Scenarios per evaluation. Defaults to whatever keeps a batch’s outputs under MAX_BATCH_ELEMENTS, and is exposed so a test can pin one batch against many.

Returns:
dict

Per response variable, an array of shape (n_scenarios, n_samples, max_window, *non_date_dims).