Open drbenvincent opened 1 month ago
See the discussion here https://github.com/pymc-devs/pymc/discussions/7416 on whether to port the Prior
class from pymc-marketing
into the main pymc-repo
. This would be amazing because we could add this new functionality with very little change to CausalPy
itself.
Based on the discussion, it seems that the Prior
class is most likely best suited for pymc-experimental
. However, I don't have a timeline for that just yet.
The code is a single file so it would be easy to copy and tweak to your liking.
With access to the Prior
class, the custom priors doesn't seems very difficult since the dims are already being specified in the classes.
Some things to consider:
dist = Prior("Normal", mu=0, sigma=1, dims="coeffs"); if dist.dims != ("coeffs", ): raise ...
dist = Prior("Normal", mu=0, sigma=1, dims="coeffs"); if dist.distribution != "Normal": raise ...
Based on the old API, it might look like this:
from pymc_marketing.prior import Prior
from causalpy.pymc_models import WeightedSumFitter
priors = {
"beta": Prior("Dirichlet", a=[1, 2, 3, 4], dims="coeffs"),
"sigma": Prior("Gamma", mu=1.5, sigma=0.25),
}
model = WeightedSumFitter(priors=priors)
# Check the priors
print(model.priors)
model.fit(X, y)
High level goals
Implementation
We can perhaps learn from
pymc-marketing
which started off allowing users to specify priors by providingdict
s but which has moved to having a prior class (see https://github.com/pymc-labs/pymc-marketing/pull/759). We may find thatdict
s are fine for our purposes, but there could be advantages of going down the path of using classes. (Tagging @wd60622)