Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# loo (development version)

* Clarify print output to say "posterior draws" and "log-likelihood terms" instead of the ambiguous "X by Y matrix" format (#198)

# loo 2.9.0

* Avoid under and overflows in stacking by @avehtari in #273
Expand Down
6 changes: 3 additions & 3 deletions R/elpd.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ elpd_object <- function(pointwise, dims) {
}
#' @export
print_dims.elpd_generic <- function(x, ...) {
dims <- dim(x)
cat(
"Computed from",
paste(dim(x), collapse = " by "),
"log-likelihood matrix using the generic elpd function\n"
"Computed from", dims[1], "posterior draws and",
dims[2], "log-likelihood terms using the generic elpd function.\n"
)
}
29 changes: 14 additions & 15 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,40 +119,40 @@ print_dims <- function(x, ...) UseMethod("print_dims")
#' @rdname print_dims
#' @export
print_dims.importance_sampling <- function(x, ...) {
dims <- dim(x)
cat(
"Computed from",
paste(dim(x), collapse = " by "),
"log-weights matrix.\n"
"Computed from", dims[1], "posterior draws and",
dims[2], "log-weight terms.\n"
)
}

#' @rdname print_dims
#' @export
print_dims.psis_loo <- function(x, ...) {
dims <- dim(x)
cat(
"Computed from",
paste(dim(x), collapse = " by "),
"log-likelihood matrix.\n"
"Computed from", dims[1], "posterior draws and",
dims[2], "log-likelihood terms.\n"
)
}

#' @rdname print_dims
#' @export
print_dims.importance_sampling_loo <- function(x, ...) {
dims <- dim(x)
cat(
"Computed from",
paste(dim(x), collapse = " by "),
"log-likelihood matrix using", class(x)[1], ".\n"
"Computed from", dims[1], "posterior draws and",
dims[2], "log-likelihood terms using", class(x)[1], ".\n"
)
}

#' @rdname print_dims
#' @export
print_dims.waic <- function(x, ...) {
dims <- dim(x)
cat(
"Computed from",
paste(dim(x), collapse = " by "),
"log-likelihood matrix.\n"
"Computed from", dims[1], "posterior draws and",
dims[2], "log-likelihood terms.\n"
)
}

Expand All @@ -169,9 +169,8 @@ print_dims.kfold <- function(x, ...) {
#' @export
print_dims.psis_loo_ss <- function(x, ...) {
cat(
"Computed from",
paste(c(dim(x)[1], nobs(x)) , collapse = " by "),
"subsampled log-likelihood\nvalues from",
"Computed from", dim(x)[1], "posterior draws and",
nobs(x), "subsampled log-likelihood\nterms from",
length(x$loo_subsampling$elpd_loo_approx),
"total observations.\n"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/loo_moment_matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
Output

Computed from 4000 by 30 log-likelihood matrix.
Computed from 4000 posterior draws and 30 log-likelihood terms.

Estimate SE
elpd_loo -74.0 18.8
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/psis.md
Original file line number Diff line number Diff line change
Expand Up @@ -4787,7 +4787,7 @@
Message
Replacing NAs in `r_eff` with 1s
Output
Computed from 1000 by 32 log-weights matrix.
Computed from 1000 posterior draws and 32 log-weight terms.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.0]).

All Pareto k estimates are good (k < 0.67).
Expand All @@ -4803,7 +4803,7 @@
Warning:
Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
Output
Computed from 10 by 32 log-weights matrix.
Computed from 10 posterior draws and 32 log-weight terms.
MCSE and ESS estimates assume independent draws (r_eff=1).
Pareto k diagnostic values:
Count Pct. Min. ESS
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/tisis.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Message
Replacing NAs in `r_eff` with 1s
Output
Computed from 1000 by 32 log-weights matrix.
Computed from 1000 posterior draws and 32 log-weight terms.
MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.0]).

