Skip to content
QFT.org

Search QFT.org

Enter a word or phrase.

    You can also browse the main navigation and chapter contents.

    Autocorrelation and Effective Sample Size

    A simulation stores 8,192 field configurations. Does that mean an observable has 8,192 independent measurements? Usually it does not: nearby configurations share fluctuations. The uncertainty of their average depends on both the update rule and the observable being measured.

    We derive that uncertainty, test it on an exactly soluble process, and repeat the test for a finite scalar-field correlator. The examples also show why discarding measurements or stopping an autocorrelation sum early can give misleading error bars.

    Preparation: Expectation values, covariance, and Gaussian random variables. Monte Carlo time below counts algorithmic updates; it is unrelated to physical time.

    Count pairs in the sample mean

    Let XtX_t be a real stationary measurement history with mean μ\mu and nonzero finite variance. Stationarity means that its covariance depends only on the separation:

    Γ(k)=E[(Xt−μ)(Xt+k−μ)],ρ(k)=Γ(k)Γ(0).\Gamma(k)=\mathbb E[(X_t-\mu)(X_{t+k}-\mu)], \qquad \rho(k)=\frac{\Gamma(k)}{\Gamma(0)}.

    For X‾=N−1∑t=0N−1Xt\overline X=N^{-1}\sum_{t=0}^{N-1}X_t, expand the square of the sum. There are NN diagonal pairs and 2(N−k)2(N-k) ordered pairs at positive separation kk. Therefore, exactly at finite NN,

    Var⁡(X‾)=Γ(0)N[1+2∑k=1N−1(1−kN)ρ(k)].\operatorname{Var}(\overline X) =\frac{\Gamma(0)}{N} \left[1+2\sum_{k=1}^{N-1}\left(1-\frac{k}{N}\right)\rho(k)\right].

    If the correlations are absolutely summable and the run is long compared with their decay, define

    τint=12+∑k=1∞ρ(k),Var⁡(X‾)≃2τintΓ(0)N,Neff=N2τint.\tau_{\mathrm{int}}=\frac12+\sum_{k=1}^{\infty}\rho(k), \qquad \operatorname{Var}(\overline X)\simeq\frac{2\tau_{\mathrm{int}}\Gamma(0)}{N}, \qquad N_{\mathrm{eff}}=\frac{N}{2\tau_{\mathrm{int}}}.

    NeffN_{\mathrm{eff}} compares the variance of this mean with that of independent draws having the same one-measurement variance. It is specific to XX, not a property of a configuration file alone. Independent samples have τint=1/2\tau_{\mathrm{int}}=1/2 in this convention; some authors instead call 2τint2\tau_{\mathrm{int}} the autocorrelation time.

    These variance identities do not by themselves establish a central limit theorem or convergence from a nonequilibrium start. A normal confidence interval additionally requires an appropriate limit theorem and a sufficiently long run. A chain trapped in a sector can have a deceptively short measured correlation time.

    An exact test: the autoregressive process

    Choose ∣a∣<1|a|<1 and independent standard normal variables ϵt\epsilon_t. Start with X0∼N(0,1)X_0\sim N(0,1) and update

    Xt+1=aXt+1−a2 ϵt.X_{t+1}=aX_t+\sqrt{1-a^2}\,\epsilon_t.

    The variance remains one, and repeated substitution gives Γ(k)=a∣k∣\Gamma(k)=a^{|k|}. Summing the geometric series yields

    τint=1+a2(1−a).\tau_{\mathrm{int}}=\frac{1+a}{2(1-a)}.

    At a=0.8a=0.8, τint=4.5\tau_{\mathrm{int}}=4.5 and the asymptotic effective sample size is N/9N/9. An independent-sample standard error is too small by a factor of three. At a=−1/2a=-1/2, however, τint=1/6\tau_{\mathrm{int}}=1/6 and Neff=3NN_{\mathrm{eff}}=3N: alternating correlations improve the mean. This does not create new independent configurations; it improves this particular estimator.

    Starting with the exact stationary distribution deliberately removes equilibration bias from this test. Starting instead at a fixed x0x_0 gives E[Xt]=atx0\mathbb E[X_t]=a^t x_0. That transient must be addressed separately before applying stationary error formulas.

    Estimate the correlation sum without summing noise

    For one stored history, a direct estimate is

    Γ^(k)=1N−k∑t=0N−k−1(Xt−X‾)(Xt+k−X‾).\widehat\Gamma(k)=\frac{1}{N-k} \sum_{t=0}^{N-k-1}(X_t-\overline X)(X_{t+k}-\overline X).

    Subtracting the estimated mean introduces finite-run bias. Correlations at large lag also become noisy because fewer pairs contribute. Instead of summing every lag, choose a window W≪NW\ll N and estimate

    V^W=1N[Γ^(0)+2∑k=1WΓ^(k)].\widehat V_W=\frac1N\left[\widehat\Gamma(0)+2\sum_{k=1}^{W}\widehat\Gamma(k)\right].

    A short window misses a positive tail; a very long window adds noise and can even yield an inadmissible negative variance estimate. Such an estimate is a failure of this error analysis, not a zero-error result. Compare windows, longer runs, and independent streams. The Γ\Gamma-method develops systematic window selection and the uncertainty of the error estimate itself [1, §§3.1–3.3]. Our benchmark uses fixed windows so that this tradeoff can be seen directly; it is not an implementation of that paper's automatic window procedure.

    A small slow component is especially easy to miss. Take two independent unit-variance autoregressive processes with coefficients 0.50.5 and 0.9950.995, and combine them with amplitudes 0.99\sqrt{0.99} and 0.01\sqrt{0.01}. The resulting unit-variance process has

    ρ(k)=0.99(0.5)k+0.01(0.995)k,τint=12+0.990.51−0.5+0.010.9951−0.995=3.48.\begin{aligned} \rho(k)&=0.99(0.5)^k+0.01(0.995)^k,\\ \tau_{\mathrm{int}}&=\frac12+0.99\frac{0.5}{1-0.5} +0.01\frac{0.995}{1-0.995}=3.48. \end{aligned}

    Even the exact correlation function truncated at W=10W=10 gives only 1.58631.5863. This is a truncation error, before any statistical noise is added. The following analytic plot shows the missing contribution accumulating over hundreds of updates.

    The exact truncated autocorrelation time rises from 1.586 at a ten-update window toward 3.48 only after hundreds of updates; the fast component saturates near 1.49.

    Exact finite geometric sums for the two-mode process above. The blue solid curve includes both modes; the dashed curve retains the baseline 1/2 and only the fast contribution. The dotted line is the infinite-window answer. All times are in algorithmic updates; this plot contains no measured or fitted data.

    Blocking and independent runs

    Partition a stationary stream into BB consecutive blocks of bb measurements, so N=BbN=Bb, and denote their averages by YjY_j. If the block averages are approximately independent, estimate

    Var⁡^(X‾)=1B(B−1)∑j=1B(Yj−X‾)2.\widehat{\operatorname{Var}}(\overline X) =\frac{1}{B(B-1)}\sum_{j=1}^{B}(Y_j-\overline X)^2.

    Increase bb until the error estimate becomes stable while retaining enough blocks to estimate its uncertainty. Very short blocks retain correlations; very long blocks leave too few observations. Normal intervals with an estimated variance can under-cover when BB is small. Blocking is a useful comparison, not a proof that an unseen slow mode is absent [1, Appendix B].

    For several genuinely independent runs, do not form lag pairs across their boundaries. Compare the run means as well as their within-run fluctuations. Keeping rejected proposals as repeated configurations is essential: deleting them changes the sampled history and generally its distribution.

    For a nonlinear quantity f(X‾)f(\overline{\mathbf X}), the leading fluctuating direction is ∇f⋅Xt\nabla f\cdot\mathbf X_t. Its autocorrelation can differ from every individual component's. Resample whole aligned blocks and repeat the nonlinear calculation inside each resample; independently resampling correlated numerator and denominator measurements destroys information needed for a ratio's error.

    A finite scalar-field correlator

    Consider eight real scalar variables with periodic labels ϕ8=ϕ0\phi_8=\phi_0 and dimensionless Euclidean action

    SE=12∑j=07[ϕj2+(ϕj+1−ϕj)2]=12ϕTKϕ.S_E=\frac12\sum_{j=0}^{7} \left[\phi_j^2+(\phi_{j+1}-\phi_j)^2\right] =\frac12\boldsymbol\phi^T K\boldsymbol\phi.

    The lattice spacing and mass in lattice units are both one. This is a fixed Gaussian target, not a continuum extrapolation. Its covariance is C=K−1C=K^{-1}, which can also be calculated by the discrete Fourier sum

    C0r=18∑n=07cos⁡(2πnr/8)1+4sin⁡2(πn/8).C_{0r}=\frac18\sum_{n=0}^{7} \frac{\cos(2\pi nr/8)}{1+4\sin^2(\pi n/8)}.

    Generate independent ξt∼N(0,C)\boldsymbol\xi_t\sim N(0,C) and use

    ϕt+1=aϕt+1−a2 ξt,ϕ0∼N(0,C).\boldsymbol\phi_{t+1}=a\boldsymbol\phi_t+ \sqrt{1-a^2}\,\boldsymbol\xi_t, \qquad \boldsymbol\phi_0\sim N(0,C).

    The new covariance is a2C+(1−a2)C=Ca^2C+(1-a^2)C=C, so the chain is stationary. Moreover E[ϕt,iϕt+k,j]=akCij\mathbb E[\phi_{t,i}\phi_{t+k,j}]=a^k C_{ij}. This exact global Gaussian update is chosen to test error estimation; it is not an efficient general-purpose algorithm for interacting fields.

    Measure Ot=ϕt,0ϕt,1O_t=\phi_{t,0}\phi_{t,1}. Its mean is C01=6/35C_{01}=6/35. Gaussian factorization gives three pairings in E[OtOt+k]\mathbb E[O_tO_{t+k}]. The same-time pairing is C012C_{01}^2 and cancels when we subtract the mean squared. The two cross-time pairings leave

    ΓO(k)=a2k(C00C11+C012),τint,O=1+a22(1−a2).\Gamma_O(k)=a^{2k}(C_{00}C_{11}+C_{01}^2), \qquad \tau_{\mathrm{int},O}=\frac{1+a^2}{2(1-a^2)}.

    At a=0.8a=0.8 the field component has τint=4.5\tau_{\mathrm{int}}=4.5, while this correlator has τint,O=41/18≃2.2778\tau_{\mathrm{int},O}=41/18\simeq2.2778. Analyze the measured observable rather than assigning every measurement the field's correlation time.

    Reproduce the coverage experiment

    The example examples/computational-qft/autocorrelation/check.py runs 1,024 independent stationary histories using NumPy's random generator with seed 20261021. It checks the covariance against both matrix inversion and Fourier modes, then compares the spread of run means with the exact finite-NN pair sum. Run it from the repository root with Python 3, NumPy, and Matplotlib:

    python3 examples/computational-qft/autocorrelation/check.py
    

    For each history it constructs the interval X‾±1.96σ^\overline X\pm1.96\widehat\sigma. Coverage is the fraction of these intervals containing the exact mean. The retained run gives:

    QuantitySamples per runTreating draws as independentUsing exact finite-NN varianceEstimated covariance, W=30W=30
    AR(1), a=0.8a=0.82,04846.5%93.8%93.2%
    AR(1), a=0.8a=0.88,19249.1%95.1%94.6%
    Scalar ϕ0ϕ1\phi_0\phi_12,04865.6%94.5%93.6%
    Scalar ϕ0ϕ1\phi_0\phi_18,19266.1%95.5%95.9%

    At 95% coverage the sampling uncertainty of a fraction estimated from 1,024 runs is about 0.68 percentage points. The experiments at the two lengths use prefixes of the same histories and are consequently correlated. The exact-variance interval is exactly Gaussian for the AR mean; for the bilinear field observable its normal form is a long-run approximation.

    The saved output also compares W=10,60,100W=10,60,100 and block lengths 32,128,25632,128,256. At N=2048N=2048, W=100W=100 produced four nonpositive variance estimates for the AR process and one for the field correlator. They are reported as invalid intervals and count as coverage failures, not silently clipped or discarded. Longer histories reduce these problems. These tests isolate stationary sampling errors; they say nothing about equilibration, multimodal exploration, or the interacting continuum limit.

    Thinning changes the estimator

    Retaining every ssth AR measurement changes its autocorrelation to aska^{sk}, so

    τint(s)=1+as2(1−as),Neff(s)Neff(1)≃1s1−as1+as1+a1−a\tau_{\mathrm{int}}^{(s)}=\frac{1+a^s}{2(1-a^s)}, \qquad \frac{N_{\mathrm{eff}}^{(s)}}{N_{\mathrm{eff}}^{(1)}} \simeq\frac1s\frac{1-a^s}{1+a^s}\frac{1+a}{1-a}

    at fixed total number of updates and long run length. With a=0.8a=0.8 and s=4s=4, the time in stored-sample units is 1.193771.19377; converting that time to update units gives 4.775074.77507, not the unthinned value 4.54.5. The effective sample size is about 94.24% of the unthinned value. Multiplying a measured time by the storage interval converts units; it does not recover the autocorrelation sum of the discarded history. Thinning can save storage or expensive measurement work, but that is a separate cost comparison.

    Markov-chain ESS also differs from the common importance-weight diagnostic (∑iwi)2/∑iwi2(\sum_i w_i)^2/\sum_i w_i^2. Equal weights make that diagnostic NN even when successive observations are strongly correlated. Neither diagnostic alone establishes overlap with an unvisited sector.

    For a correlator, keep the whole vector of Euclidean separations together when blocking Monte Carlo updates. Even independent field configurations contribute correlated estimates at different separations. The periodic scalar mass calculation gives downloadable means and their full covariance, then compares the mass obtained with full and diagonal weights.

    Compare the exactly known slow tail above with the measured Ising energy and squared-magnetization histories. The local and cluster chains use different amounts of work per update, so their lag cutoffs and their estimated errors must be compared in common units.

    Summary

    Derive the uncertainty of a mean from the covariance of its actual observable. State the update unit and autocorrelation convention, retain rejected states, examine the lag window and block size, and use exact examples and independent runs to test the reported intervals. An apparently large effective sample size cannot establish that the chain reached the intended distribution.

    Exercises

    1. Check a nonlinear observable. For stationary AR(1) with unit variance, find the autocorrelation time of Yt=Xt2Y_t=X_t^2 and compare it with that of XtX_t at a=−1/2a=-1/2.

    Solution

    Gaussian factorization gives E[Xt2Xt+k2]=1+2a2k\mathbb E[X_t^2X_{t+k}^2]=1+2a^{2k}, hence ΓY(k)=2a2k\Gamma_Y(k)=2a^{2k} and τint,Y=(1+a2)/[2(1−a2)]\tau_{\mathrm{int},Y}=(1+a^2)/[2(1-a^2)]. At a=−1/2a=-1/2 this is 5/65/6, while τint,X=1/6\tau_{\mathrm{int},X}=1/6. Negative correlations help the mean of XX, but squaring removes the alternating sign and gives positively correlated measurements.

    2. Quantify the hidden tail. What fraction of the asymptotic mean variance is retained by an exact W=10W=10 truncation in the two-mode example?

    Solution

    At fixed NN and one-measurement variance, the asymptotic mean variance is proportional to τint\tau_{\mathrm{int}}. The ratio is 1.586324/3.48≃0.455841.586324/3.48\simeq0.45584. Thus the variance estimate misses about 54.4%, and its standard error is only 0.45584≃0.6752\sqrt{0.45584}\simeq0.6752 of the correct value. More accurately measuring the first ten lags cannot repair the omitted tail.

    References

    1. U. Wolff, “Monte Carlo errors with less errors,” Computer Physics Communications 156 (2004), 143–153, corrected arXiv version 4 (2006). Full text. Sections 2–3 discuss correlated observables and covariance-sum error estimates; Appendix B compares binning.

    Scrollable formula. Use Left and Right arrow keys to reveal hidden content.

    Scrollable table. Use Left and Right arrow keys to reveal hidden columns.

    Scrollable figure. Use Left and Right arrow keys to reveal hidden content.