Skip to content

Commit

Permalink
Adding autocorrelation function to sampling.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
madilynpaul committed May 17, 2024
1 parent a642a34 commit 846bcd3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmeutils/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,14 @@ def is_equilibrated(data, threshold_fraction=0.50, threshold_neff=50, nskip=1):
return [True, t0, g, Neff]
else:
return [False, None, None, None]


def autocorr1D(array):
"""
Takes in a linear np array, performs autocorrelation
function and returns normalized array with half the length
of the input
"""
ft = np.fft.rfft(array - np.average(array))
acorr = np.fft.irfft(ft * np.conjugate(ft)) / (len(array) * np.var(array))
return acorr[0 : len(acorr) // 2]

0 comments on commit 846bcd3

Please sign in to comment.