Skip to content

Commit a59519c

Browse files
Merge pull request #328 from ishaan-arora-1/fix/clarify-print-dims-198
Clarify print output to specify posterior draws and log-likelihood terms
2 parents 6388605 + 05c80c1 commit a59519c

11 files changed

Lines changed: 63 additions & 61 deletions

File tree

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# loo (development version)
22

3+
* Update user messages in `print()` by @ishaan-arora-1, @florence-bockting in
4+
#328.
5+
36
# loo 2.10.1
47

58
* Revert behavior of internal `psis_smooth_tail()` function that led to several

R/elpd.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ elpd_object <- function(pointwise, dims) {
6767
}
6868
#' @export
6969
print_dims.elpd_generic <- function(x, ...) {
70+
dims <- dim(x)
7071
cat(
71-
"Computed from",
72-
paste(dim(x), collapse = " by "),
73-
"log-likelihood matrix using the generic elpd function\n"
72+
"Computed from", dims[1], "posterior draws and",
73+
dims[2], "log-likelihood terms using the generic elpd function.\n"
7474
)
7575
}

R/print.R

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,40 +141,40 @@ print_dims <- function(x, ...) UseMethod("print_dims")
141141
#' @rdname print_dims
142142
#' @export
143143
print_dims.importance_sampling <- function(x, ...) {
144+
dims <- dim(x)
144145
cat(
145-
"Computed from",
146-
paste(dim(x), collapse = " by "),
147-
"log-weights matrix.\n"
146+
"Computed from", dims[1], "posterior draws and",
147+
dims[2], "log-weight terms.\n"
148148
)
149149
}
150150

151151
#' @rdname print_dims
152152
#' @export
153153
print_dims.psis_loo <- function(x, ...) {
154+
dims <- dim(x)
154155
cat(
155-
"Computed from",
156-
paste(dim(x), collapse = " by "),
157-
"log-likelihood matrix.\n"
156+
"Computed from", dims[1], "posterior draws and",
157+
dims[2], "log-likelihood terms.\n"
158158
)
159159
}
160160

161161
#' @rdname print_dims
162162
#' @export
163163
print_dims.importance_sampling_loo <- function(x, ...) {
164+
dims <- dim(x)
164165
cat(
165-
"Computed from",
166-
paste(dim(x), collapse = " by "),
167-
"log-likelihood matrix using", class(x)[1], ".\n"
166+
"Computed from", dims[1], "posterior draws and",
167+
dims[2], "log-likelihood terms using", class(x)[1], ".\n"
168168
)
169169
}
170170

171171
#' @rdname print_dims
172172
#' @export
173173
print_dims.waic <- function(x, ...) {
174+
dims <- dim(x)
174175
cat(
175-
"Computed from",
176-
paste(dim(x), collapse = " by "),
177-
"log-likelihood matrix.\n"
176+
"Computed from", dims[1], "posterior draws and",
177+
dims[2], "log-likelihood terms.\n"
178178
)
179179
}
180180

@@ -191,11 +191,13 @@ print_dims.kfold <- function(x, ...) {
191191
#' @export
192192
print_dims.psis_loo_ss <- function(x, ...) {
193193
cat(
194-
"Computed from",
195-
paste(c(dim(x)[1], nobs(x)) , collapse = " by "),
196-
"subsampled log-likelihood\nvalues from",
194+
"Subsampling loo uses 1) faster, more biased computation with ",
197195
length(x$loo_subsampling$elpd_loo_approx),
198-
"total observations.\n"
196+
" log-lik.\n",
197+
"terms, and 2) slower, more accurate computation with ",
198+
nobs(x),
199+
" subsampled terms.\n",
200+
sep = ""
199201
)
200202
}
201203

tests/testthat/_snaps/loo_moment_matching.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
1414
Output
1515
16-
Computed from 4000 by 30 log-likelihood matrix.
16+
Computed from 4000 posterior draws and 30 log-likelihood terms.
1717
1818
Estimate SE
1919
elpd_loo -74.0 18.8

tests/testthat/_snaps/loo_subsampling_cases.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
print(looss_1)
55
Output
66
7-
Computed from 4000 by 100 subsampled log-likelihood
8-
values from 3020 total observations.
7+
Subsampling loo uses 1) faster, more biased computation with 3020 log-lik.
8+
terms, and 2) slower, more accurate computation with 100 subsampled terms.
99
1010
Estimate SE subsampling SE
1111
elpd_loo -1968.5 15.6 0.3
@@ -24,8 +24,8 @@
2424
print(looss_1b)
2525
Output
2626
27-
Computed from 4000 by 200 subsampled log-likelihood
28-
values from 3020 total observations.
27+
Subsampling loo uses 1) faster, more biased computation with 3020 log-lik.
28+
terms, and 2) slower, more accurate computation with 200 subsampled terms.
2929
3030
Estimate SE subsampling SE
3131
elpd_loo -1968.3 15.6 0.2
@@ -44,7 +44,7 @@
4444
print(aploo_1)
4545
Output
4646
47-
Computed from 2000 by 3020 log-likelihood matrix.
47+
Computed from 2000 posterior draws and 3020 log-likelihood terms.
4848
4949
Estimate SE
5050
elpd_loo -1968.4 15.6
@@ -64,8 +64,8 @@
6464
print(looapss_1)
6565
Output
6666
67-
Computed from 2000 by 100 subsampled log-likelihood
68-
values from 3020 total observations.
67+
Subsampling loo uses 1) faster, more biased computation with 3020 log-lik.
68+
terms, and 2) slower, more accurate computation with 100 subsampled terms.
6969
7070
Estimate SE subsampling SE
7171
elpd_loo -1968.2 15.6 0.4
@@ -85,8 +85,8 @@
8585
print(looss_2)
8686
Output
8787
88-
Computed from 4000 by 100 subsampled log-likelihood
89-
values from 3020 total observations.
88+
Subsampling loo uses 1) faster, more biased computation with 3020 log-lik.
89+
terms, and 2) slower, more accurate computation with 100 subsampled terms.
9090
9191
Estimate SE subsampling SE
9292
elpd_loo -1952.0 16.2 0.2

