bilby.core.sampler.ptemcee.get_Q_convergence

bilby.core.sampler.ptemcee.get_Q_convergence(samples)[source]

Calculate the Gelman-Rubin statistic as an estimate of convergence for an ensemble of MCMC walkers.

Calculates the Gelman-Rubin statistic, from Gelman and Rubin (1992). See section 2.2 of Gelman and Rubin (1992), at https://doi.org/10.1214/ss/1177011136.

There is also a good description of this statistic in section 7.4.2 of “Advanced Statistical Computing” (Peng 2021), in-progress course notes, currently found at https://bookdown.org/rdpeng/advstatcomp/monitoring-convergence.html. As of this writing, L in this resource refers to the number of sampling steps remaining after some have been discarded to achieve burn-in, equivalent to nsteps here. Paraphrasing, we compare the variance between our walkers (chains) to the variance within each walker (compare inter-walker vs. intra-walker variance). We do this because our walkers should be indistinguishable from one another when they reach a steady-state, i.e. convergence. Looking at V-hat in the definition of this function, we can see that as nsteps -> infinity, B (inter-chain variance) -> 0, R -> 1; so, R >~ 1 is a good condition for the convergence of our ensemble.

In practice, this function calculates the Gelman-Rubin statistic for each dimension, and then returns the largest of these values. This means that we can be sure that, once the walker with the largest such value achieves a Gelman-Rubin statistic of >~ 1, the others have as well.

Parameters:
samples: np.ndarray

Array of ensemble MCMC samples, shaped like (number of walkers, number of MCMC steps, number of dimensions).

Returns:
Q: float

The largest value of the Gelman-Rubin statistic, from those values calculated for each dimension. If only one step is represented in samples, this returns np.inf.