Skip to content

Commit

Permalink
point to new warnings webpage
Browse files Browse the repository at this point in the history
closes #505
  • Loading branch information
jgabry committed Mar 10, 2022
1 parent 2ca8d76 commit 1c458ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
18 changes: 5 additions & 13 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ check_divergences <- function(post_warmup_sampler_diagnostics) {
"Warning: ", num_divergences, " of ", num_draws,
" (", (base::format(round(percentage_divergences, 0), nsmall = 1)), "%)",
" transitions ended with a divergence.\n",
"This may indicate insufficient exploration of the posterior distribution.\n",
"Possible remedies include: \n",
" * Increasing adapt_delta closer to 1 (default is 0.8) \n",
" * Reparameterizing the model (e.g. using a non-centered parameterization)\n",
" * Using informative or weakly informative prior distributions \n"
"See https://mc-stan.org/misc/warnings for details.\n"
)
}
}
Expand All @@ -273,11 +269,8 @@ check_max_treedepth <- function(post_warmup_sampler_diagnostics, metadata) {
percentage_max_treedepths <- 100 * num_max_treedepths / num_draws
message(
"Warning: ", num_max_treedepths, " of ", num_draws, " (", (base::format(round(percentage_max_treedepths, 0), nsmall = 1)), "%)",
" transitions hit the maximum treedepth limit of ", metadata$max_treedepth,
" or 2^", metadata$max_treedepth, "-1 leapfrog steps.\n",
"Trajectories that are prematurely terminated due to this limit will result in slow exploration.\n",
"Increasing the max_treedepth limit can avoid this at the expense of more computation.\n",
"If increasing max_treedepth does not remove warnings, try to reparameterize the model.\n"
" transitions hit the maximum treedepth limit of ", metadata$max_treedepth,".\n",
"See https://mc-stan.org/misc/warnings for details.\n"
)
}
}
Expand Down Expand Up @@ -310,9 +303,8 @@ check_ebfmi <- function(post_warmup_sampler_diagnostics, threshold = 0.2) {
if (any(efbmi_per_chain < threshold)) {
message(
"Warning: ", sum(efbmi_per_chain < threshold), " of ", length(efbmi_per_chain),
" chains had energy-based Bayesian fraction of missing information (E-BFMI)",
" less than ", threshold, ".",
"\nThis may indicate poor exploration of the posterior.\n"
" chains had an E-BFMI less than ", threshold, ".\n",
"See https://mc-stan.org/misc/warnings for details.\n"
)
}
invisible(unname(efbmi_per_chain))
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test_that("check_divergences() works", {
test_that("check_max_treedepth() works", {
csv_files <- c(test_path("resources", "csv", "model1-2-no-warmup.csv"))
csv_output <- read_cmdstan_csv(csv_files)
output <- "16 of 100 \\(16.0%\\) transitions hit the maximum treedepth limit of 5 or 2\\^5-1 leapfrog steps."
output <- "16 of 100 \\(16.0%\\) transitions hit the maximum treedepth limit of 5."
expect_message(
max_tds <- check_max_treedepth(
csv_output$post_warmup_sampler_diagnostics,
Expand All @@ -61,7 +61,7 @@ test_that("check_max_treedepth() works", {
csv_files <- c(test_path("resources", "csv", "model1-2-no-warmup.csv"),
test_path("resources", "csv", "model1-2-no-warmup.csv"))
csv_output <- read_cmdstan_csv(csv_files)
output <- "32 of 200 \\(16.0%\\) transitions hit the maximum treedepth limit of 5 or 2\\^5-1 leapfrog steps."
output <- "32 of 200 \\(16.0%\\) transitions hit the maximum treedepth limit of 5."
expect_message(
max_tds <- check_max_treedepth(
csv_output$post_warmup_sampler_diagnostics,
Expand All @@ -72,7 +72,7 @@ test_that("check_max_treedepth() works", {

# force different number of max treedepths per chain just to test
csv_output$post_warmup_sampler_diagnostics[1, 1:2, "treedepth__"] <- c(1, 15)
output <- "31 of 200 \\(16.0%\\) transitions hit the maximum treedepth limit of 5 or 2\\^5-1 leapfrog steps."
output <- "31 of 200 \\(16.0%\\) transitions hit the maximum treedepth limit of 5."
expect_message(
max_tds <- check_max_treedepth(
csv_output$post_warmup_sampler_diagnostics,
Expand All @@ -83,7 +83,7 @@ test_that("check_max_treedepth() works", {

csv_files <- c(test_path("resources", "csv", "model1-2-warmup.csv"))
csv_output <- read_cmdstan_csv(csv_files)
output <- "1 of 100 \\(1.0%\\) transitions hit the maximum treedepth limit of 5 or 2\\^5-1 leapfrog steps."
output <- "1 of 100 \\(1.0%\\) transitions hit the maximum treedepth limit of 5."
expect_message(
check_max_treedepth(
csv_output$post_warmup_sampler_diagnostics,
Expand All @@ -102,7 +102,7 @@ test_that("check_ebfmi and computing ebfmi works", {
energy_df$energy__[i+1] <- energy_df$energy__[i] + rnorm(1, 0, 0.01)
}
energy_df <- posterior::as_draws(energy_df)
expect_message(check_ebfmi(energy_df), "fraction of missing information \\(E-BFMI\\) less than")
expect_message(check_ebfmi(energy_df), "had an E-BFMI less than")
energy_vec <- energy_df$energy__
check_val <- (sum(diff(energy_vec)^2) / length(energy_vec)) / stats::var(energy_vec)
expect_equal(as.numeric(ebfmi(energy_df)), check_val)
Expand Down

0 comments on commit 1c458ab

Please sign in to comment.