From 15dc777a3ef0388b4426879d93f5ac319abbe3c5 Mon Sep 17 00:00:00 2001 From: Matthew Kay Date: Tue, 7 May 2024 09:41:21 -0500 Subject: [PATCH 1/8] type check assertions for rvar draws, closes #363 --- R/rvar-.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/rvar-.R b/R/rvar-.R index 33db28fd..a74e42c9 100755 --- a/R/rvar-.R +++ b/R/rvar-.R @@ -800,6 +800,13 @@ drop_chain_dim <- function(x) { #' (first one is draws), etc. #' @noRd cleanup_rvar_draws <- function(x) { + assert( + check_numeric(x), + check_logical(x), + check_factor(x), + check_character(x) + ) + if (length(x) == 0) { # canonical NULL rvar is at least 1 draw of nothing # this ensures that (e.g.) extending a null rvar From b788e4f77b082248a51fe8fe49ead0257c0100da Mon Sep 17 00:00:00 2001 From: n-kall Date: Fri, 10 May 2024 10:08:29 +0300 Subject: [PATCH 2/8] update news --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 03f5a1a8..c61ba7d3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,10 @@ ### Enhancements +* Add `are_log_weights` option to `pareto_smooth`, which can improve + Pareto smoothing computation if the input are log weights. +* Add `exclude` option to `subset_draws`, which can be used to exclude + the matched selection. * Add `pareto_smooth` option to `weight_draws`, to Pareto smooth weights before adding to a draws object. * Matrix multiplication of `rvar`s can now be done with the base matrix From 050ce3e8386020b208834e10137ea3c6af48a58f Mon Sep 17 00:00:00 2001 From: n-kall Date: Fri, 10 May 2024 10:11:57 +0300 Subject: [PATCH 3/8] add thin_draws updates to news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index c61ba7d3..16b23dd1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,8 @@ the matched selection. * Add `pareto_smooth` option to `weight_draws`, to Pareto smooth weights before adding to a draws object. +* `thin_draws` now automatically thins draws based on ESS, and + non-integer thinning is possible. * Matrix multiplication of `rvar`s can now be done with the base matrix multiplication operator (`%*%`) instead of `%**%` in R >= 4.3. * `variables()`, `variables<-()`, `set_variables()`, and `nvariables()` now From f500de12422d1a0aa52bbd5a101017513bc39177 Mon Sep 17 00:00:00 2001 From: n-kall Date: Fri, 10 May 2024 10:16:03 +0300 Subject: [PATCH 4/8] add individual pareto diagnostics to news --- NEWS.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 16b23dd1..80e0ddab 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,8 +8,10 @@ the matched selection. * Add `pareto_smooth` option to `weight_draws`, to Pareto smooth weights before adding to a draws object. -* `thin_draws` now automatically thins draws based on ESS, and - non-integer thinning is possible. +* Add individual Pareto diagnostic functions (`pareto_khat`, + `pareto_khat_threshold`, `pareto_min_ss`, `pareto_convergence_rate`) +* `thin_draws` now automatically thins draws based on ESS by default, + and non-integer thinning is possible. * Matrix multiplication of `rvar`s can now be done with the base matrix multiplication operator (`%*%`) instead of `%**%` in R >= 4.3. * `variables()`, `variables<-()`, `set_variables()`, and `nvariables()` now From a77b178bd5fc3af4c418a007bf0c4d5c9ae25f9a Mon Sep 17 00:00:00 2001 From: n-kall Date: Fri, 10 May 2024 10:18:11 +0300 Subject: [PATCH 5/8] minor tweak to news --- NEWS.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 80e0ddab..ac1f9f17 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,10 +2,11 @@ ### Enhancements -* Add `are_log_weights` option to `pareto_smooth`, which can improve - Pareto smoothing computation if the input are log weights. * Add `exclude` option to `subset_draws`, which can be used to exclude the matched selection. +* Add `are_log_weights` option to `pareto_smooth`, which is necessary + for correct Pareto smoothing computation if the input vector + consists of log weights. * Add `pareto_smooth` option to `weight_draws`, to Pareto smooth weights before adding to a draws object. * Add individual Pareto diagnostic functions (`pareto_khat`, From 0cd1433500f0e9548a70db28c67ddfbda72028ab Mon Sep 17 00:00:00 2001 From: n-kall Date: Fri, 10 May 2024 10:27:53 +0300 Subject: [PATCH 6/8] tweak news formatting --- NEWS.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index ac1f9f17..20e71d00 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,16 +2,16 @@ ### Enhancements -* Add `exclude` option to `subset_draws`, which can be used to exclude +* Add `exclude` option to `subset_draws()`, which can be used to exclude the matched selection. -* Add `are_log_weights` option to `pareto_smooth`, which is necessary +* Add `are_log_weights` option to `pareto_smooth()`, which is necessary for correct Pareto smoothing computation if the input vector consists of log weights. -* Add `pareto_smooth` option to `weight_draws`, to Pareto smooth +* Add `pareto_smooth` option to `weight_draws()`, to Pareto smooth weights before adding to a draws object. -* Add individual Pareto diagnostic functions (`pareto_khat`, - `pareto_khat_threshold`, `pareto_min_ss`, `pareto_convergence_rate`) -* `thin_draws` now automatically thins draws based on ESS by default, +* Add individual Pareto diagnostic functions (`pareto_khat()`, + `pareto_khat_threshold()`, `pareto_min_ss()`, `pareto_convergence_rate()`) +* `thin_draws()` now automatically thins draws based on ESS by default, and non-integer thinning is possible. * Matrix multiplication of `rvar`s can now be done with the base matrix multiplication operator (`%*%`) instead of `%**%` in R >= 4.3. From 8a5f677ae102dc20a07567f81cfce9bde1e8edf3 Mon Sep 17 00:00:00 2001 From: n-kall Date: Tue, 14 May 2024 16:43:37 +0300 Subject: [PATCH 7/8] set r_eff default back to NULL, fixes #368 --- R/pareto_smooth.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/pareto_smooth.R b/R/pareto_smooth.R index 976296c6..39acaacd 100644 --- a/R/pareto_smooth.R +++ b/R/pareto_smooth.R @@ -250,7 +250,7 @@ pareto_smooth.rvar <- function(x, return_k = FALSE, extra_diags = FALSE, ...) { #' @export pareto_smooth.default <- function(x, tail = c("both", "right", "left"), - r_eff = 1, + r_eff = NULL, ndraws_tail = NULL, return_k = FALSE, extra_diags = FALSE, From 6c121b8c560dda7dca42fd03c5a244c8bb084764 Mon Sep 17 00:00:00 2001 From: n-kall Date: Tue, 14 May 2024 16:46:23 +0300 Subject: [PATCH 8/8] update docs --- man-roxygen/args-pareto.R | 2 +- man/pareto_diags.Rd | 6 +++--- man/pareto_khat.Rd | 6 +++--- man/pareto_smooth.Rd | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/man-roxygen/args-pareto.R b/man-roxygen/args-pareto.R index 92e09373..488e60bf 100644 --- a/man-roxygen/args-pareto.R +++ b/man-roxygen/args-pareto.R @@ -15,7 +15,7 @@ #' al. (2024)). #' @param r_eff (numeric) relative effective sample size estimate. If #' `r_eff` is NULL, it will be calculated assuming the draws are -#' from MCMC. Default is 1. +#' from MCMC. Default is NULL. #' @param verbose (logical) Should diagnostic messages be printed? If #' `TRUE`, messages related to Pareto diagnostics will be #' printed. Default is `FALSE`. diff --git a/man/pareto_diags.Rd b/man/pareto_diags.Rd index e84f0b4a..31420b9e 100644 --- a/man/pareto_diags.Rd +++ b/man/pareto_diags.Rd @@ -68,7 +68,7 @@ The default is \code{"both"}.} \item{r_eff}{(numeric) relative effective sample size estimate. If \code{r_eff} is NULL, it will be calculated assuming the draws are -from MCMC. Default is 1.} +from MCMC. Default is NULL.} \item{ndraws_tail}{(numeric) number of draws for the tail. If \code{ndraws_tail} is not specified, it will be calculated as @@ -134,8 +134,8 @@ pareto_diags(d$Sigma) \references{ Aki Vehtari, Daniel Simpson, Andrew Gelman, Yuling Yao and Jonah Gabry (2024). Pareto Smoothed Importance Sampling. -\emph{Journal of Machine Learning Research}, accepted for publication. -arxiv:arXiv:1507.02646 (version 8) +\emph{Journal of Machine Learning Research}, 25(72):1-58. +\href{https://jmlr.org/papers/v25/19-556.html}{PDF} } \seealso{ \code{\link{pareto_khat}} for only calculating khat, and diff --git a/man/pareto_khat.Rd b/man/pareto_khat.Rd index 120afe8e..9df455d0 100644 --- a/man/pareto_khat.Rd +++ b/man/pareto_khat.Rd @@ -41,7 +41,7 @@ The default is \code{"both"}.} \item{r_eff}{(numeric) relative effective sample size estimate. If \code{r_eff} is NULL, it will be calculated assuming the draws are -from MCMC. Default is 1.} +from MCMC. Default is NULL.} \item{ndraws_tail}{(numeric) number of draws for the tail. If \code{ndraws_tail} is not specified, it will be calculated as @@ -76,8 +76,8 @@ pareto_khat(d$Sigma) \references{ Aki Vehtari, Daniel Simpson, Andrew Gelman, Yuling Yao and Jonah Gabry (2024). Pareto Smoothed Importance Sampling. -\emph{Journal of Machine Learning Research}, accepted for publication. -arxiv:arXiv:1507.02646 (version 8) +\emph{Journal of Machine Learning Research}, 25(72):1-58. +\href{https://jmlr.org/papers/v25/19-556.html}{PDF} } \seealso{ \code{\link{pareto_diags}} for additional related diagnostics, and diff --git a/man/pareto_smooth.Rd b/man/pareto_smooth.Rd index a293d080..d89b1ab3 100644 --- a/man/pareto_smooth.Rd +++ b/man/pareto_smooth.Rd @@ -13,7 +13,7 @@ pareto_smooth(x, ...) \method{pareto_smooth}{default}( x, tail = c("both", "right", "left"), - r_eff = 1, + r_eff = NULL, ndraws_tail = NULL, return_k = FALSE, extra_diags = FALSE, @@ -53,7 +53,7 @@ The default is \code{"both"}.} \item{r_eff}{(numeric) relative effective sample size estimate. If \code{r_eff} is NULL, it will be calculated assuming the draws are -from MCMC. Default is 1.} +from MCMC. Default is NULL.} \item{ndraws_tail}{(numeric) number of draws for the tail. If \code{ndraws_tail} is not specified, it will be calculated as @@ -94,8 +94,8 @@ pareto_smooth(d$Sigma) \references{ Aki Vehtari, Daniel Simpson, Andrew Gelman, Yuling Yao and Jonah Gabry (2024). Pareto Smoothed Importance Sampling. -\emph{Journal of Machine Learning Research}, accepted for publication. -arxiv:arXiv:1507.02646 (version 8) +\emph{Journal of Machine Learning Research}, 25(72):1-58. +\href{https://jmlr.org/papers/v25/19-556.html}{PDF} } \seealso{ \code{\link{pareto_khat}} for only calculating khat, and