-
Notifications
You must be signed in to change notification settings - Fork 332
Closed
Description
Pulling out fourier transformation from the MMM methods would be very convenient and reduce the dependency with that class.
I think the logic can be isolated, making it very easy to a isolate in a model. For instance,
fourier = YearlyFourier(nodes=10)
coords = {"date": [...], "fourier_components": fourier.columns}
with pm.Model(coords=coords) as model:
dayofyear = pm.Data("dayofyear", ..., dims="date")
seasonality = pm.Deterministic(
"seasonality",
fourier.apply(x=dayofyear),
dims=("date", "fourier_components"),
)
mu = seasonality.sum(axis=1)Then it could be used pretty easily in more larger more custom models (following flow of #632)
from pymc_marketing.mmm.components import MichaelisMenten, GeometricAdstock
adstock = GeometricAdstock(l_max=10, mode=ConvType.Before)
saturation = MichaelisMenten()
def create_forward_pass(first, second):
def media_forward_pass(x, dim):
return second.apply(x=first.apply(x=x, dim=dim), dim=dim)
return media_forward_pass
forward_pass = create_forward_pass(adstock, saturation)
with model:
model.add_coord("channel", ["C1", "C2", "C3"])
media_data = pm.Data("media_data", ..., dims=("date", "channel"))
media_contribution = pm.Deterministic(
"media_contribution",
forward_pass(media_data, dim="channel"),
dims=("date", "channel"),
)
mu += media_contribution.sum(axis=1)
with model:
...
mu += holiday_effects + time_varying_intercept + endless_imaginationThe YearlyFourier class could hold information about the priors to be familiar with the new classes from #632
Thoughts on the isolation and API idea?