Skip to content

fix(mmm): allow constant tensors in adstock sample_prior (fixes #1749)#2304

Open
shivamlalakiya wants to merge 4 commits intopymc-labs:mainfrom
shivamlalakiya:fix/constant-params-plot
Open

fix(mmm): allow constant tensors in adstock sample_prior (fixes #1749)#2304
shivamlalakiya wants to merge 4 commits intopymc-labs:mainfrom
shivamlalakiya:fix/constant-params-plot

Conversation

@shivamlalakiya
Copy link
Contributor

@shivamlalakiya shivamlalakiya commented Feb 18, 2026

Description

Fixes #1749

Previously, sample_prior would fail if an adstock transformation (e.g., GeometricAdstock) was initialized with constant tensors instead of PyMC distributions, as pm.sample_prior_predictive requires free random variables.

This PR adds a fallback mechanism: if no free random variables are detected in the model, it evaluates the constant tensors deterministically and returns a valid InferenceData object.

Changes

  • Modified sample_prior in transformers.py to handle ValueError from sample_prior_predictive.
  • Added regression test tests/mmm/test_issue_1749.py to verify constant inputs work.

Related Issue

Checklist


📚 Documentation preview 📚: https://pymc-marketing--2304.org.readthedocs.build/en/2304/

@cursor
Copy link

cursor bot commented Feb 18, 2026

PR Summary

Low Risk
Small, localized change to prior-sampling that only affects transformations initialized with constant tensors; main risk is slightly different prior datasets due to newly-added pm.Deterministic nodes.

Overview
Fixes Transformation.sample_prior to work when transformation parameters are provided as constant tensors (and to include them in the returned idata.prior). It now registers non-distribution priors as pm.Deterministic variables before calling pm.sample_prior_predictive, covering both all-constant and mixed constant/distribution cases.

Adds regression tests for issue #1749 verifying sample_prior succeeds and returns expected constant values for GeometricAdstock (alpha) and for generic transformations, including with coordinate dimensions.

Written by Cursor Bugbot for commit c940cf4. This will update automatically on new commits. Configure here.

@github-actions github-actions bot added MMM tests enhancement New feature or request good second issue Bit more involved but still doable for newcomers plots labels Feb 18, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@ricardoV94
Copy link
Contributor

There's not really any prior being sampled...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good second issue Bit more involved but still doable for newcomers MMM plots tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plot curve workflow with constant parameters

3 participants