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

Posterior predictive doesn't resample intermediate Deterministics of intervened variables #6977

Open
ferrine opened this issue Oct 31, 2023 · 2 comments · May be fixed by #7596
Open

Posterior predictive doesn't resample intermediate Deterministics of intervened variables #6977

ferrine opened this issue Oct 31, 2023 · 2 comments · May be fixed by #7596
Labels

Comments

@ferrine
Copy link
Member

ferrine commented Oct 31, 2023

Describe the issue:

When sampling with do operator, Deterministics are injected from the trace and do operation gives no effect

Reproduceable code example:

with pm.Model() as model:
    a = pm.Normal("a")
    b = pm.Deterministic("b", a + 10)
    c = pm.Deterministic("c", b * 3)
    d = pm.Normal("d", c, observed=0)
with model:
    trace = pm.sample()
with pm.do(model, {"a": -100}):
    trace1 = pm.sample_posterior_predictive(trace, var_names=["c"])
# should raise an error since a is -100
np.testing.assert_allclose(trace1.posterior_predictive["c"], trace.posterior["c"])
with pm.do(model, {"a": -100}):
    trace1 = pm.sample_posterior_predictive(trace, var_names=["c", "b"])
# raises an error since a is -100
np.testing.assert_allclose(trace1.posterior_predictive["c"], trace.posterior["c"])

Error message:

...

PyMC version information:

5.9.1

Context for the issue:

No response

@ferrine ferrine added the bug label Oct 31, 2023
@ricardoV94
Copy link
Member

ricardoV94 commented Oct 31, 2023

That's really how posterior predictive works at the moment, it has nothing to do with the do operation.

If there's a variable with the same name in the trace that isn't being resampled it will be used in posterior predictive. In your case you need to include "b" in var_names

@ricardoV94
Copy link
Member

Tangentially related to #6876

@ricardoV94 ricardoV94 changed the title BUG: do operator and Deterministics work not as expected Posterior predictive doesn't resample intermediate Deterministics of intervened variables Oct 31, 2023
@ricardoV94 ricardoV94 linked a pull request Nov 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants