PyMC reposted this
The Prior class has a new home in `pymc-extras`! The class was introduced to express PyMC variables with dimensions outside of the PyMC model context. It has been quite useful for creating multidimensional variables. ```python from pymc_extras.prior import Prior scalar = Prior("Normal") # Specify parameters and dimensions vector = Prior("Normal", mu=0, sigma=1, dims=("product",)) # Use other priors as parameters to form hierarchical distributions mu = Prior("Normal") hierarchical_vector = Prior("Normal", mu=mu, sigma=1, dims=("product",)) ``` These can be used with PyMC models by using the `create_variable` method to create an arbitrary number of variables. Variable names are automatically generated based on the parameters defined. ```python import pymc as pm coords = dict(product=["A", "B"]) with pm.Model(coords=coords) as model: alpha = hierarchical_vector.create_variable("alpha") beta = hierarchical_vector.create_variable("beta") ``` The best part is that the dimensions are automatically handled. For example, the mu below will be transposed to broadcast correctly. ```python coords["store"] = ["X", "Y", "Z"] mu = Prior("Normal", dims=("store",)) hierarchical_matrix = Prior("Normal", mu=mu, sigma=1, dims=("store", "product")) with pm.Model(coords=coords) as model: gamma = hierarchical_matrix.create_variable("gamma") ``` Give it a try in your PyMC model to focus on the dimensions of your variables rather than handling shapes and names! Find in the 0.2.7 release of the `pymc-extras` package on PyPI: https://lnkd.in/d7TgY2iB