Repository navigation
Add classes to all loo warnings #417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,44 @@ | |
| #' diagnostics and effective sample size and Monte Carlo standard error | ||
| #' estimates. | ||
| #' | ||
| #' @section Warning classes: | ||
| #' | ||
| #' Every warning signaled by \pkg{loo} has the class `loo_warning` and one | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't 100% true yet because there are still three |
||
| #' class for its cause. Warnings that question the reliability of a result | ||
| #' also have the class `loo_warning_diagnostic`. Use these classes to handle | ||
| #' or muffle a specific warning, for example with [withCallingHandlers()] | ||
| #' and `invokeRestart("muffleWarning")`. | ||
| #' | ||
| #' Diagnostic warnings: | ||
| #' | ||
| #' * `loo_warning_pareto_k_high`: Some Pareto k values are too high. | ||
| #' * `loo_warning_pareto_tail_not_fitted`: There are not enough tail samples to | ||
| #' fit the generalized Pareto distribution. | ||
| #' * `loo_warning_pareto_tail_constant`: All tail values are the same. | ||
| #' * `loo_warning_p_waic_high`: Some `p_waic` estimates are greater than 0.4. | ||
| #' * `loo_warning_moment_match_failed`: Moment matching failed for some | ||
| #' observations. | ||
| #' * `loo_warning_moment_match_max_iters`: Moment matching reached | ||
| #' `max_iters`. | ||
| #' * `loo_warning_large_kf`: The accuracy of self-normalized importance | ||
| #' sampling may be bad. | ||
| #' * `loo_warning_y_mismatch`: The models do not have the same `y` variable. | ||
| #' * `loo_warning_cv_mismatch`: The models use different types of | ||
| #' cross-validation or different numbers of folds. | ||
| #' * `loo_warning_chance_difference`: The difference in performance is | ||
| #' potentially due to chance. | ||
| #' * `loo_warning_subsample_se`: A subsampling standard error is naive or | ||
| #' negative. | ||
|
Comment on lines
+68
to
+69
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class seems to cover two different causes: "Naive diff SE is used" from |
||
| #' | ||
| #' Other warnings: | ||
| #' | ||
| #' * `loo_warning_multicore_unavailable`: Multicore is not implemented for | ||
| #' the selected method. | ||
| #' * `loo_warning_pareto_k_not_plotted`: Some Pareto k values are `Inf`, `NA`, | ||
| #' or `NaN` and are not plotted. | ||
| #' * `loo_warning_llfun_not_matrix`: The values from `llfun` are not a matrix | ||
| #' and were coerced. | ||
| #' * `loo_warning_deprecated`: A deprecated feature was used. | ||
| #' | ||
| #' @template loo-and-psis-references | ||
| #' @template stacking-references | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -584,8 +584,8 @@ elpd_loo_approximation <- function(.llfun, data, draws, cores, loo_approximation | |
| } | ||
|
|
||
| p_eff_approx <- numeric(N) | ||
| if (cores>1) warning("Multicore is not implemented for waic_delta", | ||
| call. = FALSE) | ||
| if (cores>1) .warn("Multicore is not implemented for waic_delta", | ||
| class = "loo_warning_multicore_unavailable") | ||
|
|
||
| if (loo_approximation == "waic_grad") { | ||
| for(i in 1:nrow(data)) { | ||
|
|
@@ -1081,7 +1081,7 @@ loo_subsample_estimation_hh <- function(x) { | |
| if (hh_elpd_loo$hat_v_y_ppz > 0) { | ||
| x$estimates["elpd_loo", "SE"] <- sqrt(hh_elpd_loo$hat_v_y_ppz) | ||
| } else { | ||
| warning("Negative estimate of SE, more subsampling obs. needed.", call. = FALSE) | ||
| .warn_diagnostic("Negative estimate of SE, more subsampling obs. needed.", class = "loo_warning_subsample_se") | ||
| x$estimates["elpd_loo", "SE"] <- NaN | ||
| } | ||
| x$estimates["elpd_loo", "subsampling SE"] <- sqrt(hh_elpd_loo$v_hat_y_ppz) | ||
|
|
@@ -1091,7 +1091,7 @@ loo_subsample_estimation_hh <- function(x) { | |
| if (hh_p_loo$hat_v_y_ppz > 0) { | ||
| x$estimates["p_loo", "SE"] <- sqrt(hh_p_loo$hat_v_y_ppz) | ||
| } else { | ||
| warning("Negative estimate of SE, more subsampling obs. needed.", call. = FALSE) | ||
| .warn_diagnostic("Negative estimate of SE, more subsampling obs. needed.", class = "loo_warning_subsample_se") | ||
| x$estimates["elpd_loo", "SE"] <- NaN | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR, but I noticed it while reviewing: this line 1095 is in the |
||
| } | ||
| x$estimates["p_loo", "subsampling SE"] <- sqrt(hh_p_loo$v_hat_y_ppz) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's probably worth also mentioning that the base warning class changes to
rlang_warning. I'm guessing it doesn't affect anyone, but just in case.