Skip to content

Commit c41858c

Browse files
authored
Merge pull request #755 from njtierney/add-warmup-print-i652
Add warmup print i652
2 parents d475f88 + 450dcee commit c41858c

7 files changed

+25
-2
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Changes
44

55
- `log.greta_array()` function warns if user uses the `base` arg, as it was unused, (#597).
6+
- Add warmup information to MCMC print method (#652, resolved by #755).
67

78
# greta 0.5.0
89

R/greta_mcmc_list.R

+2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ window.greta_mcmc_list <- function(x, start, end, thin, ...) {
6262
#' @export
6363
print.greta_mcmc_list <- function(x, ..., n = 5){
6464

65+
n_warmup <- n_warmup(x)
6566
n_chain <- coda::nchain(x)
6667
n_iter <- coda::niter(x)
6768
n_thin <- coda::thin(x)
6869
cli::cli_h1("MCMC draws from {.pkg greta}")
6970
cli::cli_bullets(
7071
c(
7172
"*" = "Iterations = {n_iter}",
73+
"*" = "Warmup = {n_warmup}",
7274
"*" = "Chains = {n_chain}",
7375
"*" = "Thinning = {n_thin}"
7476
)

R/inference.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@ run_samplers <- function(samplers,
394394
greta_stash$trace_log_files <- trace_log_files
395395
greta_stash$percentage_log_files <- percentage_log_files
396396
greta_stash$progress_bar_log_files <- progress_bar_log_files
397-
greta_stash$mcmc_info <- list(n_samples = n_samples)
397+
greta_stash$mcmc_info <- list(
398+
n_samples = n_samples,
399+
warmup = warmup
400+
)
398401
}
399402

400403
if (plan_is$parallel) {
@@ -514,7 +517,8 @@ stashed_samples <- function() {
514517
model_info <- list(
515518
raw_draws = free_state_draws,
516519
samplers = samplers,
517-
model = samplers[[1]]$model
520+
model = samplers[[1]]$model,
521+
warmup = samplers[[1]]$warmup
518522
)
519523

520524
values_draws <- as_greta_mcmc_list(values_draws, model_info)

R/inference_class.R

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ sampler <- R6Class(
244244
n_chains = 1,
245245
numerical_rejections = 0,
246246
thin = 1,
247+
warmup = 1,
247248

248249
# tuning information
249250
mean_accept_stat = 0.5,
@@ -336,6 +337,7 @@ sampler <- R6Class(
336337
one_by_one, plan_is, n_cores, float_type,
337338
trace_batch_size,
338339
from_scratch = TRUE) {
340+
self$warmup <- warmup
339341
self$thin <- thin
340342
dag <- self$model$dag
341343

R/utils.R

+5
Original file line numberDiff line numberDiff line change
@@ -1174,3 +1174,8 @@ are_initials <- function(x){
11741174
FUN.VALUE = logical(1)
11751175
)
11761176
}
1177+
1178+
n_warmup <- function(x){
1179+
x_info <- attr(x, "model_info")
1180+
x_info$warmup
1181+
}

tests/testthat/_snaps/greta_mcmc_list_class.md

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
-- MCMC draws from greta -------------------------------------------------------
88
* Iterations = 10
9+
* Warmup = 10
910
* Chains = 4
1011
* Thinning = 1
1112
@@ -36,6 +37,7 @@
3637
3738
-- MCMC draws from greta -------------------------------------------------------
3839
* Iterations = 20
40+
* Warmup = 20
3941
* Chains = 4
4042
* Thinning = 1
4143
@@ -66,6 +68,7 @@
6668
6769
-- MCMC draws from greta -------------------------------------------------------
6870
* Iterations = 20
71+
* Warmup = 20
6972
* Chains = 4
7073
* Thinning = 1
7174
@@ -109,6 +112,7 @@
109112
110113
-- MCMC draws from greta -------------------------------------------------------
111114
* Iterations = 20
115+
* Warmup = 20
112116
* Chains = 4
113117
* Thinning = 1
114118
@@ -153,6 +157,7 @@
153157
154158
-- MCMC draws from greta -------------------------------------------------------
155159
* Iterations = 20
160+
* Warmup = 20
156161
* Chains = 4
157162
* Thinning = 1
158163
@@ -196,6 +201,7 @@
196201
197202
-- MCMC draws from greta -------------------------------------------------------
198203
* Iterations = 2
204+
* Warmup = 2
199205
* Chains = 4
200206
* Thinning = 1
201207
@@ -221,6 +227,7 @@
221227
222228
-- MCMC draws from greta -------------------------------------------------------
223229
* Iterations = 2
230+
* Warmup = 2
224231
* Chains = 4
225232
* Thinning = 1
226233
@@ -247,6 +254,7 @@
247254
248255
-- MCMC draws from greta -------------------------------------------------------
249256
* Iterations = 2
257+
* Warmup = 2
250258
* Chains = 4
251259
* Thinning = 1
252260

tests/testthat/_snaps/print_calculate.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
2929
-- MCMC draws from greta -------------------------------------------------------
3030
* Iterations = 10
31+
* Warmup = 10
3132
* Chains = 4
3233
* Thinning = 1
3334

0 commit comments

Comments
 (0)