Skip to content

Commit 27761c2

Browse files
committed
Adding test_autocorr1D to test_sampling.py.
1 parent f87ff93 commit 27761c2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

cmeutils/tests/test_sampling.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import numpy as np
22
import pytest
3+
import scipy
34

4-
from cmeutils.sampling import equil_sample, is_equilibrated
5+
from cmeutils.sampling import equil_sample, is_equilibrated, autocorr1D
56
from cmeutils.tests.base_test import BaseTest
67

78

@@ -82,3 +83,19 @@ def test_trim_high_threshold(self, correlated_data_tau100_n10000):
8283
[equil_data, uncorr_indices, prod_start, Neff] = equil_sample(
8384
data, threshold_fraction=0.75, threshold_neff=10000
8485
)
86+
def test_autocorr1D(self):
87+
randoms = np.random.randint(100, size=(100))
88+
integers = np.array(np.arange(100))
89+
90+
autocorrelation_randoms = autocorr1D(randoms)
91+
autocorrelation_integers = autocorr1D(integers)
92+
93+
def expfunc(x, a):
94+
return np.exp(-x/a)
95+
x_values = np.array(range(len(autocorrelation_integers)))
96+
97+
exp_coeff_randoms = scipy.optimize.curve_fit(expfunc,x_values,autocorrelation_randoms)[0][0]
98+
exp_coeff_int = scipy.optimize.curve_fit(expfunc,x_values,autocorrelation_integers)[0][0]
99+
100+
assert round(autocorrelation_integers[0],10) and round(autocorrelation_randoms[0],10) == 1
101+
assert exp_coeff_int > 5 and exp_coeff_randoms < 1

0 commit comments

Comments
 (0)