pymc-labs / pymc-marketing

Bayesian marketing toolbox in PyMC. Media Mix (MMM), customer lifetime value (CLV), buy-till-you-die (BTYD) models and more.
https://www.pymc-marketing.io/
Apache License 2.0
584 stars 137 forks source link

Wrapper `Prior` / `Distribution` class #749

Closed wd60622 closed 1 day ago

wd60622 commented 2 weeks ago

Personally don't like writing the priors in big dictionaries. Inspired here by the bambi API

mu = Prior("Normal")
sigma = Prior("HalfNormal")
hierarchical_parameter = Prior("Normal", mu=mu, sigma=sigma, dims="channel", centered=False)

Honestly think this will be way shorted than dictionaries plus bring in goodies like:

This could be a documented submodule and would help demystify what goes in dictionary instead of any type of key!

This can also support post creation transformations. For instance:

positive_hierarchical_parameter = Prior("Normal", mu=mu, sigma=sigma, dims="channel", centered=False, transform="exp")

And some support for to and from dictionary for the serialization requirement.

Just some thoughts after typing out many large dictionaries in #747 CC: @carlosagostini @juanitorduz

juanitorduz commented 2 weeks ago

Yes! I love this idea! These dictionaries are growing up a lot and becoming hard to maintain! (also ... Pydantic haha)

wd60622 commented 2 weeks ago

Yes! I love this idea! These dictionaries are growing up a lot and becoming hard to maintain! (also ... Pydantic haha)

Big fan of pydantic. How does kwargs in intialization method work though?

Some initialization keys would be same:

Then parameter specific would change and might be handled with **kwargs

wd60622 commented 2 weeks ago

Any thoughts here @ColtAllen

wd60622 commented 2 weeks ago

Think it would be interesting to also wrap it into #706


mu = Prior("Normal", mu=0, sigma=1).constrain(lower=5, upper=10)

mu.kwargs # {"mu": 7.5, "sigma": 1.25}
ColtAllen commented 2 weeks ago

Any thoughts here @ColtAllen

It's certainly more convenient than dealing with a bunch of nested dicts in a custom model config. Is this an issue unique to pymc-marketing? If not it'd make more sense as a pymc addition.

wd60622 commented 2 weeks ago

It's certainly more convenient than dealing with a bunch of nested dicts in a custom model config. Is this an issue unique to pymc-marketing? If not it'd make more sense as a pymc addition.

I think it could definitely be used elsewhere. I think it can start here, can be pitched to larger PyMC group, then go from there