MMM.optimize_budget#

MMM.optimize_budget(budget, num_periods, budget_bounds=None, response_variable='total_contributions', utility_function=<function average_response>, constraints=(), default_constraints=True, **minimize_kwargs)[source]#

Optimize the given budget based on the specified utility function over a specified time period.

This function optimizes the allocation of a given budget across different channels to maximize the response, considering adstock and saturation effects. It scales the budget and budget bounds, performs the optimization, and generates a synthetic dataset for posterior predictive sampling.

The function first scales the budget and budget bounds using the maximum scale of the channel transformer. It then uses the BudgetOptimizer to allocate the budget, and creates a synthetic dataset based on the optimal allocation. Finally, it performs posterior predictive sampling on the synthetic dataset.

Important: When generating the posterior predicive distribution for the target with the optimized budget, we are setting the control variables to zero! This is done because in many situations we do not have all the control variables in the future (e.g. outlier control, special events).

Parameters:
budgetfloat or int

The total budget to be allocated.

num_periodsint

The number of time units over which the budget is to be allocated.

budget_boundsDataArrayr or dict[str, tuple[float, float]], optional

An xarray DataArary or dictionary specifying the lower and upper bounds for the budget allocation for each channel. If None, no bounds are applied.

response_variablestr, optional

The response variable to optimize. Default is “total_contributions”.

utility_functionUtilityFunctionType, optional

The utility function to maximize. Default is the mean of the response distribution.

custom_constraintslist[dict[str, Any]], optional

Custom constraints for the optimization. If None, no custom constraints are applied. Format: [{“key”:…,”constraint_fun”:…,”constraint_type”:…}]

default_constraintsbool, optional

Whether to add the default sum constraint to the optimizer. Default is True.

**minimize_kwargs

Additional arguments to pass to the BudgetOptimizer.

Returns:
az.InferenceData

The posterior predictive samples generated from the synthetic dataset.

Raises:
ValueError

If the time granularity is not supported.

ValueError

If the noise level is not a float.