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

sample_posterior_predictive does not consider changes in "ConstantData" and "Constant coords" #6876

Open
ricardoV94 opened this issue Aug 24, 2023 · 1 comment

Comments

@ricardoV94
Copy link
Member

Description

The existing checks assume the same model is used between sample and sample_posterior_predictive, in which case the only variable that can be changed are mutable ones.

However if one wants to sample in a new model (as described in https://www.pymc-labs.io/blog-posts/out-of-model-predictions-with-pymc/), they have to artificially use mutable variables even if they never intend to change them after definition:

import pymc as pm

with pm.Model() as m:
    x = pm.ConstantData("x", [0, 0, 0, 0, 0, 0])
    b = pm.Normal("b", x)
    y = pm.Normal("y", b.sum(), observed=0)
    idata = pm.sample()

with pm.Model() as pred_m:
    x = pm.ConstantData("x", [0, 0, 0])
    # x = pm.MutableData("x", [0, 0, 0])  # This works fine
    b = pm.Normal("b", x)
    y = pm.Normal("y", b.sum(), observed=0)
    idata = pm.sample_posterior_predictive(idata, predictions=True,)  # Fails because b isn't resampled

A similar thing happens for variables whose dims are changed. If they were defined in coords_mutable it will resample correctly, but not if they were defined as vanilla "constant" coords

@ricardoV94 ricardoV94 changed the title sample_posterior_predictive does not consider changes in "ConstatData" and "Constant coords" sample_posterior_predictive does not consider changes in "ConstantData" and "Constant coords" Oct 31, 2023
@ricardoV94
Copy link
Member Author

Related to #6977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant