The following code is part of the code in ATAT , the file name is equil' . It is the algorithm to calculate the row’, I do not understand this algorithm for searching `row’. Would you kindly add a few comments?
Real corr;
Real last_corr=0.5;
int done=0;
while (!done) {
corr=0.;
for (int i=0; i<granularity-cur_corr_len; i++) {
corr+=buf_val(i)*buf_val(i+cur_corr_len);
}
corr/=(Real)(granularity-cur_corr_len);
corr-=sqr((bin_sum(cur_bin)(which_elem)-bin_sum(cur_bin-1)(which_elem))/(Real)granularity);
Real var=(bin_sum2(cur_bin)(which_elem)-bin_sum2(cur_bin-1)(which_elem))/(Real)granularity
-sqr((bin_sum(cur_bin)(which_elem)-bin_sum(cur_bin-1)(which_elem))/(Real)granularity);
if (var>0) {
corr/=var;
}
else {
corr=1.;
}
done=1;
if (corr<0.) corr=0.;
if (corr<0.25 && last_corr<=0.75 && cur_corr_len>=2) {cur_corr_len/=2; done=0;}
if (corr>0.75 && last_corr>=0.25 && cur_corr_len<granularity/4) {cur_corr_len*=2; done=0;}
last_corr=corr;
}
corr=pow(corr,1./(Real)cur_corr_len);
buf_corr(cur_bin)=corr;
The idea is to find a length (of time) such that the correlation is about 1/2. I do this by bisection: halfing or doubling the trial length until a find the right value.
Then, the line
corr=pow(corr,1./(Real)cur_corr_len);
Converts the correlation for a length of time cur_corr_len into a correlation for one time step (assuming correlations decay exponentially).
BTW, another reason for using the 1/2 as the target is that if the correlation of the process decays as a sum of exponential, taking a long time (corresponding to 1/2 decay) makes sure that all other transients have decayed and only the dominant exponential is taken into account.
I’ll try to put more comments in the code there… may take time
Thank you very much for the comments. Now I understand better…
I tested this algorithm by calculating the "corr" value for every 100 MC steps(for every 100 data points collected, calculate corr value) and got the following results:
1.08847971188175
1.17148271587158
0.000000000000000E+000
1.17038096136324
1.10354147622102
1.08504928221464
1.13088017233617
1.15389875808912
1.15813268886841
1.19092326187063
1.17277944558781
1.09549652143627
1.20223975056106
1.35514724933907
…
the corr value should be less than one indeed b/c its a decaying process from maximal value 1. And also the later calculation for variance of the averaged energy by equation Var[Q]=V/n(1+corr)/(1-corr) requires that the corr value should be less than 1 to yield a positive variance value. However the results seem to be incorrect for every 100 data points, sometimes it is zero, although the average corr value for several groups of data may be less than 1…Would you kindly give some comments about this problem? Thanks very much!
I test this bisection searching for corr in my own code… if there are 100 Monte Carlo data points, one can always calculate the correlation by the this algorithm. Would you please give some comments if the calculated correlation value is larger than 1 using this bisection searching? Is there the same issue in ATAT software? Thanks very much!
Sorry but I have no idea why your code would find a correlation >1. I don’t if ATAT has the same. If it does, please send me your input files for me to reproduce the problem and fix it. I am always happy to eliminate a bug if it’s there.