Closed tomicapretto closed 1 year ago
Try
pm.Normal("response", mu=mu, sigma=sigma, observed=y, shape=mu.shape)
Now it works! But is this the way one expects to use this from now?
Yes, if you don't specify shape or dims explicitly it defaults to shape=observed.shape
, in which case you would need to update observed
to a dummy value with the correct shape.
It's mentioned in the docstring examples of set_data
I think I understand the underlying reason, but I still think it's a little weird to behave like that at a high level.
When you compute predictions for new observations (there's a new set of predictor values), and given the posterior draws, the original observed values do not play any role in the prediction.
Is it expected this feature to keep the same behavior in the future? If that's the case, we could close this issue and I'll just adapt my code so it works.
Yes I think this will likely stay.
It's not that we are explicitly checking the shape, it's that the model variable that is first created is something like pm.Normal.dist(mu, shape=(10,))
where mu
has shape==(10,)
. Later mu
is changed to have shape==(4,)
, but nothing is done about the shape of the distribution, which results in an invalid graph.
You must tell PyMC that the shape is tied to the shape of the mu
parameter. We can't always assume this because the following is also valid:
with pm.Model() as m:
...
pm.Normal("llike", mu=[0], observed=[0, 0, 0])
The only safe assumption when nothing is told about shape and dims is that the shape of an observed variable must match the shape of its observations at creation time.
Thanks @ricardoV94 !!
Describe the issue:
I'm using
pm.sample_posterior_predictive()
withpredictions=True
to get draws from the posterior predictive distribution for out-of-sample data and it's not working. From what I understand from the traceback, there's a shape mismatch between the data for the predictors and the response. The problem is the responses are not observed for out-of-sample data, so it does not make sense to compare them.Reproduceable code example:
Error message:
PyMC version information:
It worked until PyMC 4.1.7