Split moment matching for efficient approximate leave-one-out cross-validation (LOO)
Source:R/split_moment_matching.R
loo_moment_match_split.RdA function that computes the split moment matching importance sampling loo. Takes in the moment matching total transformation, transforms only half of the draws, and computes a single elpd using multiple importance sampling.
Usage
loo_moment_match_split(
x,
upars,
cov,
total_shift,
total_scaling,
total_mapping,
i,
log_prob_upars,
log_lik_i_upars,
r_eff_i,
cores,
is_method,
...
)Arguments
- x
A fitted model object.
- upars
A matrix containing the model parameters in unconstrained space where they can have any real value.
- cov
Logical; Indicate whether to match the covariance matrix of the samples or not. If
FALSE, only the mean and marginal variances are matched.- total_shift
A vector representing the total shift made by the moment matching algorithm.
- total_scaling
A vector representing the total scaling of marginal variance made by the moment matching algorithm.
- total_mapping
A vector representing the total covariance transformation made by the moment matching algorithm.
- i
Observation index.
- log_prob_upars
A function that takes arguments
xanduparsand returns a matrix of log-posterior density values of the unconstrained posterior draws passed viaupars.- log_lik_i_upars
A function that takes arguments
x,upars, andiand returns a vector of log-likeliood draws of theith observation based on the unconstrained posterior draws passed viaupars.- r_eff_i
MCMC relative effective sample size of the
i'th log likelihood draws.- cores
The number of cores to use for parallelization. This defaults to the option
mc.coreswhich can be set for an entire R session byoptions(mc.cores = NUMBER). The old optionloo.coresis now deprecated but will be given precedence overmc.coresuntilloo.coresis removed in a future release. As of version 2.0.0 the default is now 1 core ifmc.coresis not set, but we recommend using as many (or close to as many) cores as possible.Note for Windows 10 users: it is strongly recommended to avoid using the
.Rprofilefile to setmc.cores(using thecoresargument or settingmc.coresinteractively or in a script is fine).
- is_method
The importance sampling method to use. The following methods are implemented:
- ...
Further arguments passed to the custom functions documented above.
Value
A list containing the updated log-importance weights and log-likelihood values. Also returns the updated MCMC effective sample size and the integrand-specific log-importance weights.
References
Paananen, T., Piironen, J., Buerkner, P.-C., Vehtari, A. (2021). Implicitly adaptive importance sampling. Statistics and Computing, 31, 16. doi:10.1007/s11222-020-09982-2. arXiv preprint arXiv:1906.08850.