Skip to content

Commit

Permalink
remove extra parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabry committed Aug 5, 2024
1 parent e2d7c7f commit 568f29b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/loo_model_weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ stacking_weights <-
negative_log_score_loo <- function(w) {
# objective function: log score
stopifnot(length(w) == K - 1)
w_full <- (c(w, 1 - sum(w)))
w_full <- c(w, 1 - sum(w))
# avoid over- and underflows using log weights and rowLogSumExps
sum <- sum(matrixStats::rowLogSumExps(sweep(lpd_point[1:N,], 2, log(w_full), '+')))
return(-as.numeric(sum))
Expand All @@ -275,7 +275,7 @@ stacking_weights <-
# and by subtracting the row maximum of lpd_point
mlpd <- matrixStats::rowMaxs(lpd_point)
for (k in 1:(K - 1)) {
grad[k] <- sum((exp(lpd_point[, k]-mlpd) - exp(lpd_point[, K]-mlpd)) / exp(matrixStats::rowLogSumExps(sweep(lpd_point, 2, log(w_full), '+'))-mlpd))
grad[k] <- sum((exp(lpd_point[, k] - mlpd) - exp(lpd_point[, K] - mlpd)) / exp(matrixStats::rowLogSumExps(sweep(lpd_point, 2, log(w_full), '+')) - mlpd))
}
return(-grad)
}
Expand Down

0 comments on commit 568f29b

Please sign in to comment.