Potential Bug: Budget Optimizer Fails with Adstock Models (Dimension Mismatch)

The ‘MultiDimensionalBudgetOptimizerWrapper.optimize_budget()’ fails for me with a dimension mismatch error. The traceback returns a ValueError: Input dimension mismatch: (input[2].shape[3] = 53, input[3].shape[3] = 61), no matter what optimiser dates are chosen.This seems to align with the adstock lag except the tutorial example also has this mismatch without issue.I tried a patch to the method to include_carryover=True but this just endlessly runs.

Its surprising because the [multidimensional example tutorial]( MMM Multidimensional Example Notebook — Open Source Marketing Analytics Solution ) uses the same methods with the same type of mismatch but it runs without error and so theres only to be a problem when running our custom model. We’ve tried to follow the tutorial as closely as possible.

The other information to key in mind is that we’ve saved and loaded our model using cloudpickle.

# load data

import cloudpickle

with open("/content/drive/MyDrive/pyMC_mmm_model.pkl", "rb") as f:

    model_dict = cloudpickle.load(f)

mmm = model_dict['mmm']

idata = model_dict['idata']


Thank you!

Environment

- pymc-marketing: 0.17.1

- Affects: Custom models using `GeometricAdstock` lag = 8,

Root Cause

File: `pymc_marketing/mmm/multidimensional.py`, Line 2557

self.zero_data = create_zero_dataset(

model=self.model_class,

start_date=start_date,

end_date=end_date,

include_carryover=False,  #  Creates insufficient periods

)

self.num_periods = len(self.zero_data[self.model_class.date_column].unique())


For a 53-week optimization with `l_max=8`:

- Creates: 53 periods

- Needs: 53 + 8 = 61 periods (to account for carryover effects)

- Result: Dimension mismatch during optimization