BudgetOptimizer#

class pymc_marketing.mmm.budget_optimizer.BudgetOptimizer(*, num_periods: ~typing.Annotated[int, ~annotated_types.Gt(gt=0)], model: ~pymc_marketing.mmm.budget_optimizer.Annotated[~pymc_marketing.mmm.budget_optimizer.OptimizerCompatibleModelWrapper, ~pydantic.functional_validators.InstanceOf()], response_variable: str = 'total_contribution', utility_function: ~collections.abc.Callable[[~pytensor.tensor.variable.TensorVariable, ~pytensor.tensor.variable.TensorVariable], float] = <function average_response>, budgets_to_optimize: ~xarray.core.dataarray.DataArray | None = None, custom_constraints: ~collections.abc.Sequence[~pymc_marketing.mmm.constraints.Constraint] = (), default_constraints: bool = True)[source]#

A class for optimizing budget allocation in a marketing mix model.

The goal of this optimization is to maximize the total expected response by allocating the given budget across different marketing channels. The optimization is performed using the Sequential Least Squares Quadratic Programming (SLSQP) method, which is a gradient-based optimization algorithm suitable for solving constrained optimization problems.

For more information on the SLSQP algorithm, refer to the documentation: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html

Parameters:
num_periodsint

Number of time units at the desired time granularity to allocate budget for.

modelMMMModel

The marketing mix model to optimize.

response_variablestr, optional

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

utility_functionUtilityFunctionType, optional

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

budgets_to_optimizexarray.DataArray, optional

Mask defining a subset of budgets to optimize. Non-optimized budgets remain fixed at 0.

custom_constraintsSequence[Constraint], optional

Custom constraints for the optimizer.

default_constraintsbool, optional

Whether to add a default sum constraint on the total budget. Default is True.

Methods

BudgetOptimizer.__init__(**data)

Create a new model by parsing and validating input data from keyword arguments.

BudgetOptimizer.allocate_budget(total_budget)

Allocate the budget based on total_budget, optional budget_bounds, and custom constraints.

BudgetOptimizer.construct([_fields_set])

BudgetOptimizer.copy(*[, include, exclude, ...])

Returns a copy of the model.

BudgetOptimizer.dict(*[, include, exclude, ...])

BudgetOptimizer.extract_response_distribution(...)

Extract the response distribution graph, conditioned on posterior parameters.

BudgetOptimizer.from_orm(obj)

BudgetOptimizer.json(*[, include, exclude, ...])

BudgetOptimizer.model_construct([_fields_set])

Creates a new instance of the Model class with validated data.

BudgetOptimizer.model_copy(*[, update, deep])

!!! abstract "Usage Documentation"

BudgetOptimizer.model_dump(*[, mode, ...])

!!! abstract "Usage Documentation"

BudgetOptimizer.model_dump_json(*[, indent, ...])

!!! abstract "Usage Documentation"

BudgetOptimizer.model_json_schema([...])

Generates a JSON schema for a model class.

BudgetOptimizer.model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

BudgetOptimizer.model_post_init(context, /)

Override this method to perform additional initialization after __init__ and model_construct.

BudgetOptimizer.model_rebuild(*[, force, ...])

Try to rebuild the pydantic-core schema for the model.

BudgetOptimizer.model_validate(obj, *[, ...])

Validate a pydantic model instance.

BudgetOptimizer.model_validate_json(json_data, *)

!!! abstract "Usage Documentation"

BudgetOptimizer.model_validate_strings(obj, *)

Validate the given object with string data against the Pydantic model.

BudgetOptimizer.parse_file(path, *[, ...])

BudgetOptimizer.parse_obj(obj)

BudgetOptimizer.parse_raw(b, *[, ...])

BudgetOptimizer.schema([by_alias, ref_template])

BudgetOptimizer.schema_json(*[, by_alias, ...])

BudgetOptimizer.set_constraints(constraints)

Set constraints for the optimizer.

BudgetOptimizer.update_forward_refs(**localns)

BudgetOptimizer.validate(value)

Attributes

DEFAULT_MINIMIZE_KWARGS

model_computed_fields

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_extra

Get extra fields set during validation.

model_fields

model_fields_set

Returns the set of fields that have been explicitly set on this model instance.

num_periods

mmm_model

response_variable

utility_function

budgets_to_optimize

custom_constraints

default_constraints