Skip to content

Prior predictions constant data #5723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pymc/backends/arviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ def __init__(
self.nchains = self.ndraws = 0

self.prior = prior
self.prior_predictions = None
if self.prior is not None:
self.prior_predictions = True

self.posterior_predictive = posterior_predictive
self.log_likelihood = log_likelihood
self.predictions = predictions
Expand Down Expand Up @@ -464,7 +468,7 @@ def observed_data_to_xarray(self):
default_dims=[],
)

@requires(["trace", "predictions"])
@requires(["trace", "predictions", "prior_predictions"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this prior predictions attribute is not needed, generating the constant data group here should be enough. IIUC, removing this line completely and leaving everything else untouched should be enough

@requires("model")
def constant_data_to_xarray(self):
"""Convert constant data to xarray."""
Expand Down
22 changes: 22 additions & 0 deletions pymc/tests/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,28 @@ def point_list_arg_bug_fixture() -> Tuple[pm.Model, pm.backends.base.MultiTrace]


class TestSamplePriorPredictive(SeededTest):
def test_idata_output(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test should be in idata_conversion. And I would try to avoid having a new test but instead checking for constant data in existing tests where it is currently missing

"""This test controls that returned idata
contains all expected groups"""

with pm.Model() as model:
x = pm.MutableData("x", [1, 2, 3])
y = pm.MutableData("y", [1.1, 1.9, 3.1])
a = pm.Normal("a", mu=1, sigma=1)
b = pm.Normal("b", mu=0, sigma=1)
mu = pm.Deterministic("mu", var=a * x + b)
obs = pm.Normal("obs", mu=mu, sigma=1, observed=y)
idata = pm.sample_prior_predictive(samples=10)

test_dict = {
"prior": ["a", "b", "mu"],
"prior_predictive": ["obs"],
"observed_data": ["obs"],
"constant_data": ["x", "y"],
}
fails = check_multiple_attrs(test_dict, idata)
assert not fails

def test_ignores_observed(self):
observed = np.random.normal(10, 1, size=200)
with pm.Model():
Expand Down