dfm / emcee

The Python ensemble sampling toolkit for affine-invariant MCMC
https://emcee.readthedocs.io
MIT License
1.46k stars 431 forks source link

What is the meaning of the `acf /= 4*n` line in the autocorr_func_1d() function in the v3 docs? #297

Closed Gabriel-p closed 5 years ago

Gabriel-p commented 5 years ago

In the autocorrelation section of the latest docs (https://emcee.readthedocs.io/en/latest/tutorials/autocorr/) there is a autocorr_func_1d() function defined where the line

acf /= 4*n

is included.

What is the meaning of this line? I could not find it in the integrated_time() function in the master branch, and I can't understand what it is supposed to do there.

OriolAbril commented 5 years ago

It corresponds to the term 1/(N-tau) in the definition of the autocovariance function c_f(tau), however, instead of using N-tau (which would yield an unbiased but unconsistent estimator of the autocovariance), N is used (which gives a consistent but biased estimator; N in the fft is 2*n, I have no clue about the other 2 factor though, I think it should be 2*n, not 4*n). The typical reference when using this biased estimator of the covariance is Geyer, C. J. (1992). Practical markov chain monte carlo. Statistical science, 473-483.

However, this factor is irrelevant when the autocovariance is normalized in order to get the autocorrelation (the normalization is done in acf /= acf[0]). Therefore, as the code in master only calculates the autocorrelation, there is no need for this factor 4*n or 2*n.

Gabriel-p commented 5 years ago

Thank you @OriolAbril. Since this is a very minor issue with the docs and you've provided an answer (although the misery of the 4 is still there), I'll just close this.