PlanEvaluation#

class pymc_marketing.mmm.budget_optimizer.PlanEvaluation(objective, objective_gradient, constraint_residuals=None)[source]#

The compiled objective and its gradient at one labelled plan.

Returned by BudgetOptimizer.evaluate_plan(). Both sign conventions are offered because both are wanted and confusing them is silent: the optimizer minimises objective = -utility, so objective is what compares with scipy_result.fun, while utility is what compares with a response.

Attributes:
objectivefloat

The objective at the plan, on the minimiser’s scale (the negated utility). Equal to result.scipy_result.fun when the plan is the solution of that run.

objective_gradientdict[str, xarray.DataArray]

Derivative of objective with respect to every decision cell, keyed by decision-variable name and labelled with that variable’s own dims and coords – the same layout unpack() produces. Cells outside the optimization mask are reported as 0.0 because they are not decision variables, not because the response is insensitive to them; optimizer.budgets_to_optimize says which is which.

constraint_residualsdict[str, ConstraintResidual] or None

Value of every registered constraint at the plan, keyed by Constraint key, when BudgetOptimizer.evaluate_plan() was called with a total_budget; None otherwise. See feasible().

Notes

Gradient units follow the decision variable: for media this is response per unit of per-period spend sustained over the whole window, including the carry-over tail. Divide by the number of periods for a per-dollar figure. A lever’s entry is in that lever’s own units.

Methods

PlanEvaluation.__init__(objective, ...[, ...])

PlanEvaluation.feasible([atol])

Whether every registered constraint holds at the plan.

Attributes

PlanEvaluation.constraint_residuals

PlanEvaluation.utility

The utility at the plan: -objective, the quantity being maximised.

PlanEvaluation.utility_gradient

Derivative of the utility per decision cell: -objective_gradient.

PlanEvaluation.objective

PlanEvaluation.objective_gradient