tests/testthat/_snaps/print_plot.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
print(waic1)
55
Output
66
7-
Computed from 1000 by 32 log-likelihood matrix.
7+
Computed from 1000 posterior draws and 32 log-likelihood terms.
88
99
Estimate SE
1010
elpd_waic -83.5 4.3
@@ -18,7 +18,7 @@
1818
Code
1919
print(psis1)
2020
Output
21-
Computed from 1000 by 32 log-weights matrix.
21+
Computed from 1000 posterior draws and 32 log-weight terms.
2222
MCSE and ESS estimates assume independent draws (r_eff=1).
2323
2424
All Pareto k estimates are good (k < 0.67).
@@ -30,7 +30,7 @@
3030
print(loo1)
3131
Output
3232
33-
Computed from 1000 by 32 log-likelihood matrix.
33+
Computed from 1000 posterior draws and 32 log-likelihood terms.
3434
3535
Estimate SE
3636
elpd_loo -83.6 4.3
@@ -49,7 +49,7 @@
4949
print(loo1_r_eff)
5050
Output
5151
52-
Computed from 1000 by 32 log-likelihood matrix.
52+
Computed from 1000 posterior draws and 32 log-likelihood terms.
5353
5454
Estimate SE
5555
elpd_loo -83.6 4.3

tests/testthat/_snaps/psis.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4787,7 +4787,7 @@
47874787
Message
47884788
Replacing NAs in `r_eff` with 1s
47894789
Output
4790-
Computed from 1000 by 32 log-weights matrix.
4790+
Computed from 1000 posterior draws and 32 log-weight terms.
47914791
MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.0]).
47924792
47934793
All Pareto k estimates are good (k < 0.67).
@@ -4803,7 +4803,7 @@
48034803
Warning:
48044804
Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
48054805
Output
4806-
Computed from 10 by 32 log-weights matrix.
4806+
Computed from 10 posterior draws and 32 log-weight terms.
48074807
MCSE and ESS estimates assume independent draws (r_eff=1).
48084808
Pareto k diagnostic values:
48094809
Count Pct. Min. ESS

tests/testthat/_snaps/tisis.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Message
66
Replacing NAs in `r_eff` with 1s
77
Output
8-
Computed from 1000 by 32 log-weights matrix.
8+
Computed from 1000 posterior draws and 32 log-weight terms.
99
MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.0]).
1010
1111
All Pareto k estimates are good (k < 0.67).
@@ -17,7 +17,7 @@
1717
print(loo_tis)
1818
Output
1919
20-
Computed from 1000 by 32 log-likelihood matrix using tis_loo .
20+
Computed from 1000 posterior draws and 32 log-likelihood terms using tis_loo .
2121
2222
Estimate SE
2323
elpd_loo -83.6 4.3
@@ -31,7 +31,7 @@
3131
print(loo_sis)
3232
Output
3333
34-
Computed from 1000 by 32 log-likelihood matrix using sis_loo .
34+
Computed from 1000 posterior draws and 32 log-likelihood terms using sis_loo .
3535
3636
Estimate SE
3737
elpd_loo -83.6 4.3

