Skip to content

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

Closed
@ferrine

Description

@ferrine

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions