From 000322b7443a3e279365cadcb1574735936586b1 Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Sun, 1 Sep 2024 16:59:16 -0400 Subject: [PATCH] add some basic accuracy checking to ac fit --- neurodsp/tests/aperiodic/test_autocorr.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/neurodsp/tests/aperiodic/test_autocorr.py b/neurodsp/tests/aperiodic/test_autocorr.py index 3137e1ba..5db31cca 100644 --- a/neurodsp/tests/aperiodic/test_autocorr.py +++ b/neurodsp/tests/aperiodic/test_autocorr.py @@ -20,6 +20,7 @@ def test_compute_decay_time(tsig): assert isinstance(decay_time, float) def test_fit_autocorr(tsig): + # This is a smoke test - check it runs with no accuracy checking timepoints, autocorrs = compute_autocorr(tsig, max_lag=500) @@ -36,3 +37,21 @@ def test_fit_autocorr(tsig): popts2 = fit_autocorr(timepoints, autocorrs, fit_function='double_exp') fit_vals2 = compute_ac_fit(timepoints, *popts2, fit_function='double_exp') assert np.all(fit_vals2) + +def test_fit_autocorr_acc(): + # This test includes some basic accuracy checking + + fs = 100 + tau = 0.015 + lags = np.linspace(0, 100, 1000) + + # Test can fit and recompute the tau value + corrs1 = exp_decay_func(lags, tau, 1, 0) + params1 = fit_autocorr(lags, corrs1) + assert np.isclose(params1[0], tau, 0.001) + + # Test can fit and recompute the tau value - timepoints as time values + lags = lags / fs + corrs2 = exp_decay_func(lags, tau, 1, 0) + params2 = fit_autocorr(lags, corrs2) + assert np.isclose(params2[0], tau, 0.001)