sis {loo} | R Documentation |
Standard importance sampling (SIS)
Description
Implementation of standard importance sampling (SIS).
Usage
sis(log_ratios, ...)
## S3 method for class 'array'
sis(log_ratios, ..., r_eff = NULL, cores = getOption("mc.cores", 1))
## S3 method for class 'matrix'
sis(log_ratios, ..., r_eff = NULL, cores = getOption("mc.cores", 1))
## Default S3 method:
sis(log_ratios, ..., r_eff = NULL)
Arguments
log_ratios |
An array, matrix, or vector of importance ratios on the log scale (for Importance sampling LOO, these are negative log-likelihood values). See the Methods (by class) section below for a detailed description of how to specify the inputs for each method. |
... |
Arguments passed on to the various methods. |
r_eff |
Vector of relative effective sample size estimates containing
one element per observation. The values provided should be the relative
effective sample sizes of |
cores |
The number of cores to use for parallelization. This defaults to
the option
|
Value
The sis()
methods return an object of class "sis"
,
which is a named list with the following components:
log_weights
-
Vector or matrix of smoothed but unnormalized log weights. To get normalized weights use the
weights()
method provided for objects of classsis
. diagnostics
-
A named list containing one vector:
-
pareto_k
: Not used insis
, all set to 0. -
n_eff
: effective sample size estimates.
-
Objects of class "sis"
also have the following attributes:
norm_const_log
-
Vector of precomputed values of
colLogSumExps(log_weights)
that are used internally by theweights
method to normalize the log weights. r_eff
-
If specified, the user's
r_eff
argument. tail_len
-
Not used for
sis
. dims
-
Integer vector of length 2 containing
S
(posterior sample size) andN
(number of observations). method
-
Method used for importance sampling, here
sis
.
Methods (by class)
-
sis(array)
: AnI
byC
byN
array, whereI
is the number of MCMC iterations per chain,C
is the number of chains, andN
is the number of data points. -
sis(matrix)
: AnS
byN
matrix, whereS
is the size of the posterior sample (with all chains merged) andN
is the number of data points. -
sis(default)
: A vector of lengthS
(posterior sample size).
References
Vehtari, A., Gelman, A., and Gabry, J. (2017). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. Statistics and Computing. 27(5), 1413–1432. doi:10.1007/s11222-016-9696-4 (journal version, preprint arXiv:1507.04544).
Vehtari, A., Simpson, D., Gelman, A., Yao, Y., and Gabry, J. (2024). Pareto smoothed importance sampling. Journal of Machine Learning Research, 25(72):1-58. PDF
See Also
-
psis()
for approximate LOO-CV using PSIS. -
loo()
for approximate LOO-CV. -
pareto-k-diagnostic for PSIS diagnostics.
Examples
log_ratios <- -1 * example_loglik_array()
r_eff <- relative_eff(exp(-log_ratios))
sis_result <- sis(log_ratios, r_eff = r_eff)
str(sis_result)
# extract smoothed weights
lw <- weights(sis_result) # default args are log=TRUE, normalize=TRUE
ulw <- weights(sis_result, normalize=FALSE) # unnormalized log-weights
w <- weights(sis_result, log=FALSE) # normalized weights (not log-weights)
uw <- weights(sis_result, log=FALSE, normalize = FALSE) # unnormalized weights