2
$\begingroup$

I am using Hamiltonian Monte Carlo (HMC) to sample the posterior of a continuous-time Markov Chain (CTMC).

However, after running 10 parallel chains with 100 draws each, the effective sample size (ESS) rises in a certain pattern, way beyond the actual sample size (which should be 10 * 100 = 1000 samples).

plot

Has anyone seen this pattern before? What could be the cause of this misbehavior?

To calculate the ESS I am using the ess() function from the Arviz Python package with the parameters left to default (i.e. method="bulk").

The trace plot of one of the chains for this parameter looks like this:

plot2

I figured the oscillations come from the convexity of my target distribution and the fact that I am using HMC to sample it.

$\endgroup$

1 Answer 1

3
$\begingroup$

This is actually not an error - it is possible for the effective sample size to be larger than the actual sample size. This means that your MCMC samples provide more information about the parameter, than if you had obtained the same number of independent samples directly from the target (posterior) distribution.

To get some intuition about what this means: Imagine that we are doing a Bayesian analysis of a problem where the true posterior distribution for some parameter, $\theta$, (unbeknownst to us) is a normal distribution with $\mu=172$ and $\sigma=12$. If an omniscient statistician were to estimate the posterior mean, $\mu$, for that parameter by directly drawing $N=100$ samples from the posterior $N(172, 12)$ distribution and taking the average, then the standard error of the mean for that estimate would be:

$$ \textrm{SE} = \frac{\sigma}{\sqrt{N}} = \frac{12}{\sqrt{100}} = 1.2 $$

This means that if the omniscient statistician were to repeat this experiment many times (drawing $100$ random samples from the $N(172,12)$ distribution and each time computing the sample mean), then the resulting values would be distributed around the true value, $\mu=172$, with a standard deviation of approximately $1.2$.

If we instead use MCMC to estimate $\mu$ using $N=100$ iterations (post warmup), and learn that $\textrm{ESS}>N$ then this means that our uncertainty about $\mu$ is less than $1.2$: if we were to run the MCMC for 100 iterations multiple times, then the posterior means from each run would be distributed around the true value with a standard deviation that was less than $1.2$.

This can happen when consecutive MCMC samples are negatively correlated: ESS is often defined as:

$$ \textrm{ESS} = \frac{N}{1 + 2 \sum_{n=1}^{\infty}\rho_n} $$

where $\rho_n$ is the lag-n autocorrelation (i.e., the correlation between the samples and the samples shifted n steps). If there is negative autocorrelation for odd lags then the denominator can be less than 1 leading to the situation where $\textrm{ESS}>N$.


Stan reference manual: Effective Sample Size
Andrew Gelman blog: Simple example of anticorrelated samples
Wikipedia: Antithetic variates
Aki Vehtari GitHub: Comparison of MCMC effective sample size estimators

$\endgroup$
1
  • 2
    $\begingroup$ Important caveat: ESS is always for a specific quantity (AFAIK arviz defaults to the mean of rank-normalized values, but ESS for mean is also commonly reported). While it is possible to have ESS > N for a specific quantity, you cannot have ESS > N for all quantities at the same time - there's no free lunch, if your MCMC provides more information than i.i.d. samples about the central tendency of a distribution, it has to provide less info for some other aspect (though the other aspects may often be less important to you). $\endgroup$ Commented May 22, 2023 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.