Skip to content
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 build check function, on prior predictive and plot prior #605

Merged
merged 2 commits into from
Dec 5, 2022
Merged

Add build check function, on prior predictive and plot prior #605

merged 2 commits into from
Dec 5, 2022

Conversation

tjburch
Copy link
Contributor

@tjburch tjburch commented Dec 4, 2022

Added a check that the model has been built in order to call prior_predictive. Since the same check is being called for this and plot_priors, I moved it out to a function that raises a ValueError if unbuilt.

Also added a single test that creates an unbuilt model and looks for that ValueError.

Closes #595.

@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2022

Codecov Report

Merging #605 (7824d72) into main (efac57d) will increase coverage by 0.03%.
The diff coverage is 100.00%.

❗ Current head 7824d72 differs from pull request most recent head f9f96f2. Consider uploading reports for the commit f9f96f2 to get more accurate results

@@            Coverage Diff             @@
##             main     #605      +/-   ##
==========================================
+ Coverage   82.81%   82.85%   +0.03%     
==========================================
  Files          38       38              
  Lines        3020     3027       +7     
==========================================
+ Hits         2501     2508       +7     
  Misses        519      519              
Impacted Files Coverage Δ
bambi/models.py 85.71% <100.00%> (+0.12%) ⬆️
bambi/tests/test_model_construction.py 97.29% <100.00%> (+0.05%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tomicapretto
Copy link
Collaborator

bambi/bambi/models.py

Lines 883 to 887 in 7824d72

if self.backend is None:
raise ValueError(
"The model is empty. "
"Are you forgetting to first call .build() or .fit() on the Bambi model?"
)

The above is not exactly the same type of check but it's very similar. There will be cases where changing the priors won't change the graph, if you still use the same family of distributions for example, but there will be cases where it would change the graph. So I think we should consider the check here as well. What do you think?

@tjburch
Copy link
Contributor Author

tjburch commented Dec 5, 2022

Good catch.

That checks on a backend, which is set within the build function only, so it looks to me like in all cases where the model is built the backend should exist, so doing the check on being built be identical to checking if the backend exists. So I'll just run the same check. If I'm not thinking of some edge case let me know.

@tomicapretto
Copy link
Collaborator

Does it look like the failing test is due to numerical issues?

@tjburch
Copy link
Contributor Author

tjburch commented Dec 5, 2022

Yeah, looks like some spurious divergences. Thanks for triggering it again.

@tomicapretto
Copy link
Collaborator

Thanks @tjburch :D

@tomicapretto tomicapretto merged commit a53a3eb into bambinos:main Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Model.prior_predictive() does not check if the model was built
3 participants