-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use SoftPlusHSGP in multidimensional HSGP #1510
Use SoftPlusHSGP in multidimensional HSGP #1510
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1510 +/- ##
=======================================
Coverage 92.74% 92.75%
=======================================
Files 52 52
Lines 6120 6126 +6
=======================================
+ Hits 5676 5682 +6
Misses 444 444 ☔ View full report in Codecov by Sentry. |
media_latent_process = HSGP.parameterize_from_data( | ||
media_latent_process = SoftPlusHSGP.parameterize_from_data( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wd60622 can you please explain the motivation behind the softplus transform? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Aligns the default hsgp with other MMM class
- remove negative channel contributions with time varying media = True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @wd60622 ! Would you mind running the time-varying parameter notebooks affected by this change just to control the expected result? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a multidimensional mmm notebook already? This is just the new class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but in theory you could reproduce the results of the MMM basic class with this object right? The intention is not to update the docs but maybe have some experiments on the effect of this parametrization. I think you can just share some plots or experiments 9for the sake of illustrating the benefits) :) Just for future reference. It is not a blocker, but more to have a bit more intuition WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I can update
However, there is still slight difference in the intercept which I noted. Should that be consolidated?
Thoughts @cetagostini
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make sure that the baseline is in. I think without it might be too inflexible.
This is an adapted version of the other MMM intercept: import pandas as pd
import pymc as pm
import matplotlib.pyplot as plt
from pymc_marketing.mmm import SoftPlusHSGP
n_dates = 52 * 2
dates = pd.date_range("2025-01-01", periods=n_dates, freq="W-MON")
X = (dates - dates[0]).days.values
hsgp = SoftPlusHSGP.parameterize_from_data(X, ls_lower=10, ls_upper=25, dims="date")
coords = {"date": dates}
with pm.Model(coords=coords) as model:
name = "intercept"
intercept_baseline = pm.Gamma(f"{name}_baseline", mu=3, sigma=1)
intercept_moving = hsgp.create_variable(f"{name}_multiplier")
intercept = pm.Deterministic(
name,
intercept_baseline * intercept_moving,
dims=hsgp.dims,
)
idata = pm.sample_prior_predictive()
prior = idata.prior
from pymc_marketing.plot import plot_curve
prior["intercept"].pipe(plot_curve, {"date"})
plt.show() Results in: Note Without the baseline, the intercept is just centered around 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the example @wd60622 !
Realizing that the current implementation does that have baseline and multiplier concept pymc-marketing/pymc_marketing/mmm/multidimensional.py Lines 1030 to 1044 in b9bbcd4
So merging this now! |
Description
This might still differ from the other implementation where the HSGP intercept has a baseline which is then multiplied by HSGP:
pymc-marketing/pymc_marketing/mmm/mmm.py
Lines 482 to 498 in 89c9e97
Another alternative is to build that part into the HSGP model itself. However, the mmm would require another prior for the intercept. Which I think is good to keep separate. We can always wrap that logic into a separate function like in
MuEffect
pymc-marketing/pymc_marketing/mmm/multidimensional.py
Lines 58 to 68 in 89c9e97
Thoughts?
Related Issue
Checklist
pre-commit.ci autofix
to auto-fix.📚 Documentation preview 📚: https://pymc-marketing--1510.org.readthedocs.build/en/1510/