pymc.sample_posterior_predictive#
- pymc.sample_posterior_predictive(trace, model=None, var_names=None, sample_dims=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)
- 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.
- sample_dims
list
ofstr
, optional Dimensions over which to loop and generate posterior predictive samples. When sample_dims is
None
(default) both “chain” and “draw” are considered sample dimensions. Only taken into account when trace is InferenceData or Dataset.- 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.pytensorf.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))
Generate 5 posterior predictive samples per posterior sample.
expanded_data = idata.posterior.expand_dims(pred_id=5) with model: idata.extend(pymc.sample_posterior_predictive(expanded_data))