arviz.SamplingWrapper#
- class arviz.SamplingWrapper(model, idata_orig=None, log_lik_fun=None, is_ufunc=True, posterior_vars=None, sample_kwargs=None, idata_kwargs=None, log_lik_kwargs=None, apply_ufunc_kwargs=None)[source]#
Class wrapping sampling routines for its usage via ArviZ.
Using a common class, all inference backends can be supported in ArviZ. Hence, statistical functions requiring refitting like Leave Future Out or Simulation Based Calibration can be performed from ArviZ.
For usage examples see user guide pages on Sampling wrappers.See other SamplingWrapper classes at wrappers api section.
- Parameters
- model
The model object used for sampling.
- idata_origInferenceData, optional
Original InferenceData object.
- log_lik_funcallable, optional
For simple cases where the pointwise log likelihood is a Python function, this function will be used to calculate the log likelihood. Otherwise,
point_log_likelihood
method must be implemented. It’s callback must belog_lik_fun(*args, **log_lik_kwargs)
and will be called usingwrap_xarray_ufunc()
orxarray.apply_ufunc()
depending on the value ofis_ufunc
.For more details on
args
orlog_lik_kwargs
see the notes and parametersposterior_vars
andlog_lik_kwargs
.- is_ufuncbool, default True
If True, call
log_lik_fun
usingxarray.apply_ufunc()
otherwise usewrap_xarray_ufunc()
.- posterior_varslist of str, optional
List of variable names to unpack as
args
forlog_lik_fun
. Each string in the list will be used to retrieve a DataArray from the Dataset in the posterior group and passed tolog_lik_fun
.- sample_kwargsdict, optional
Sampling kwargs are stored as class attributes for their usage in the
sample
method.- idata_kwargsdict, optional
kwargs are stored as class attributes to be used in the
get_inference_data
method.- log_lik_kwargsdict, optional
Keyword arguments passed to
log_lik_fun
.- apply_ufunc_kwargsdict, optional
Passed to
xarray.apply_ufunc()
orwrap_xarray_ufunc()
.
Warning
Sampling wrappers are an experimental feature in a very early stage. Please use them with caution.
Notes
Example of
log_like_fun
usage.Methods
SamplingWrapper.__init__
(model[, ...])Check that all methods listed are implemented.
SamplingWrapper.get_inference_data
(fitted_model)Convert the
fitted_model
to an InferenceData object.Get the log likelilhood samples \(\log p_{post(-i)}(y_i)\).
SamplingWrapper.sample
(modified_observed_data)Sample
self.model
on themodified_observed_data
subset.Select a subset of the observations in idata_orig.