Skip to content

sample_prior_predictive(var_names=[...]) results in KeyError inside to_inferencedata() #5337

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

Closed
michaelosthege opened this issue Jan 10, 2022 · 0 comments · Fixed by #5338
Closed
Assignees
Labels
Milestone

Comments

@michaelosthege
Copy link
Member

michaelosthege commented Jan 10, 2022

Description of your problem

Please provide a minimal, self-contained, and reproducible example.

with pm.Model() as model:
    x = pm.Normal("x")
    y = pm.Normal("y", x, observed=5)
    idata = pm.sample(tune=10, draws=20, chains=1, step=pm.Metropolis())
    pm.sample_posterior_predictive(idata, var_names=["x"]) # 👈 this works fine
    pm.sample_prior_predictive(var_names=["x"])          # 👈 this doesn't

Please provide the full traceback.

Complete error traceback
KeyError                                  Traceback (most recent call last)
<ipython-input-12-46d00c82b13d> in <module>
      4     idata = pm.sample(tune=10, draws=20, chains=1, step=pm.Metropolis())
      5     pm.sample_posterior_predictive(idata)
----> 6     pm.sample_prior_predictive(var_names=["x"])

c:\users\osthege\repos\pymc-main\pymc\sampling.py in sample_prior_predictive(samples, model, var_names, random_seed, mode, return_inferencedata, idata_kwargs)
   2030     if idata_kwargs:
   2031         ikwargs.update(idata_kwargs)
-> 2032     return pm.to_inference_data(prior=prior, **ikwargs)
   2033 
   2034 

c:\users\osthege\repos\pymc-main\pymc\backends\arviz.py in to_inference_data(trace, prior, posterior_predictive, log_likelihood, coords, dims, model, save_warmup, density_dist_obs)
    587         return trace
    588 
--> 589     return InferenceDataConverter(
    590         trace=trace,
    591         prior=prior,

c:\users\osthege\repos\pymc-main\pymc\backends\arviz.py in to_inference_data(self)
    523             "posterior_predictive": self.posterior_predictive_to_xarray(),
    524             "predictions": self.predictions_to_xarray(),
--> 525             **self.priors_to_xarray(),
    526             "observed_data": self.observed_data_to_xarray(),
    527         }

c:\users\osthege\repos\pymc-main\pymc\backends\arviz.py in priors_to_xarray(self)
    442                 if var_names is None
    443                 else dict_to_dataset(
--> 444                     {k: np.expand_dims(self.prior[k], 0) for k in var_names},
    445                     library=pymc,
    446                     coords=self.coords,

c:\users\osthege\repos\pymc-main\pymc\backends\arviz.py in <dictcomp>(.0)
    442                 if var_names is None
    443                 else dict_to_dataset(
--> 444                     {k: np.expand_dims(self.prior[k], 0) for k in var_names},
    445                     library=pymc,
    446                     coords=self.coords,

KeyError: 'y'

Versions and main components

  • PyMC/PyMC3 Version: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant