-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add function that returns the prior as a dictionary #829
Comments
Hey I would like to work on this, could you please elaborate more about this. |
Hi @tanishy7777, I imagine a method called See the following examples # Example 1
priors = {
"mu": {
"Intercept": bmb.Prior("Normal", mu=0, sigma=1),
"x": bmb.Prior("Normal", mu=0, sigma=5),
},
"sigma": bmb.Prior("HalfNormal", sigma=5)
}
model = bmb.Model("y ~ 1 + x", data, priors=priors)
model.get_priors()
# {
# "mu": {
# "Intercept": Prior("Normal", mu=0, sigma=1),
# "x": Prior("Normal", mu=0, sigma=5),
# },
# "sigma": Prior("HalfNormal", sigma=5)
# }
# Example 2
formula = bmb.Formula(
"y ~ 1 + x",
"sigma ~ 1 + x",
)
priors = {
"mu": {
"Intercept": bmb.Prior("Normal", mu=0, sigma=1),
"x": bmb.Prior("Normal", mu=0, sigma=5),
},
"sigma": {
"Intercept": bmb.Prior("Normal", mu=0, sigma=0.25),
"x": bmb.Prior("Normal", mu=0, sigma=1),
}
}
model = bmb.Model(formula, data, priors=priors)
model.get_priors()
# {
# "mu": {
# "Intercept": Prior("Normal", mu=0, sigma=1),
# "x": Prior("Normal", mu=0, sigma=5),
# },
# "sigma": {
# "Intercept": Prior("Normal", mu=0, sigma=0.25),
# "x": Prior("Normal", mu=0, sigma=1),
# },
# } Note that those examples are simple as the priors were explicitly passed by the user. This is a bit more complicated when priors are not explicitly set. And I can imagine working on this issue would require familiarization with how things are structured in Bambi. |
Will something like this work? `import bambi as bmb class Model:
Example 1priors_example_1 = { model_1 = Model("y ~ 1 + x", data=None, priors=priors_example_1) Example 2formula_example_2 = bmb.Formula( priors_example_2 = { model_2 = Model(formula_example_2, data=None, priors=priors_example_2) It introduces the .get_priors() method to the Model class in Bambi. The new method provides a way to access the dictionary of priors directly, making it easier to modify priors and use functions like predictive_explorer from PreliZ. The implementation handles both explicit and default priors. |
Now we can "see" the prior being used by printing the model. But it will be nice to have direct access to the dictionary of priors. This dictionary should be the one expected by
priors
argument in.Model()
, or a string representing it. This will make it easier to modify priors and use functions likepredictive_explorer
from PreliZThe text was updated successfully, but these errors were encountered: