DOC: add out-of-sample predictions subsection to NumPyro conversion guide#178
DOC: add out-of-sample predictions subsection to NumPyro conversion guide#178Shlokpalrecha wants to merge 1 commit into
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Documentation build overview
Show files changed (14 files in total): 📝 14 modified | ➕ 0 added | ➖ 0 deleted
|
|
|
||
|
|
||
| def _check_tilde_start(x): | ||
| """Check whether an item starts with the negation prefix. |
There was a problem hiding this comment.
Is there any reason why youre making changes to the utils file?
I think it would be best to keep this PR scoped to just the conversion guide
| @@ -121,12 +121,12 @@ | |||
| "name": "stderr", | |||
There was a problem hiding this comment.
Line #2. sigma_pool = rng.uniform(8.0, 18.0, size=3)
the two line sampling procedure isnt really necessary, you can just hard code a few sigma values or sample them in 1 line instead of two
Reply via ReviewNB
| @@ -121,12 +121,12 @@ | |||
| "name": "stderr", | |||
There was a problem hiding this comment.
Line #3. sigma_oos = rng.choice(sigma_pool, size=J, replace=True)
lets choose a different number of schools to make predictions on than 8 to avoid confusion. maybe just 3?
Reply via ReviewNB
| @@ -121,12 +121,12 @@ | |||
| "name": "stderr", | |||
There was a problem hiding this comment.
Line #2. idata_mcmc_oos.predictions_constant_data
you can remove this cell, its covered by the last cell which returns idata_mcmc_oos
Reply via ReviewNB
There was a problem hiding this comment.
I removed that redundant cell and now only return idata_mcmc_oos in this section.
|
Thanks, updated. I removed unrelated scope from this PR, simplified the sigma sampling, switched to 3-school out-of-sample predictions to avoid confusion, and removed the redundant display cell |
Im not seeing those changes reflected here - maybe check if you pushed the correct commit? |
| @@ -35,7 +35,7 @@ | |||
| }, | |||
There was a problem hiding this comment.
This reads more like a PR review than a tutorial page. How about something like:
A common scenario is to generate predictions for newly obtained data or data that was excluded from the fit. The InferenceData schema has a predictions group to hold this kind of posterior predictive samples.This example shows how posterior predictive samples generated for newly obtained values of sigma can be incorporated into the generated DataTree
Reply via ReviewNB
| @@ -35,7 +35,7 @@ | |||
| }, | |||
There was a problem hiding this comment.
sigma_model = np.random.default_rng(2026).choice(np.array([9.0, 12.0, 16.0]), size=J, replace=True)
I think this is still overly complicated and using model in the variable name is potentially confusing. The other variables called model are the functions that do encode a probabilistic model. This could be something like: new_sigma = np.array([-2.0, 7.0, 17.0])
predictions_oos_full = predictive_oos(random.PRNGKey(2), J=J, sigma=sigma_model)
I have barely used numpyro but doing this here with J=8 and then having to index seems again too complicated, this is a very common usecase. My guess is this can be simplified to ..., J=3, sigma=new_sigma) which in turn will allow deleting lines 6-8 and using the output of predictive_oos directly as the predictions argument. I think this is what @kylejcaron was asking for in the previous review round.
Reply via ReviewNB
There was a problem hiding this comment.
Thanks, agreed. I simplified this section accordingly in docs/source/how_to/ConversionGuideNumPyro.ipynb:
renamed to new_sigma,
switched to direct J=3 predictions call,
removed the previous indexing-heavy flow.
I also adjusted the predictive setup so the simplified example runs cleanly while keeping the tutorial code straightforward.
655e6f6 to
ec46b02
Compare
|
Apologies for the earlier confusion with what was visible in the PR. I’ve now pushed the corrected branch state and aligned the section with all review points: |
| @@ -35,7 +35,7 @@ | |||
| }, | |||
There was a problem hiding this comment.
Line #1. sigma_model = np.random.default_rng(2026).choice(np.array([9.0, 12.0, 16.0]), size=J, replace=True)
Theres no reason to do sampling with replacement here, and you end up with size J=8 instead of J=3 which would be better
you can just hardcode sigma to a size 3 array
Reply via ReviewNB
| @@ -35,7 +35,7 @@ | |||
| }, | |||
There was a problem hiding this comment.
Line #3. predictive_oos = Predictive(eight_schools_model, mcmc.get_samples())
mcmc.get_samples() contains theta from the fitted schools.
Our goal is to estimate theta for 3 new schools. One of the possible correct patterns for numpyro here would be:
post_samples = mcmc.get_samples()
post_samples.pop("theta") # remove theta so it can be estimated for new schools
predictive_oos = Predictive(eight_schools_model, post_samples)
Reply via ReviewNB
Context
This PR adds the missing out-of-sample predictions example requested in arviz-base issue #2452, following guidance from @OriolAbril.
What this adds
mcmcobject already present in the notebook.y.predictions=...predictions_constant_data={"sigma": sigma_oos}idata_mcmc_oos.predictionsidata_mcmc_oos.predictions_constant_dataValidation
tox -e checkpassed locally.