Skip to content

Commit

Permalink
Clean up sample_prior_predictive
Browse files Browse the repository at this point in the history
Since model_builder must create model object and set data, data only
needs to be set if model object already exists and no need to check for
model object before sampling.
  • Loading branch information
pdb5627 committed Oct 7, 2023
1 parent 299dabc commit 56293c0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pymc_experimental/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,17 +601,16 @@ def sample_prior_predictive(

if self.model is None:
self.build_model(X_pred, y_pred)

self._data_setter(X_pred, y_pred)
if self.model is not None:
with self.model: # sample with new input data
prior_pred: az.InferenceData = pm.sample_prior_predictive(samples, **kwargs)
self.set_idata_attrs(prior_pred)
if extend_idata:
if self.idata is not None:
self.idata.extend(prior_pred)
else:
self.idata = prior_pred
else:
self._data_setter(X_pred, y_pred)
with self.model: # sample with new input data
prior_pred: az.InferenceData = pm.sample_prior_predictive(samples, **kwargs)
self.set_idata_attrs(prior_pred)
if extend_idata:
if self.idata is not None:
self.idata.extend(prior_pred)
else:
self.idata = prior_pred

prior_predictive_samples = az.extract(prior_pred, "prior_predictive", combined=combined)

Expand Down

0 comments on commit 56293c0

Please sign in to comment.