-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
Description of your problem
Please provide a minimal, self-contained, and reproducible example.
First making a basic example demonstrating the expected result. I have a model, I make a change to the data using pm.set_data, and I expect the posterior predictive to reflect that change. Here I simply change the shape of the data from 100 to 3, and check that the shape of the posterior predictive matches. Everything works as expected.
>>> import numpy as np
>>> import pymc as pm
>>>
>>> raw_data = np.random.default_rng().normal(loc=30, size=100)
>>> fit_data = raw_data + 2
>>> with pm.Model(coords={"index": list(range(raw_data.shape[0]))}) as >>> model:
>>> alpha = pm.Normal("alpha", mu=0, sd=1)
>>> shared_data = pm.MutableData("shared_data", value=raw_data)
>>> pm.Normal("normal", mu=alpha + shared_data, observed=fit_data)
>>>
>>> idata = pm.sample(return_inferencedata=True)
>>> pm.set_data({"shared_data": [1.0, 2.0, 1.0]})
>>> pp_idata = pm.sample_posterior_predictive(idata, predictions=True)
>>>
>>> pp_idata["predictions"]["normal"].shape
(4, 1000, 3)Now, I run almost the exact same snippet as above, except I wrap alpha + shared_data in pm.Deterministic. The rest is identical. Now, when I check the posterior predictive, the values no longer seem to be affected by pm.set_data, and the shape is still 100.
>>> import numpy as np
>>> import pymc as pm
>>>
>>> raw_data = np.random.default_rng().normal(loc=30, size=100)
>>> fit_data = raw_data + 2
>>> with pm.Model(coords={"index": list(range(raw_data.shape[0]))}) as model:
>>> alpha = pm.Normal("alpha", mu=0, sd=1)
>>> shared_data = pm.MutableData("shared_data", value=raw_data)
>>> mu = pm.Deterministic("mu", alpha + shared_data) # New line!
>>> pm.Normal("normal", mu=mu, observed=fit_data)
>>>
>>> idata = pm.sample(return_inferencedata=True)
>>> pm.set_data({"shared_data": [1.0, 2.0, 1.0]})
>>> pp_idata = pm.sample_posterior_predictive(idata, predictions=True)
>>>
>>> pp_idata["predictions"]["normal"].shape
(4, 1000, 100)Versions and main components
ricardoV94
Metadata
Metadata
Assignees
Labels
No labels