Replies: 2 comments 1 reply
-
You should be able to do this by following the Here is some inspiration: from pytensor import tensor as pt
import pymc as pm
from pymc_marketing.mmm import LogisticSaturation
from pymc_marketing.prior import Prior, sample_prior
class ConcatenatePrior:
def __init__(
self,
first: Prior,
n: int,
second: Prior,
dims: str,
):
self.first = first
self.n = n
self.second = second
self.dims = dims
def create_variable(self, name: str):
model = pm.modelcontext(None)
coords = model.coords[self.dims]
model.add_coords(
{
f"{self.dims}_first": coords[: self.n],
f"{self.dims}_second": coords[self.n :],
}
)
self.first.dims = f"{self.dims}_first"
self.second.dims = f"{self.dims}_second"
return pm.Deterministic(
name,
pt.concatenate(
[
self.first.create_variable(name=f"{name}_first"),
self.second.create_variable(name=f"{name}_second"),
]
),
dims=self.dims,
)
variable = ConcatenatePrior(
first=Prior("Normal"),
n=2,
second=Prior("HalfNormal"),
dims="channel",
)
coords = {"channel": ["first", "second", "third", "fourth"]}
with pm.Model(coords=coords) as model:
variable.create_variable("test")
idata = pm.sample_prior_predictive()
idata.prior["test"].to_series().unstack().hist(sharex=True)
plt.show()
priors = {"beta": variable}
saturation = LogisticSaturation(priors=priors)
prior = saturation.sample_prior(coords=coords)
curve = saturation.sample_curve(prior)
saturation.plot_curve(curve)
plt.show() You might run into some issues with I/O and have to implement the pymc-marketing/pymc_marketing/model_builder.py Lines 357 to 358 in dcbfa60 Just doing the to_dict should allow you to fit the model. |
Beta Was this translation helpful? Give feedback.
-
@williambdean thanks for the inspiration; this is helpful context for how these things are implemented in the MMM class. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to set the prior distribution for the coefficient of each control variable individually. For example, let's say I have two controls
event_1
andevent_2
, and I'd like to set a Normal distribution on the coefficient forevent_1
and a HalfNormal distribution for the coefficient ofevent_2
. Is this supported somehow in the current API? If not any ideas about the easiest way to do it?Beta Was this translation helpful? Give feedback.
All reactions