Skip to content

Refactor sample_posterior_predictive_w for V4 #5800

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pymc/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2032,8 +2032,6 @@ def sample_posterior_predictive_w(
weighted models (default), or a dictionary with variable names as keys, and samples as
numpy arrays.
"""
raise NotImplementedError(f"sample_posterior_predictive_w has not yet been ported to PyMC 4.0.")

if isinstance(traces[0], InferenceData):
n_samples = [
trace.posterior.sizes["chain"] * trace.posterior.sizes["draw"] for trace in traces
Expand Down Expand Up @@ -2140,13 +2138,13 @@ def sample_posterior_predictive_w(
# TODO sample_posterior_predictive_w is currently only work for model with
# one observed.
# XXX: This needs to be refactored
# ppc[var.name].append(draw_values([var], point=param, size=size[idx])[0])
raise NotImplementedError()
ppcl[var.name].append(draw([var])[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be conditioned on the posterior samples.

You will have to create a custom function similarly to what sample_posterior_predictive does. See recent changes in #5759

Copy link
Member

@ricardoV94 ricardoV94 May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might also be useful to compare what changed between V3 and V4 in sample_posterior_predictive because some of the things in sample_posterior_predictive_w might no longer be needed / make sense


except KeyboardInterrupt:
pass
else:
ppcd = {k: np.asarray(v) for k, v in ppcl.items()}
return ppcd
if not return_inferencedata:
return ppcd
ikwargs: Dict[str, Any] = dict(model=models)
Expand Down
3 changes: 0 additions & 3 deletions pymc/tests/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,6 @@ def test_deterministics_out_of_idata(self, multitrace):
assert np.all(np.abs(ppc.posterior_predictive.c + 4) <= 0.1)


@pytest.mark.xfail(
reason="sample_posterior_predictive_w not refactored for v4", raises=NotImplementedError
)
class TestSamplePPCW(SeededTest):
def test_sample_posterior_predictive_w(self):
data0 = np.random.normal(0, 1, size=50)
Expand Down