Module: schema.processors.budget_optimization_processor

Defines a processor for budget optimization inference on a Meridian model.

This module provides the BudgetOptimizationProcessor class, which is used to perform marketing budget optimization based on a trained Meridian model. The processor takes a trained model and a BudgetOptimizationSpec object, which defines the optimization parameters, constraints, and scenarios.

The optimization process aims to find the optimal allocation of budget across different media channels to maximize a specified objective, such as Key Performance Indicator (KPI) or Revenue, subject to various constraints.

Key Features:

  • Supports both fixed and flexible budget scenarios.
  • Allows setting channel-level budget constraints, either as absolute values or relative to historical spend.
  • Generates detailed optimization results, including optimal spends, expected outcomes, and response curves.
  • Outputs results in a structured protobuf format (BudgetOptimization).

Key Classes:

  • BudgetOptimizationSpec: Dataclass to specify optimization parameters and constraints.
  • BudgetOptimizationProcessor: The main processor class to execute budget optimization.

Example Usage:

  1. Fixed Budget Optimization: Optimize budget allocation for a fixed total budget, aiming to maximize KPI.

    from schema.processors import budget_optimization_processor
    from meridian.analysis import optimizer
    from schema.processors import common
    
    # Assuming 'trained_model' is a loaded Meridian model object
    
    spec = budget_optimization_processor.BudgetOptimizationSpec(
        optimization_name="fixed_budget_scenario_1",
        scenario=optimizer.FixedBudgetScenario(total_budget=1000000),
        kpi_type=common.KpiType.REVENUE, # Or common.KpiType.NON_REVENUE
        # Optional: Add channel constraints
        constraints=[
            budget_optimization_processor.ChannelConstraintRel(
                channel_name="channel_a",
                spend_constraint_lower=0.1, # Allow 10% decrease
                spend_constraint_upper=0.5  # Allow 50% increase
            ),
            budget_optimization_processor.ChannelConstraintRel(
                channel_name="channel_b",
                spend_constraint_lower=0.0, # No decrease
                spend_constraint_upper=1.0  # Allow 100% increase
            )
        ],
        include_response_curves=True,
    )
    
    processor = budget_optimization_processor.BudgetOptimizationProcessor(
        trained_model
    )
    # result is a `budget_pb.BudgetOptimization` proto
    result = processor.execute([spec])
    
  2. Flexible Budget Optimization: Optimize budget to achieve a target Return on Investment (ROI).

    from schema.processors import budget_optimization_processor
    from meridian.analysis import optimizer
    from schema.processors import common
    import meridian.constants as c
    
    # Assuming 'trained_model' is a loaded Meridian model object
    
    spec = budget_optimization_processor.BudgetOptimizationSpec(
        optimization_name="flexible_roi_target",
        scenario=optimizer.FlexibleBudgetScenario(
            target_metric=c.ROI,
            target_value=3.5  # Target ROI of 3.5
        ),
        kpi_type=common.KpiType.REVENUE,
        date_interval_tag="optimization_period",
        # Skip response curves for faster computation.
        include_response_curves=False,
    )
    
    processor = budget_optimization_processor.BudgetOptimizationProcessor(
        trained_model
    )
    result = processor.execute([spec])
    

Classes

class BudgetOptimizationProcessor: A Processor for marketing budget optimization.

class BudgetOptimizationSpec: Spec dataclass for marketing budget optimization processor.

class ChannelConstraintAbs: A budget constraint on a channel.

class ChannelConstraintRel: A budget constraint on a channel.