Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions R/loo_moment_matching.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,20 @@ loo_moment_match_i <- function(i,
# 1. match means
trans <- shift(x, uparsi, lwi)
# gather updated quantities
quantities_i <- update_quantities_i(x, trans$upars, i = i,
quantities_i <- try(update_quantities_i(x, trans$upars, i = i,
orig_log_prob = orig_log_prob,
log_prob_upars = log_prob_upars,
log_lik_i_upars = log_lik_i_upars,
r_eff_i = r_eff_i,
cores = 1,
is_method = is_method,
...)
)
if (inherits(quantities_i, "try-error")) {
# Stan log prob caused an exception probably due to under- or
# overflow of parameters to invalid values
break
}
if (quantities_i$ki < ki) {
uparsi <- trans$upars
total_shift <- total_shift + trans$shift
Expand All @@ -310,14 +316,20 @@ loo_moment_match_i <- function(i,
# 2. match means and marginal variances
trans <- shift_and_scale(x, uparsi, lwi)
# gather updated quantities
quantities_i <- update_quantities_i(x, trans$upars, i = i,
quantities_i <- try(update_quantities_i(x, trans$upars, i = i,
orig_log_prob = orig_log_prob,
log_prob_upars = log_prob_upars,
log_lik_i_upars = log_lik_i_upars,
r_eff_i = r_eff_i,
cores = 1,
is_method = is_method,
...)
)
if (inherits(quantities_i, "try-error")) {
# Stan log prob caused an exception probably due to under- or
# overflow of parameters to invalid values
break
}
if (quantities_i$ki < ki) {
uparsi <- trans$upars
total_shift <- total_shift + trans$shift
Expand All @@ -336,15 +348,21 @@ loo_moment_match_i <- function(i,
if (cov) {
trans <- shift_and_cov(x, uparsi, lwi)
# gather updated quantities
quantities_i <- update_quantities_i(x, trans$upars, i = i,
quantities_i <- try(update_quantities_i(x, trans$upars, i = i,
orig_log_prob = orig_log_prob,
log_prob_upars = log_prob_upars,
log_lik_i_upars = log_lik_i_upars,
r_eff_i = r_eff_i,
cores = 1,
is_method = is_method,
...)
)

if (inherits(quantities_i, "try-error")) {
# Stan log prob caused an exception probably due to under- or
# overflow of parameters to invalid values
break
}
if (quantities_i$ki < ki) {
uparsi <- trans$upars
total_shift <- total_shift + trans$shift
Expand Down