optimization_variables#

Optimization variables for budget optimization.

The decision vector handed to scipy.optimize.minimize is a flat 1-D array. Everything the optimizer knows about what that vector means, which model variable each segment substitutes, how a segment maps to model-space tensors (the forward map), and how a solution maps back to labelled DataArray objects (the inverse map), lives here, stated once per variable.

  • OptimizationVariable is the per-variable protocol: a named, contiguous segment of the flat vector with a forward map (to_model), an inverse (unpack) and its exact inverse (pack), plus defaults for the initial guess and bounds.

  • MediaVariable implements the media-budget path: mask scatter, channel scaling, temporal distribution, cost-per-unit conversion, and adstock carry-over padding.

  • OptimizationVariables owns the flat symbolic input and the variable layout, and produces the single substitution dict for pymc.do.

Module Attributes

FLAT_DIM

Name of the flat decision vector's dimension, shared by every variable and by the container so a rename cannot desynchronise them.

Functions

align_to_model_coords(da, coords, *, label)

Reindex a labelled input onto the model's budget coordinates.

Classes

LeverVariable(name, dim, coords, bounds, ...)

A non-media decision variable: one pm.Data node in native units.

MediaVariable(name, mask, num_periods, ...)

The media-budget decision variable.

OptimizationVariable()

One named, contiguous segment of the flat decision vector.

OptimizationVariables(variables[, ...])

The complete decision vector: an ordered list of variables.