All Pareto k estimates are good (k < 0.67).
Expand Down
30 changes: 15 additions & 15 deletions tests/testthat/test_loo_subsampling_cases.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,25 @@ test_that("Test loo_subsampling and loo_approx with radon data", {
))
expect_failure(expect_output(
print(full_loo),
"subsampled log-likelihood\nvalues"
"subsampled log-likelihood\nterms"
))

expect_failure(expect_output(
print(loo_ss),
"Posterior approximation correction used\\."
))
expect_output(print(loo_ss), "subsampled log-likelihood\nvalues")
expect_output(print(loo_ss), "subsampled log-likelihood\nterms")

expect_output(print(loo_ap_ss), "Posterior approximation correction used\\.")
expect_output(print(loo_ap_ss), "subsampled log-likelihood\nvalues")
expect_output(print(loo_ap_ss), "subsampled log-likelihood\nterms")

expect_output(
print(loo_ap_ss_full),
"Posterior approximation correction used\\."
)
expect_failure(expect_output(
print(loo_ap_ss_full),
"subsampled log-likelihood\nvalues"
"subsampled log-likelihood\nterms"
))

# Test conversion of objects
Expand Down Expand Up @@ -344,9 +344,9 @@ test_that("Test the vignette", {
)
expect_output(
print(looss_1),
"Computed from 4000 by 100 subsampled log-likelihood"
"Computed from 4000 posterior draws and 100 subsampled log-likelihood"
)
expect_output(print(looss_1), "values from 3020 total observations.")
expect_output(print(looss_1), "terms from 3020 total observations.")
expect_output(
print(looss_1),
"MCSE and ESS estimates assume independent draws"
Expand All @@ -366,9 +366,9 @@ test_that("Test the vignette", {
)
expect_output(
print(looss_1b),
"Computed from 4000 by 200 subsampled log-likelihood"
"Computed from 4000 posterior draws and 200 subsampled log-likelihood"
)
expect_output(print(looss_1b), "values from 3020 total observations.")
expect_output(print(looss_1b), "terms from 3020 total observations.")
expect_output(
print(looss_1b),
"MCSE and ESS estimates assume independent draws"
Expand All @@ -391,9 +391,9 @@ test_that("Test the vignette", {
)
expect_output(
print(looss_2),
"Computed from 4000 by 100 subsampled log-likelihood"
"Computed from 4000 posterior draws and 100 subsampled log-likelihood"
)
expect_output(print(looss_2), "values from 3020 total observations.")
expect_output(print(looss_2), "terms from 3020 total observations.")
expect_output(
print(looss_2),
"MCSE and ESS estimates assume independent draws"
Expand All @@ -415,7 +415,7 @@ test_that("Test the vignette", {
)
expect_output(
print(aploo_1),
"Computed from 2000 by 3020 log-likelihood matrix"
"Computed from 2000 posterior draws and 3020 log-likelihood terms"
)
expect_output(
print(aploo_1),
Expand All @@ -441,13 +441,13 @@ test_that("Test the vignette", {
)
expect_output(
print(looapss_1),
"Computed from 2000 by 100 subsampled log-likelihood"
"Computed from 2000 posterior draws and 100 subsampled log-likelihood"
)
expect_output(
print(looapss_1),
"MCSE and ESS estimates assume independent draws"
)
expect_output(print(looapss_1), "values from 3020 total observations.")
expect_output(print(looapss_1), "terms from 3020 total observations.")
expect_output(print(looapss_1), "elpd_loo -1968.2 15.6 0.4")
expect_output(print(looapss_1), "p_loo 2.9 0.1 0.5")
expect_output(print(looapss_1), "All Pareto k estimates are good")
Expand All @@ -474,13 +474,13 @@ test_that("Test the vignette", {
)
expect_output(
print(looss_2),
"Computed from 4000 by 100 subsampled log-likelihood"
"Computed from 4000 posterior draws and 100 subsampled log-likelihood"
)
expect_output(
print(looss_2),
"MCSE and ESS estimates assume independent draws"
)
expect_output(print(looss_2), "values from 3020 total observations.")
expect_output(print(looss_2), "terms from 3020 total observations.")
expect_output(print(looss_2), "elpd_loo -1952.0 16.2 0.2")
expect_output(print(looss_2), "p_loo 2.6 0.1 0.3")

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test_print_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ test_that("plot methods throw appropriate errors/warnings", {
lldim_msg <- paste0(
"Computed from ",
prod(dim(LLarr)[1:2]),
" by ",
" posterior draws and ",
dim(LLarr)[3],
" log-likelihood matrix"
" log-likelihood terms"
)
lwdim_msg <- paste0(
"Computed from ",
prod(dim(LLarr)[1:2]),
" by ",
" posterior draws and ",
dim(LLarr)[3],
" log-weights matrix"
" log-weight terms"
)

test_that("print.waic output is ok", {
Expand Down
22 changes: 11 additions & 11 deletions vignettes/loo2-large-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ print(loo_ss_1)
```

```
Computed from 4000 by 100 subsampled log-likelihood
values from 3020 total observations.
Computed from 4000 posterior draws and 100 subsampled log-likelihood
terms from 3020 total observations.

Estimate SE subsampling SE
elpd_loo -1968.5 15.6 0.3
Expand Down Expand Up @@ -240,8 +240,8 @@ print(loo_ss_1b)
```

```
Computed from 4000 by 200 subsampled log-likelihood
values from 3020 total observations.
Computed from 4000 posterior draws and 200 subsampled log-likelihood
terms from 3020 total observations.

Estimate SE subsampling SE
elpd_loo -1968.3 15.6 0.2
Expand Down Expand Up @@ -285,8 +285,8 @@ print(loo_ss_1c)


```
Computed from 4000 by 100 subsampled log-likelihood
values from 3020 total observations.
Computed from 4000 posterior draws and 100 subsampled log-likelihood
terms from 3020 total observations.

Estimate SE subsampling SE
elpd_loo -1968.9 15.4 0.5
Expand Down Expand Up @@ -339,7 +339,7 @@ print(loo_ap_1)
The function creates a class, `psis_loo_ap` that inherits from `psis_loo, loo`.

```
Computed from 2000 by 3020 log-likelihood matrix
Computed from 2000 posterior draws and 3020 log-likelihood terms

Estimate SE
elpd_loo -1968.4 15.6
Expand Down Expand Up @@ -375,8 +375,8 @@ print(loo_ap_ss_1)
```

```
Computed from 2000 by 100 subsampled log-likelihood
values from 3020 total observations.
Computed from 2000 posterior draws and 100 subsampled log-likelihood
terms from 3020 total observations.

Estimate SE subsampling SE
elpd_loo -1968.2 15.6 0.4
Expand Down Expand Up @@ -455,8 +455,8 @@ print(loo_ss_2)
```

```
Computed from 4000 by 100 subsampled log-likelihood
values from 3020 total observations.
Computed from 4000 posterior draws and 100 subsampled log-likelihood
terms from 3020 total observations.

Estimate SE subsampling SE
elpd_loo -1952.0 16.2 0.2
Expand Down
4 changes: 2 additions & 2 deletions vignettes/loo2-with-rstan.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ print(loo_1)
```

```
Computed from 4000 by 3020 log-likelihood matrix
Computed from 4000 posterior draws and 3020 log-likelihood terms

Estimate SE
elpd_loo -1968.5 15.6
Expand Down Expand Up @@ -182,7 +182,7 @@ print(loo_2)
```

```
Computed from 4000 by 3020 log-likelihood matrix
Computed from 4000 posterior draws and 3020 log-likelihood terms

Estimate SE
elpd_loo -1952.3 16.2
Expand Down