Closed
Description
As discussed with @ricardoV94, currently, we can change observations with the do
operator only for a model that has no observations, i.e only free or deterministic variables:
Before
# define model
with pm.Model() as m:
x = pm.MutableData("x", np.linspace(-5, 5, 50))
b0 = pm.Normal("b0")
b1 = pm.Normal("b1")
noise = pm.HalfNormal("noise")
y = pm.Normal("y", pm.math.sigmoid(b0 + b1 * x), sigma=noise, observed=np.random.randn(50))
# generate new observations, e.g for parameter-recovery study
with pm.do(m, {noise: 1.0}) as prior_m:
prior_pred = pm.sample_prior_predictive(1).isel(chain=0, draw=0)
# run inference with these new observations
with pm.observe(m, {y: prior_pred.prior_predictive["y"]}) as observed_m:
posterior = pm.sample()
# this raises
ValueError: At least one var is not a free variable or deterministic in the model
After
Being able to do the above