Skip to content

port pymc-marketing.prior module #448

Open
@williambdean

Description

@williambdean

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions