pymc-examples icon indicating copy to clipboard operation
pymc-examples copied to clipboard

Error in log_gaussian_cox_process Notebook: TypeError: DictConverter.posterior_predictive is not a dictionary

Open tommy3001 opened this issue 1 year ago • 1 comments

Error in log_gaussian_cox_process Notebook: pymc-examples/examples/case_studies:

Issue description

When switching to PyMC v4.2.2 in log_gaussian_cox_process Notebook, I get in cell 19 with the call

spp_trace = pm.sample_posterior_predictive( trace, var_names=["log_intensity_new"], keep_size=True )

the following issue :


TypeError Traceback (most recent call last) Cell In [19], line 13 7 intensity_new = gp.conditional("log_intensity_new", Xnew=xy_new) 9 spp_trace = pm.sample_posterior_predictive( 10 trace, var_names=["log_intensity_new"], keep_size=True 11 ) 12 trace.extend( ---> 13 az.from_dict(posterior_predictive=spp_trace, dims={"log_intensity_new": ["sample"]}) 14 ) 15 intensity_samples = np.exp(trace.posterior_predictive["log_intensity_new"])

File ~/mambaforge/envs/pymc_env/lib/python3.10/site-packages/arviz/data/io_dict.py:460, in from_dict(posterior, posterior_predictive, predictions, sample_stats, log_likelihood, prior, prior_predictive, sample_stats_prior, observed_data, constant_data, predictions_constant_data, warmup_posterior, warmup_posterior_predictive, warmup_predictions, warmup_log_likelihood, warmup_sample_stats, save_warmup, index_origin, coords, dims, pred_dims, pred_coords, attrs, **kwargs) 353 def from_dict( 354 posterior=None, 355 *, (...) 378 **kwargs, 379 ): 380 """Convert Dictionary data into an InferenceData object. 381 382 For a usage example read the (...) 433 InferenceData 434 """ 435 return DictConverter( 436 posterior=posterior, 437 posterior_predictive=posterior_predictive, 438 predictions=predictions, 439 sample_stats=sample_stats, 440 log_likelihood=log_likelihood, 441 prior=prior, 442 prior_predictive=prior_predictive, 443 sample_stats_prior=sample_stats_prior, 444 observed_data=observed_data, 445 constant_data=constant_data, 446 predictions_constant_data=predictions_constant_data, 447 warmup_posterior=warmup_posterior, 448 warmup_posterior_predictive=warmup_posterior_predictive, 449 warmup_predictions=warmup_predictions, 450 warmup_log_likelihood=warmup_log_likelihood, 451 warmup_sample_stats=warmup_sample_stats, 452 save_warmup=save_warmup, 453 index_origin=index_origin, 454 coords=coords, 455 dims=dims, 456 pred_dims=pred_dims, 457 pred_coords=pred_coords, 458 attrs=attrs, 459 **kwargs, --> 460 ).to_inference_data()

File ~/mambaforge/envs/pymc_env/lib/python3.10/site-packages/arviz/data/io_dict.py:338, in DictConverter.to_inference_data(self) 327 def to_inference_data(self): 328 """Convert all available data to an InferenceData object. 329 330 Note that if groups can not be created, then the InferenceData 331 will not have those groups. 332 """ 333 return InferenceData( 334 **{ 335 "posterior": self.posterior_to_xarray(), 336 "sample_stats": self.sample_stats_to_xarray(), 337 "log_likelihood": self.log_likelihood_to_xarray(), --> 338 "posterior_predictive": self.posterior_predictive_to_xarray(), 339 "predictions": self.predictions_to_xarray(), 340 "prior": self.prior_to_xarray(), 341 "sample_stats_prior": self.sample_stats_prior_to_xarray(), 342 "prior_predictive": self.prior_predictive_to_xarray(), 343 "observed_data": self.observed_data_to_xarray(), 344 "constant_data": self.constant_data_to_xarray(), 345 "predictions_constant_data": self.predictions_constant_data_to_xarray(), 346 "save_warmup": self.save_warmup, 347 "attrs": self.attrs, 348 } 349 )

File ~/mambaforge/envs/pymc_env/lib/python3.10/site-packages/arviz/data/base.py:65, in requires.call..wrapped(cls) 63 if all((getattr(cls, prop_i) is None for prop_i in prop)): 64 return None ---> 65 return func(cls)

File ~/mambaforge/envs/pymc_env/lib/python3.10/site-packages/arviz/data/io_dict.py:192, in DictConverter.posterior_predictive_to_xarray(self) 190 data_warmup = self._init_dict(f"{WARMUP_TAG}posterior_predictive") 191 if not isinstance(data, dict): --> 192 raise TypeError("DictConverter.posterior_predictive is not a dictionary") 193 if not isinstance(data_warmup, dict): 194 raise TypeError("DictConverter.warmup_posterior_predictive is not a dictionary")

TypeError: DictConverter.posterior_predictive is not a dictionary

Therefore, the promised API compatibly to PyMC3 is not completely given. Which kind of code changes are necessary in the Notebook to get it run?

tommy3001 avatar Oct 28 '22 19:10 tommy3001