Max_treedepth not adhered to in rstan?

I just noticed something funny while running rstan 2.19.2. I have a model that was getting the max treedepth warning, so I ran rstan::sampling(..., control = list(max_treedepth=15)). When the model finished sampling I didn’t get any warning, but when I ran rstan::check_hmc_diagnostics, it once again showed me the treedepth warning. I took a look at the samples csv and it indeed had # max_treedepth=15 in the header, but when I run:

sampler_params <- get_sampler_params(post, inc_warmup = FALSE)
sampler_params_chain1 <- sampler_params[[1]]
max_treedepth_by_chain <- sapply(sampler_params, function(x) max(x[, "treedepth__"]))
print(max_treedepth_by_chain)

It shows that for each chain 10 was the max treedepth. Is this all expected behaviour?

1 Like

Oh! If I run:

sampler_params <- get_sampler_params(post, inc_warmup = TRUE)
sampler_params_chain1 <- sampler_params[[1]]
max_treedepth_by_chain <- sapply(sampler_params, function(x) max(x[, "treedepth__"]))
print(max_treedepth_by_chain)

(n.b. inc_warmup = TRUE), it shows max treedepths greater than 10. So does the max_treedepth parameter only apply to the warmup?

The limit applies to all the iterations, but you do not get warnings for exceeding the max_treedepth during warmup. Nor do you get divergent transition warnings during warmup. Those almost always happen when you move from one window to the next.

1 Like

Ok, then is it not odd that all my treedepths max out at 10 after warmup?

Not with control = list(max_treedepth = 15)

I had control=list(max_treedepth=15) yet observed that after warmup no iterations went above 10. Before warmup some did, but after warmup none did.

Yeah, that is fine. And you could have gotten by with max_treedepth of 11.

1 Like