Skip to content

Commit 0297c96

Browse files
committed
minor edits
1 parent 9c27923 commit 0297c96

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

R/fit.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,10 @@ CmdStanMCMC <- R6::R6Class(
858858
} else {
859859
if (self$runset$args$validate_csv) {
860860
fixed_param <- runset$args$method_args$fixed_param
861-
private$read_csv_(variables = "",
862-
sampler_diagnostics = if (!fixed_param) c("treedepth__", "divergent__", "energy__") else "")
861+
private$read_csv_(
862+
variables = "",
863+
sampler_diagnostics = if (!fixed_param) c("treedepth__", "divergent__", "energy__") else ""
864+
)
863865
if (!fixed_param) {
864866
check_divergences(private$sampler_diagnostics_)
865867
check_sampler_transitions_treedepth(private$sampler_diagnostics_, private$metadata_)

R/utils.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ ebfmi <- function(post_warmup_sampler_diagnostics) {
282282
efbmi_val <- NULL
283283
if (!is.null(post_warmup_sampler_diagnostics)) {
284284
if (!("energy__" %in% posterior::variables(post_warmup_sampler_diagnostics))) {
285-
warning("E-BFMI not computed as the 'energy__' diagnostic could not be located.", call. = FALSE)
285+
warning("E-BFMI not computed because the 'energy__' diagnostic could not be located.", call. = FALSE)
286286
} else if (posterior::niterations(post_warmup_sampler_diagnostics) < 3) {
287-
warning("E-BFMI is undefined for posterior chains of length less than 3.", call. = FALSE)
287+
warning("E-BFMI not computed because it is undefined for posterior chains of length less than 3.", call. = FALSE)
288288
} else {
289289
energy <- posterior::extract_variable_matrix(post_warmup_sampler_diagnostics, "energy__")
290290
if (any(is.na(energy))) {
@@ -302,9 +302,12 @@ ebfmi <- function(post_warmup_sampler_diagnostics) {
302302
check_ebfmi <- function(post_warmup_sampler_diagnostics, threshold = 0.2) {
303303
efbmi_val <- ebfmi(post_warmup_sampler_diagnostics)
304304
if (any(efbmi_val < threshold)) {
305-
message(paste0(sum(efbmi_val < threshold), " of ", length(efbmi_val), " chains had energy-based Bayesian fraction ",
306-
"of missing information (E-BFMI) less than ", threshold, ", which may indicate poor exploration of the ",
307-
"posterior."))
305+
message(
306+
"Warning: ", sum(efbmi_val < threshold), " of ", length(efbmi_val),
307+
" chains had energy-based Bayesian fraction of missing information (E-BFMI)",
308+
" less than ", threshold, ".",
309+
"\nThis may indicate poor exploration of the posterior."
310+
)
308311
}
309312
invisible(NULL)
310313
}

tests/testthat/test-utils.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ test_that("check_ebfmi and computing ebfmi works", {
190190
expect_equal(as.numeric(ebfmi(posterior::as_draws_list(energy_df))), check_val)
191191
expect_equal(as.numeric(ebfmi(posterior::as_draws_matrix(energy_df))), check_val)
192192
energy_df <- posterior::as_draws(data.frame("energy__" = 0))
193-
expect_warning(check_ebfmi(energy_df), "E-BFMI is undefined for posterior chains of length less than 3.")
194-
expect_warning(ebfmi(energy_df), "E-BFMI is undefined for posterior chains of length less than 3.")
193+
expect_warning(check_ebfmi(energy_df), "E-BFMI not computed because it is undefined for posterior chains of length less than 3.")
194+
expect_warning(ebfmi(energy_df), "E-BFMI not computed because it is undefined for posterior chains of length less than 3.")
195195

196196
energy_df <- posterior::as_draws(data.frame("somethingelse" = 0))
197-
expect_warning(check_ebfmi(energy_df), "E-BFMI not computed as the 'energy__' diagnostic could not be located.")
198-
expect_warning(ebfmi(energy_df), "E-BFMI not computed as the 'energy__' diagnostic could not be located.")
197+
expect_warning(check_ebfmi(energy_df), "E-BFMI not computed because the 'energy__' diagnostic could not be located.")
198+
expect_warning(ebfmi(energy_df), "E-BFMI not computed because the 'energy__' diagnostic could not be located.")
199199

200200
})
201201

0 commit comments

Comments
 (0)