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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants