Skip to content
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

Wrapper Prior / Distribution class #749

Closed
wd60622 opened this issue Jun 14, 2024 · 6 comments · Fixed by #759
Closed

Wrapper Prior / Distribution class #749

wd60622 opened this issue Jun 14, 2024 · 6 comments · Fixed by #759

Comments

@wd60622
Copy link
Contributor

wd60622 commented Jun 14, 2024

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:

  • initialization check for distribution name in pm module
  • make use of pymc distributions having defaults
  • dims will broadcast / are possible
  • quick distribution creation used under hood or for checks:
    with pm.Model(coords={"channel": ["A", "B", "C"]}):
        alpha = hierarchical_parameter.create_variable("alpha")

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
Copy link
Collaborator

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

@wd60622
Copy link
Contributor Author

wd60622 commented Jun 14, 2024

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:

  • distribution
  • dims
  • centered
  • transform

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

@wd60622
Copy link
Contributor Author

wd60622 commented Jun 15, 2024

Any thoughts here @ColtAllen

@wd60622
Copy link
Contributor Author

wd60622 commented Jun 16, 2024

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
Copy link
Collaborator

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 wd60622 self-assigned this Jun 18, 2024
@wd60622
Copy link
Contributor Author

wd60622 commented Jun 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants