Skip to content

Commit 568f29b

Browse files
committed
remove extra parentheses
1 parent e2d7c7f commit 568f29b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

R/loo_model_weights.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ stacking_weights <-
260260
negative_log_score_loo <- function(w) {
261261
# objective function: log score
262262
stopifnot(length(w) == K - 1)
263-
w_full <- (c(w, 1 - sum(w)))
263+
w_full <- c(w, 1 - sum(w))
264264
# avoid over- and underflows using log weights and rowLogSumExps
265265
sum <- sum(matrixStats::rowLogSumExps(sweep(lpd_point[1:N,], 2, log(w_full), '+')))
266266
return(-as.numeric(sum))
@@ -275,7 +275,7 @@ stacking_weights <-
275275
# and by subtracting the row maximum of lpd_point
276276
mlpd <- matrixStats::rowMaxs(lpd_point)
277277
for (k in 1:(K - 1)) {
278-
grad[k] <- sum((exp(lpd_point[, k]-mlpd) - exp(lpd_point[, K]-mlpd)) / exp(matrixStats::rowLogSumExps(sweep(lpd_point, 2, log(w_full), '+'))-mlpd))
278+
grad[k] <- sum((exp(lpd_point[, k] - mlpd) - exp(lpd_point[, K] - mlpd)) / exp(matrixStats::rowLogSumExps(sweep(lpd_point, 2, log(w_full), '+')) - mlpd))
279279
}
280280
return(-grad)
281281
}

0 commit comments

Comments
 (0)