I am programming some custom samplers (specifically adaptive MALT with manual gradients) for a model in R/C++ and comparing efficiency to Stan. Comparing min(ESS)/second is easy but I also want to compare min(ESS) per gradient evaluation, for which I need to be able to extract the number of leapfrog steps per transition/iteration for each chain for the (Stan variation of) the NUTS sampler.
Is there a way to do this in rstan or cmdstanr?
rstan::get_sampler_params will give you back an array including
cmdstan output csvs likewise have a
Hi - how can I do this for cmdstanr output? (without having to convert to rstan CSV??)
If the result from the call to
$sample() was stored in a variable
fit, then type
fit$ and rstudio will auto-suggest elements/functions, one of which is
hmc_diagnostics(), which acts like
draws() in returning the draw by draw HMC diagnostic quantities, including number of leapfrog steps, with options for the return format (df, array, rvar, etc)
Thanks @mike-lawrence - do you need to use save_warmup = 1 to get the leapfrog steps during the burn-in phase or will they be saved regardless?