Closed zaxtax closed 9 months ago
Definitely the second, I don't think a user should have to remember to call the helper. In the previous we also deal with coords transparently.
I prefer the second. As long as it works for coords_mutable
(and whatever other args we need) too.
You may have no need for coords_mutable
with as_model
since you can just build a different model with fixed coords for posterior predictive, as shown above with m_train
and m_test
Hmm, I think I'd rather keep the one model. Unless my current workflow is bad practice or I've missed the point:
m = model(data=data, coords=coords)
idata = pm.sample(
model=m,
return_inferencedata=True,
)
idata.extend(pm.sample_posterior_predictive(idata, model=m, predictions=False))
pm.set_data(new_data=data_predict, model=m)
idata.extend(pm.sample_posterior_predictive(idata, model=m, predictions=True))
tbf, I guess replacing the set_data
line isn't a killer. Might be easier to keep track of one m
though. Coming from R
(sorry), I prefer one m
: predict(m, newdata = new_data)
I'm starting to appreciate @ricardoV94 's approach of simply having a prediction model that uses the trace of the fitted model, and not have to worry about changing coords.
I'm confused by the example above -- m_train
and m_test
appear to be two entirely separate model instances, with no shared parameters. How is m_test
getting the trained parameters?
How is m_test getting the trained parameters?
That would happen when calling pm.sample_posterior_predictive with the idata from sampling
So the missing steps are:
trace = pm.sample(model=m_train)
pm.sample_posterior_predictive(trace, model=m_test, extend_inferencedata=True)
The nice thing here is that it avoids having to set up placeholder vars when you build a separate prediction model.
Yeah, I like the second one.
Still in favor of the second.
Hmm, I think I'd rather keep the one model. Unless my current workflow is bad practice or I've missed the point:
m = model(data=data, coords=coords) idata = pm.sample( model=m, return_inferencedata=True, ) idata.extend(pm.sample_posterior_predictive(idata, model=m, predictions=False)) pm.set_data(new_data=data_predict, model=m) idata.extend(pm.sample_posterior_predictive(idata, model=m, predictions=True))
tbf, I guess replacing the
set_data
line isn't a killer. Might be easier to keep track of onem
though. Coming fromR
(sorry), I prefer onem
:predict(m, newdata = new_data)
With either of the above workflows your code can look like this:
m = model(data=data, coords=coords)
idata = pm.sample(model=m)
pm.sample_posterior_predictive(idata, model=m, predictions=False, extend_inferencedata=True)
m_new = model(data=data_predict, coords=new_coords)
pm.sample_posterior_predictive(idata, model=m_new, predictions=True, extend_inferencedata=True)
Thanks everyone for your feedback!
Since it's still new. The
as_model
decorator is nice, but for models wherecoords
would change it could have better ergonomics. I've explored using a helper methodadd_coords
But @ricardoV94 pointed out that we could return a function which took an additional
coords
orname
argument insteadI'm curious, which do people prefer?