-
Notifications
You must be signed in to change notification settings - Fork 77
Support for custom priors via Prior class #488
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very cool!
As far as I can tell, these changes are currently entirely invisible to the end user, right?
Before we do a new release I will follow up with another PR that adds some documentation. This will most likely be in the form of just giving a couple of worked examples
Main request is to add custom-ness to the Dirichlet for the WeightedSumFitter
class. Like I say in a comment, I mostly see people wanting to customise the hyperparams, not the distribution itself.
@@ -237,6 +248,11 @@ class LinearRegression(PyMCModel): | |||
Inference data... | |||
""" # noqa: W605 | |||
|
|||
default_priors = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add @property
decorator here? Or is that remembered from it being done in the PyMCModel
base class?
Getting an Pylance warning: Type "dict[str, Prior]" is not assignable to declared type "property"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What line of code bring that on? Maybe having a setter will help?
causalpy/pymc_models.py
Outdated
@@ -286,9 +305,8 @@ def build_model(self, X, y, coords): | |||
X = pm.Data("X", X, dims=["obs_ind", "coeffs"]) | |||
y = pm.Data("y", y[:, 0], dims="obs_ind") | |||
beta = pm.Dirichlet("beta", a=np.ones(n_predictors), dims="coeffs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We definitely want a custom prior for the Dirichlet. I think the Dirichlet would be used always (or nearly always), but there are plenty of real world use cases where the user might want to change the hyper parameters (currently a=np.ones(n_predictors)
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. since it is function of data, we will have to handle differently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've address this with dc20e3e. If user wants to change, they can add to the "priors" at initialization.
Take a look and let me know what you think.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #488 +/- ##
==========================================
+ Coverage 94.40% 94.62% +0.21%
==========================================
Files 29 28 -1
Lines 2075 2064 -11
==========================================
- Hits 1959 1953 -6
+ Misses 116 111 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tests pass :) |
Excited about this PR! |
This using
pymc-extras
to allow for custom priors. Might need to adjust the remaining a bit to work.