Skip to content

Commit 6f86675

Browse files
committed
Removed ess_rfun
1 parent 6f815b9 commit 6f86675

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

R/effective_sample_sizes.R

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ relative_eff.array <- function(x, ..., cores = getOption("mc.cores", 1)) {
6363
S <- prod(dim(x)[1:2]) # posterior sample size = iter * chains
6464

6565
if (cores == 1) {
66-
n_eff_vec <- apply(x, 3, ess_rfun)
66+
n_eff_vec <- apply(x, 3, posterior::ess_mean)
6767
} else {
6868
if (!os_is_windows()) {
6969
n_eff_list <-
7070
parallel::mclapply(
7171
mc.cores = cores,
7272
X = seq_len(dim(x)[3]),
73-
FUN = function(i) ess_rfun(x[, , i, drop = TRUE])
73+
FUN = function(i) posterior::ess_mean(x[, , i, drop = TRUE])
7474
)
7575
} else {
7676
cl <- parallel::makePSOCKcluster(cores)
@@ -79,7 +79,7 @@ relative_eff.array <- function(x, ..., cores = getOption("mc.cores", 1)) {
7979
parallel::parLapply(
8080
cl = cl,
8181
X = seq_len(dim(x)[3]),
82-
fun = function(i) ess_rfun(x[, , i, drop = TRUE])
82+
fun = function(i) posterior::ess_mean(x[, , i, drop = TRUE])
8383
)
8484
}
8585
n_eff_vec <- unlist(n_eff_list, use.names = FALSE)
@@ -192,15 +192,3 @@ psis_n_eff.matrix <- function(w, r_eff = NULL, ...) {
192192
}
193193
1 / ss * r_eff
194194
}
195-
196-
#' MCMC effective sample size calculation
197-
#'
198-
#' @noRd
199-
#' @param sims An iterations by chains matrix of draws for a single parameter.
200-
#' In the case of the **loo** package, this will be the **exponentiated**
201-
#' log-likelihood values for the ith observation.
202-
#' @return MCMC effective sample size based on RStan's calculation.
203-
#'
204-
ess_rfun <- function(sims) {
205-
posterior::ess_basic(sims)
206-
}

tests/testthat/test_relative_eff.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test_that("relative_eff is equal to ESS / S", {
1616
ess <- r_eff <- rep(NA, dims[3])
1717
for (j in 1:dims[3]) {
1818
r_eff[j] <- relative_eff(LLarr[,,1, drop=FALSE])
19-
ess[j] <- ess_rfun(LLarr[,,1])
19+
ess[j] <- posterior::ess_mean(LLarr[,,1])
2020
}
2121
S <- prod(dim(LLarr)[1:2])
2222
expect_equal(r_eff, ess / S)

0 commit comments

Comments
 (0)