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

Auto generated dimensions in posterior predictive don't match with observed dimensions #7572

Open
lucianopaz opened this issue Nov 13, 2024 · 1 comment · May be fixed by arviz-devs/arviz#2395
Labels

Comments

@lucianopaz
Copy link
Contributor

lucianopaz commented Nov 13, 2024

Describe the issue:

When a dimension is left unnamed, pymc will auto generate the dimension's name based on the tensor's name and the axis number. The problem is that pymc.sample_posterior_predictive returns a dimension name that is not aligned with what one gets in the observed_data group.

Reproduceable code example:

import pymc as pm

with pm.Model():
    a = pm.Normal("a")
    b = pm.Normal("b", a, observed=[-1, 2, 4])
    idata = pm.sample()
    idata.extend(pm.sample_prior_predictive())
    idata = pm.sample_posterior_predictive(idata, extend_inferencedata=True)

assert idata.observed_data.b.dims == idata.prior_predictive.b.dims[2:]  # This works!
assert idata.observed_data.b.dims == idata.posterior_predictive.b.dims[2:]  # This fails

Error message:

It's a simple `AssertionError`. The telling thing is that the posterior predictive group gets a wrong imputed name because it doesn't ignore the chain and draw dimensions


>>> print(idata.observed_data.b.dims, idata.prior_predictive.b.dims, idata.posterior_predictive.b.dims)
('b_dim_0',) ('chain', 'draw', 'b_dim_0') ('chain', 'draw', 'b_dim_2')

PyMC version information:

PyMC main

Context for the issue:

No response

@lucianopaz
Copy link
Contributor Author

@OriolAbril, could you have a look at this? I opened a PR over at arviz trying to fix it

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.

1 participant