I am trying to use Python to plot the graph of autocorrelation function of metropolis algorithm by following the methodology of this lecture note. Autocorrelation function in this lecture note are defined as this and the graph should look like this with small standard deviation. Here is my code:
def computeAutocorrelation(Q_list,taunum,knum):
A_list_tau = []
A_std_tau = []
for tau in range(taunum):
A_list_k = [(Q_list[k]*Q_list[k+tau]- np.mean(Q_list[:knum-tau])**2)/variance(Q_list[:knum-tau]) for k in range(knum-tau)]
A_list_tau.append(np.mean(A_list_k))
A_std_tau.append(np.std(A_list_k))
if A_list_tau[-1] <=0.01:
A_list_tau.extend([np.nan]*(taunum-len(A_list_tau)))
A_std1_tau.extend([np.nan]*(taunum-len(A_std_tau)))
break
return A_list_tau, A_std1_tau
However when I plot this function, my graph look like this with large standard deviation.
Is there any mistake(s) I made in calculating autocorrelation function or standard deviation?