Skip to content

port pymc-marketing.prior module #448

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

Closed
williambdean opened this issue Apr 4, 2025 · 0 comments · Fixed by #470
Closed

port pymc-marketing.prior module #448

williambdean opened this issue Apr 4, 2025 · 0 comments · Fixed by #470

Comments

@williambdean
Copy link
Collaborator

williambdean commented Apr 4, 2025

Port this self-containing* module to pymc-extras

The pymc-marketing.prior module introduces protocol class, VariableFactory:

  • dims the dimensions of variable
  • create_variable method to create a pytensor variable

Prior Class

The Prior class implements this and is interface to work with PyMC distributions. i.e. Prior("Normal", mu=0, sigma=1, dims="covariate") will eval to pm.Normal(name, mu=0, sigma=1, dims="covariate") upon call prior.create_variable(name)

There are some additional features like, automatic dimension handling for nested distributions

# Straight forward
Prior("Normal", mu=Prior("Normal"), sigma=1, dims="covariate")
# The transpose is handled automatically making changes to the dimensions easier
Prior("Normal", mu=Prior("Normal", dims="covariate"), sigma=1, dims=("covariate", "geo"))

There have been some efforts to change the syntax to be closer to pm or pz but has caused some documentation issues.

Automatic Centering flag

Prior class takes centered flag at initialization which will determine how to create the variable upon create_variable call. It only works for a few distributions like Normal, StudentT, ZeroSumNormal

https://github.com/pymc-labs/pymc-marketing/blob/a87f1fa979d5694ee4d50d1fd2f3519c7c4e50f5/pymc_marketing/prior.py?plain=1#L410-L414

Note

The VariableFactory protocol can always be followed to create a custom distribution.

transform parameter

pm.math, pytensor.tensor, or registered transformations can be used in the transform parameter. This

Serialization

This comes with easy serialization to JSON for deployment use-cases

Closer syntax to pm

pr.Normal(mu=pr.Normal() sigma=1, dims="covariate")
pr.Normal(mu=pr.Normal(dims="covariate"), sigma=1, dims=("covariate", "geo"))

See pymc-labs/pymc-marketing#1540

Other Features

There is also Censored class wrapper around pm.Censored which implements the protocol.

Issues from https://github.com/pymc-labs/pymc-marketing/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22Prior%20class%22

Additional Information

Warning

Caveats include depending on pydantic

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

Successfully merging a pull request may close this issue.

1 participant