lightweight_mmm
lightweight_mmm copied to clipboard
Priors of tested media channels
Hi, I am a MMM scientist and currently using LightWeightMMM for my job.
We are passing the model our knowledge of lift tests for specific medias that we have tested.
What are your advices to do that?
For these cases we need to control the mean of the distribution, which will try to ensure positive contributions for tested media channels. The lib by default use HalfNormal distributions which are not ideal to do that.
We were thinking to pass lognormal distributions to all media channels (coefficient beta_m), but we saw that both NUTS and HMC work on the logspace to calculate the gradients, but it did not work properly.
Is there any problem with that?
Cheers!
It's a very interesting question. I don't have the answer sadly.
In general the half normal is the standard for Bayesian Inference, but you can use also other distribution based on this discussion with some reference.
Probably the answer is in this piece of the code, but I don't know enough numpyro to provide a useful solution. Source Code
def _preprocess_custom_priors(
self,
custom_priors: Dict[str, Prior]) -> MutableMapping[str, Prior]:
"""Preprocesses the user input custom priors to Numpyro distributions.
If numpyro distributions are given they remains untouched, however if any
other option is passed, it is passed to the default distribution to alter
its constructor values.
Args:
custom_priors: Mapping of the name of the prior to its custom value.
Returns:
A mapping of names to numpyro distributions based on user input and
default values.
"""
Thanks for your answer, @uomodellamansarda!
I am still struggling to understand how to provide previous information to the model. I don't know @gustfon if you were able to do that.
Based on the documentation to use prior information, it seems that we need to provide to the LightweightMMM object a custom_priors argument.
custom_priors: MutableMapping[str, Prior] = dataclasses.field( init=False, repr=False, hash=False, compare=True)
It takes a str and a Prior.
How should be the right format to provide Prior?
For example, if I know that:
- YouTube follows an Half Normal Numpyro Distribution with a mean value of 0.025 and variance 0.01.
- I have other three media channels, Facebook - Radio - TV where I don't know the coefficient mean value
How can I provide this information to my model?
custom_priors = { "YouTube" : dist.Normal( mean = 0.025,variance = 0.01) "Facebook": "" "Radio": "" "TV": "" }
Because I am struggling to understand this step:
"""
default_priors = {
**models._get_default_priors(),
**models._get_transform_default_priors()[self.model_name]
}
# Checking that the key is contained in custom_priors has already been done
# at this point in the fit function.
for prior_name in custom_priors:
if isinstance(custom_priors[prior_name], numbers.Number):
custom_priors[prior_name] = default_priors[prior_name].__class__(
custom_priors[prior_name])
elif (isinstance(custom_priors[prior_name], collections.abc.Sequence) and
not isinstance(custom_priors[prior_name], str)):
custom_priors[prior_name] = default_priors[prior_name].__class__(
*custom_priors[prior_name])
elif isinstance(custom_priors[prior_name], dict):
custom_priors[prior_name] = default_priors[prior_name].__class__(
**custom_priors[prior_name])
elif not isinstance(custom_priors[prior_name], dist.Distribution):
raise ValueError(
"Priors given must be a Numpyro distribution or one of the "
"following to fit in the constructor of our default Numpyro "
"distribution. It could be given as args or kwargs as long as it "
"is the correct format for such object. Please refer to our "
"documentation on custom priors to know more.")
return custom_priors