arviz_stats.SamplingWrapper#
- class arviz_stats.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.
- Parameters:
- model
The model object used for sampling.
- idata_origoptional
Original inference data object (InferenceData or datatree).
- log_lik_fun
callable, 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_likelihoodmethod must be implemented. It’s callback must belog_lik_fun(*args, **log_lik_kwargs)and will be called usingwrap_xarray_ufuncorxarray.apply_ufuncdepending on the value of is_ufunc.For more details on
argsorlog_lik_kwargssee the notes and parametersposterior_varsandlog_lik_kwargs.- is_ufuncbool, default
True If True, call
log_lik_funusingxarray.apply_ufuncotherwise usewrap_xarray_ufunc.- posterior_vars
listofstr, optional List of variable names to unpack as
argsforlog_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_kwargs
dict, optional Sampling kwargs are stored as class attributes for their usage in the
samplemethod.- idata_kwargs
dict, optional kwargs are stored as class attributes to be used in the
get_inference_datamethod.- log_lik_kwargs
dict, optional Keyword arguments passed to
log_lik_fun.- apply_ufunc_kwargs
dict, optional Passed to
xarray.apply_ufuncorwrap_xarray_ufunc.
- __init__(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]#
Methods
__init__(model[, idata_orig, log_lik_fun, ...])check_implemented_methods(methods)Check that all methods listed are implemented.
get_inference_data(fitted_model)Convert the
fitted_modelto an InferenceData object.log_likelihood__i(excluded_obs, idata__i)Get the log likelilhood samples \(\log p_{post(-i)}(y_i)\).
sample(modified_observed_data)Sample
self.modelon themodified_observed_datasubset.sel_observations(idx)Select a subset of the observations in idata_orig.