Skip to content

Commit

Permalink
Fix issue #212 (#267)
Browse files Browse the repository at this point in the history
* Minor cleaning (the use of `[,]` makes things just more complicated as

dimensions could be dropped accidentally).

* Fix issue #212.
  • Loading branch information
fweber144 authored Jan 24, 2022
1 parent d7c64e4 commit a9ba38b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/cv_varsel.R
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,12 @@ loo_varsel <- function(refmodel, method, nterms_max, ndraws,
r_eff = rep(1, ncol(log_lik_sub)))
)
lw_sub <- suppressWarnings(loo::weights.importance_sampling(sub_psisloo))
loo_sub[[k]][inds] <- apply(log_lik_sub[,] + lw_sub[,], 2, log_sum_exp)
# Take into account that clustered draws usually have different weights:
lw_sub <- lw_sub + log(p_pred$weights)
# This re-weighting requires a re-normalization (as.array() is applied to
# have stricter consistency checks, see `?sweep`):
lw_sub <- sweep(lw_sub, 2, as.array(apply(lw_sub, 2, log_sum_exp)))
loo_sub[[k]][inds] <- apply(log_lik_sub + lw_sub, 2, log_sum_exp)
for (i in seq_along(inds)) {
mu_sub[[k]][inds[i]] <- mu_k[i, ] %*% exp(lw_sub[, i])
}
Expand Down

0 comments on commit a9ba38b

Please sign in to comment.