Description
Port this self-containing* module to pymc-extras
The pymc-marketing.prior
module introduces protocol class, VariableFactory
:
dims
the dimensions of variablecreate_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
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
- The documentation: https://www.pymc-marketing.io/en/stable/api/generated/pymc_marketing.prior.html
- Other conversation about a port to pymc: Port the `Prior` class from `pymc-marketing` into the `pymc` repo pymc#7416