Skip to content

Commit

Permalink
add some basic accuracy checking to ac fit
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Sep 1, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
edmorley Ed Morley
1 parent 6af8c61 commit 000322b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions neurodsp/tests/aperiodic/test_autocorr.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 000322b

Please sign in to comment.