-
-
Notifications
You must be signed in to change notification settings - Fork 60
Return posterior predictive samples from all chains in ModelBuilder
#140
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
Conversation
This fixes a bug where only values from one chain were returned. It also refactors the prediction logic to reduce duplication, and makes the output of predict_posterior() consistent in type and shape with the output of pymc.sample_posterior_predictive().
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.
Looks good, for the future reference please try not to just switch places of functions if it's not needed, as it makes the code changes less readable for PR
Thanks for the review @michaelraczycki. I've added |
ModelBuilder
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.
Looks good to me
Thanks @mbjoseph and for the review @michaelraczycki! |
…pymc-devs#140) * Return posterior predictive samples from all chains This fixes a bug where only values from one chain were returned. It also refactors the prediction logic to reduce duplication, and makes the output of predict_posterior() consistent in type and shape with the output of pymc.sample_posterior_predictive(). * keep attributes even when computing posterior means * Add/test combined arg, revert method order * Fix import order. --------- Co-authored-by: Max Joseph <[email protected]> Co-authored-by: Thomas Wiecki <[email protected]>
* docstrings update in model_builder.py * bringing back accidentally removed line from example * Return posterior predictive samples from all chains in `ModelBuilder` (#140) * Return posterior predictive samples from all chains This fixes a bug where only values from one chain were returned. It also refactors the prediction logic to reduce duplication, and makes the output of predict_posterior() consistent in type and shape with the output of pymc.sample_posterior_predictive(). * keep attributes even when computing posterior means * Add/test combined arg, revert method order * Fix import order. --------- Co-authored-by: Max Joseph <[email protected]> Co-authored-by: Thomas Wiecki <[email protected]> * fixing merge conflicts --------- Co-authored-by: Max Joseph <[email protected]> Co-authored-by: Max Joseph <[email protected]> Co-authored-by: Thomas Wiecki <[email protected]>
This fixes a bug where only values from one chain were returned. It also refactors the prediction logic to reduce duplication. I've used
arviz.extract()
to get the posterior predictive samples as hinted by @twiecki in #139, removing the_extract_samples()
method from the model builder class.Behavior change proposal
This PR also includes a proposed behavior change that makes the output of
predict_posterior()
consistent in type and shape with the output ofpymc.sample_posterior_predictive()
.Namely,
predict_posterior()
would here return an xarray Dataset from the posterior predictive distribution, rather than a dictionary of numpy arrays. This is an admittedly opinionated change in behavior, though it does also streamline the code. From my perspective, retaining the metadata related to chains, draws, and other attributes is useful for three key reasons:pymc.sample_posterior_predictive()
, which could make behavior easier to predict for users, and allow greater interoperability with other functions that process and plot posterior predictive samplesThat said, I'm very open to other perspectives on how to bundle up posterior predictive samples.