9
$\begingroup$

I'm writing this code of molecular dynamics about a pseudo-ideal gas in a box. The task is integrating the EOM for every atoms for a time-step dt fixed with the leapfrog method and measure the total energy, kinetic energy, potential energy (Lenard-Jones) plus the temperature and pressure. For the latters I should measure the autocorrelation function, given as: $$ \Gamma(t)=\frac{1}{N-t}\sum_{i=1}^{N-t}(X_i-\bar{X})(X_{i+t}-\bar{X})\tag{1} $$ Where $X_i$ is the measure at the step $i$ and $\bar{X}$ is the mean value. Once did that, I should measure the autocorrelation time which was given to us as: $$ \tau_{int}=\frac{1}{2}(1+2\sum_{t=1}^{N}\Gamma(t)) \tag{2} $$ This $\tau_{int}$ should give us an estimation of the true autocorrelation time, that would be, if the autocorrelation function was not discrete: $$ \tau=\int_0^{+\infty} e^{-\frac{t}{\tau}}dt\tag{3} $$ In my simuation I get $\tau_{int}\approx0.5$, which may tell me measures aren't correlated, the problem is I get that value whatever interval step I choose between a measure and the next one. In my case I get $\tau_{int}\approx0.5$ for an interval of number of step $k=100$ and $k= 10$. To be honest I don't know how to explain it, mainly because I can't give meaning to the definition of $\tau_{int}$, if someone could explain me the reason behind that definition I woud be glad.

$\endgroup$
2
  • 1
    $\begingroup$ +1 and welcome to our new community! Thank you for contributing your question here and we hope to see much more of you in the future !!! I would recommend that you add references to show us where those formulas came from (so that we can look deeper into what this specific formula for the autocorrelation time means) and to show us that data in a code block, from which you keep gettting 0.5 no matter what interval you use. $\endgroup$ Commented Nov 16, 2021 at 17:22
  • $\begingroup$ I don't understand the last equation. For $\tau >0$, the integral always yields $\tau$. So how do you relate this with the continuous autocorrelation function? As far as I understood you, the $\tau_{\mathrm{int}}$ appears since $\Gamma$ is discrete and for a continuous $\Gamma$, we would've (ideally) obtained $\tau$- but in your 'definition' of $\tau$, no (continuous) $\Gamma$ appears... $\endgroup$
    – Jakob
    Commented Nov 16, 2021 at 19:59

1 Answer 1

9
$\begingroup$

The autocorrelation time comes from the statistical analysis of ergodic systems, where one is interested in obtaining statistical averages of an observable $A$ by drawing samples from a distribution in a time-dependent manner, i.e.:

$$\left<{A}\right>\approx \bar{A}\equiv \frac{1}{N}\sum_{i=1}^N A_i \tag{1}$$

Where $N$ is the total number of samples, $\left<{A}\right>$ is the true expectation value/ensemble average and $\bar{A}$ is the estimated ensemble average.

Usually, one is interested in the convergence of this calculation, or more specifically, the variance of the estimate $\bar{A}$. This is well-known to be (e.g. Eq. 15 here or here):

\begin{equation} \begin{aligned} Var[\bar{A}] &= \left<\bar{A}^2\right> - \left<\bar{A}\right>^2 \\ &= \left<\Bigg(\frac{1}{N}\sum_{i=1}^N A_i\Bigg)^2\right> - \left<\frac{1}{N}\sum_{i=1}^N A_i\right>^2\\ &=\frac{1}{N^2}\sum_{i=1}^{N}\sum_{j=1}^{N}A_iA_j - \Bigg(\frac{1}{N}\sum_{i=1}^{N}A_i\Bigg)\Bigg(\frac{1}{N}\sum_{j=1}^{N}A_j\Bigg) \\ &= \frac{1}{N}Var[A_i] + \frac{2}{N}\sum_{t=1}^N Cov[A_i,A_{i+t}] \end{aligned}\tag{2} \end{equation}

If we define the quantity $\frac{Cov[A_i,A_{i+t}]}{Var[A_i]}$ to be the discrete time-normalised autocorrelation function $\Gamma(t)$, we obtain:

$$Var[\bar{A}]=\frac{1}{N}Var[A_i]\Bigg(1 + 2\sum_{t=1}^N \Gamma(t)\Bigg) \tag{3} $$

Defining the relative autocorrelation time to be $\tau = 1 + 2\sum_{t=1}^N \Gamma(t)$, we see that when $\tau=1$, the variance of the estimator reduces to the variance of the mean, as expected. Note that $\tau$ is dimensionless and is relative to the sampling time, so there is no contradiction if you obtain $\tau \approx 1$ at different time intervals. This just means that your samples are effectively decorrelated at both timescales. On the other hand, larger $\tau$ means that $\frac{1}{N}Var[A_i]$ underestimates $Var[\bar{A}]$, so if you ignore this correlation, you will systematically be underestimating the true variance of the mean.

Edit: Another way to look at this is by defining an effective sample size $N_{eff}=N/\tau$. This is basically the "real" number of samples you have which you can use to estimate the variance of the mean using the usual approach. And if you have $N_{eff}$ real samples after $N$ steps, that means that you only create a new effective sample every $\tau$ steps on average.

$\endgroup$
2
  • 2
    $\begingroup$ +10. Amazing Godzilla! I was hoping this would happen! One thing that might help is if you number the equations like I did for the question. Even if you're not referring to them, someone else that cites this answer might want to say "like in Eq. 4 of Godzilla's answer" rather than saying something like "in the third equation in the second group of equations in Godzilla's answer". $\endgroup$ Commented Nov 17, 2021 at 0:39
  • $\begingroup$ Good idea, thanks for that Nike! $\endgroup$
    – Godzilla
    Commented Nov 17, 2021 at 0:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .