Skip to content

Commit 0e3a99a

Browse files
authored
Merge pull request #1015 from stan-dev/more-stable-r_eff
Improve stability of `r_eff` calculation for loo
2 parents 4c84a14 + b65e868 commit 0e3a99a

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

R/fit.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,9 @@ unconstrain_draws <- function(files = NULL, draws = NULL,
574574
} else {
575575
draws <- self$draws(inc_warmup = inc_warmup)
576576
}
577-
577+
578578
draws <- maybe_convert_draws_format(draws, "draws_matrix")
579-
579+
580580
chains <- posterior::nchains(draws)
581581

582582
model_par_names <- self$metadata()$stan_variables[self$metadata()$stan_variables != "lp__"]
@@ -595,7 +595,7 @@ unconstrain_draws <- function(files = NULL, draws = NULL,
595595
uncon_names <- private$model_methods_env_$unconstrained_param_names(private$model_methods_env_$model_ptr_, FALSE, FALSE)
596596
names(unconstrained) <- repair_variable_names(uncon_names)
597597
unconstrained$.nchains <- chains
598-
598+
599599
do.call(function(...) { create_draws_format(format, ...) }, unconstrained)
600600
}
601601
CmdStanFit$set("public", name = "unconstrain_draws", value = unconstrain_draws)
@@ -1539,7 +1539,7 @@ loo <- function(variables = "log_lik", r_eff = TRUE, moment_match = FALSE, ...)
15391539
if (is.logical(r_eff)) {
15401540
if (isTRUE(r_eff)) {
15411541
r_eff_cores <- list(...)[["cores"]] %||% getOption("mc.cores", 1)
1542-
r_eff <- loo::relative_eff(exp(LLarray), cores = r_eff_cores)
1542+
r_eff <- loo::relative_eff(exp(LLarray + max(-LLarray)), cores = r_eff_cores)
15431543
} else {
15441544
r_eff <- NULL
15451545
}

0 commit comments

Comments
 (0)