pymc.sample_posterior_predictive#
- pymc.sample_posterior_predictive(trace, samples=None, model=None, var_names=None, keep_size=None, random_seed=None, progressbar=True, return_inferencedata=True, extend_inferencedata=False, predictions=False, idata_kwargs=None, compile_kwargs=None)[source]#
Generate posterior predictive samples from a model given a trace.
- Parameters
- trace
backend
,list
,xarray.Dataset
,arviz.InferenceData
, orMultiTrace
Trace generated from MCMC sampling, or a list of dicts (eg. points or from find_MAP()), or xarray.Dataset (eg. InferenceData.posterior or InferenceData.prior)
- samples
int
Number of posterior predictive samples to generate. Defaults to one posterior predictive sample per posterior sample, that is, the number of draws times the number of chains.
It is not recommended to modify this value; when modified, some chains may not be represented in the posterior predictive sample. Instead, in cases when generating posterior predictive samples is too expensive to do it once per posterior sample, the recommended approach is to thin the
trace
argument before passing it tosample_posterior_predictive
. In such cases it might be advisable to setextend_inferencedata
toFalse
and extend the inferencedata manually afterwards.- model
Model
(optionalif
in
with
context
) Model to be used to generate the posterior predictive samples. It will generally be the model used to generate the
trace
, but it doesn’t need to be.- var_names
Iterable
[str
] Names of variables for which to compute the posterior predictive samples.
- keep_sizebool, default
True
Force posterior predictive sample to have the same shape as posterior and sample stats data:
(nchains, ndraws, ...)
. Overrides samples parameter.- random_seed
int
,RandomState
orGenerator
, optional Seed for the random number generator.
- progressbarbool
Whether or not to display a progress bar in the command line. The bar shows the percentage of completion, the sampling speed in samples per second (SPS), and the estimated remaining time until completion (“expected time of arrival”; ETA).
- return_inferencedatabool, default
True
Whether to return an
arviz.InferenceData
(True) object or a dictionary (False).- extend_inferencedatabool, default
False
Whether to automatically use
arviz.InferenceData.extend()
to add the posterior predictive samples totrace
or not. If True,trace
is modified inplace but still returned.- predictionsbool, default
False
Choose the function used to convert the samples to inferencedata. See
idata_kwargs
for more details.- idata_kwargs
dict
, optional Keyword arguments for
pymc.to_inference_data()
ifpredictions=False
or topymc.predictions_to_inference_data()
otherwise.- compile_kwargs: dict, optional
Keyword arguments for
pymc.aesaraf.compile_pymc()
.
- trace
- Returns
arviz.InferenceData
orDict
An ArviZ
InferenceData
object containing the posterior predictive samples (default), or a dictionary with variable names as keys, and samples as numpy arrays.
Examples
Thin a sampled inferencedata by keeping 1 out of every 5 draws before passing it to sample_posterior_predictive
thinned_idata = idata.sel(draw=slice(None, None, 5)) with model: idata.extend(pymc.sample_posterior_predictive(thinned_idata))