-
-
Notifications
You must be signed in to change notification settings - Fork 379
Description
Summary:
In analyze service
- Offer interfaces a unified calculation of rhat
- Update effective sample size calculation
- Updating ess requires a small change in the autocovariance computation
Description:
#2569 and #2575 moved effective sample size computation from chains.hpp to analyze service.
Move rhat calculation in the same way. In addition make minor changes to the effective sample size and rhat calculation. These changes make the computations more robust, but in most cases affect the computed values only a little. Especially these changes don't include rank normalization, folding or quantiles (these features will be added later).
The reference implementation in R is at https://github.com/stan-dev/rstan/blob/develop/rstan/rstan/R/monitor.R
- autocovariance: use "biased" estimate as recommended by Geyer (1992)
- rhat: for constant finite values return 1, for non-finite values return NaN
- ess: 1) use split chains, 2) add half rho of the next even lag after the truncation, 3) negative values and maximum ess are set chainsn_sampleslog10(chains*n_samples)
Reproducible Steps:
Refrence values from R implementation
upath <- system.file('unitTests', package='rstan')
f1 <- file.path(upath, 'testdata', 'blocker1.csv')
f2 <- file.path(upath, 'testdata', 'blocker2.csv')
fit <- read_stan_csv(c(f1,f2))
monitor(fit)
sims <- as.array(fit)
rh <- rhat(sims[,,1])
checkEquals(rh, 1.007794, tolerance = 0.001);
eb <- ess_bulk(sims[,,1])
checkEquals(eb, 465.3917, tolerance = 0.001);
et <- ess_tail(sims[,,1])
checkEquals(et, 349.1353, tolerance = 0.001);
em <- ess_mean(sims[,,1])
checkEquals(em, 467.8447, tolerance = 0.001);
Same blocker1.csv and blocker2.csv files are in stan repo at src/test/unit/mcmc/test_csv_files/ and have been used in unit tests in stan repo, too.
EDIT: updated ess_mean reference value.