tests/testthat/test_loo_subsampling_cases.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,25 @@ test_that("Test loo_subsampling and loo_approx with radon data", {
171171
))
172172
expect_failure(expect_output(
173173
print(full_loo),
174-
"subsampled log-likelihood\nvalues"
174+
"subsampled log-likelihood terms"
175175
))
176176

177177
expect_failure(expect_output(
178178
print(loo_ss),
179179
"Posterior approximation correction used\\."
180180
))
181-
expect_output(print(loo_ss), "subsampled log-likelihood\nvalues")
181+
expect_output(print(loo_ss), "Subsampling loo uses 1) faster,")
182182

183183
expect_output(print(loo_ap_ss), "Posterior approximation correction used\\.")
184-
expect_output(print(loo_ap_ss), "subsampled log-likelihood\nvalues")
184+
expect_output(print(loo_ap_ss), "Subsampling loo uses 1) faster,")
185185

186186
expect_output(
187187
print(loo_ap_ss_full),
188188
"Posterior approximation correction used\\."
189189
)
190190
expect_failure(expect_output(
191191
print(loo_ap_ss_full),
192-
"subsampled log-likelihood\nvalues"
192+
"subsampled log-likelihood terms"
193193
))
194194

195195
# Test conversion of objects
@@ -369,11 +369,8 @@ test_that("Test the vignette", {
369369
loo_approximation_draws = 100
370370
)
371371
)
372-
expect_output(
373-
print(looss_2),
374-
"Computed from 4000 by 100 subsampled log-likelihood"
375-
)
376-
expect_output(print(looss_2), "values from 3020 total observations.")
372+
expect_output(print(looss_2), "Subsampling loo uses 1) faster,")
373+
expect_output(print(looss_2), "Subsampling loo uses 1) faster,")
377374
expect_output(
378375
print(looss_2),
379376
"MCSE and ESS estimates assume independent draws"

vignettes/loo2-large-data.Rmd

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ print(loo_ss_1)
188188
```
189189

190190
```
191-
Computed from 4000 by 100 subsampled log-likelihood
192-
values from 3020 total observations.
191+
Subsampling loo uses 1) faster, more biased computation with 3020 log-lik.
192+
terms, and 2) slower, more accurate computation with 100 subsampled terms.
193193
194194
Estimate SE subsampling SE
195195
elpd_loo -1968.5 15.6 0.3
@@ -235,13 +235,13 @@ loo_ss_1b <-
235235
r_eff = r_eff,
236236
draws = parameter_draws_1,
237237
data = stan_df_1
238-
)
238+
)
239239
print(loo_ss_1b)
240240
```
241241

242242
```
243-
Computed from 4000 by 200 subsampled log-likelihood
244-
values from 3020 total observations.
243+
Subsampling loo uses 1) faster, more biased computation with 3020 log-lik.
244+
terms, and 2) slower, more accurate computation with 200 subsampled terms.
245245
246246
Estimate SE subsampling SE
247247
elpd_loo -1968.3 15.6 0.2
@@ -285,8 +285,8 @@ print(loo_ss_1c)
285285

286286

287287
```
288-
Computed from 4000 by 100 subsampled log-likelihood
289-
values from 3020 total observations.
288+
Subsampling loo uses 1) faster, more biased computation with 3020 log-lik.
289+
terms, and 2) slower, more accurate computation with 100 subsampled terms.
290290
291291
Estimate SE subsampling SE
292292
elpd_loo -1968.9 15.4 0.5
@@ -339,7 +339,7 @@ print(loo_ap_1)
339339
The function creates a class, `psis_loo_ap` that inherits from `psis_loo, loo`.
340340

341341
```
342-
Computed from 2000 by 3020 log-likelihood matrix
342+
Computed from 2000 posterior draws and 3020 log-likelihood terms
343343
344344
Estimate SE
345345
elpd_loo -1968.4 15.6
@@ -375,8 +375,8 @@ print(loo_ap_ss_1)
375375
```
376376

377377
```
378-
Computed from 2000 by 100 subsampled log-likelihood
379-
values from 3020 total observations.
378+
Subsampling loo uses 1) faster, more biased computation with 3020 log-lik.
379+
terms, and 2) slower, more accurate computation with 100 subsampled terms.
380380
381381
Estimate SE subsampling SE
382382
elpd_loo -1968.2 15.6 0.4
@@ -455,8 +455,8 @@ print(loo_ss_2)
455455
```
456456

457457
```
458-
Computed from 4000 by 100 subsampled log-likelihood
459-
values from 3020 total observations.
458+
Subsampling loo uses 1) faster, more biased computation with 3020 log-lik.
459+
terms, and 2) slower, more accurate computation with 200 subsampled terms.
460460
461461
Estimate SE subsampling SE
462462
elpd_loo -1952.0 16.2 0.2

0 commit comments

Comments
 (0)