def test_adfd(): # Test delay.adfd() # Embed a straight line. a, b = 1.0 + np.random.random(2) t = np.arange(1000) x = a + b * t # Sum of squares of first n natural numbers. sqsum = lambda n: n * (n + 1) * (2 * n + 1) / 6.0 dim, maxtau = 7, 25 desired = np.sqrt(sqsum(dim - 1)) * b * np.arange(maxtau) assert_allclose(delay.adfd(x, dim=dim, maxtau=maxtau), desired)
from nolitsa import data, delay sample = 0.25 x = data.mackey_glass(length=2500, a=0.2, b=0.1, c=10.0, tau=17.0, discard=500, sample=sample) dim = 7 maxtau = 50 tau = np.arange(maxtau) disp = delay.adfd(x, dim=dim, maxtau=maxtau) ddisp = np.diff(disp) forty = np.argmax(ddisp < 0.4 * ddisp[1]) print(r'Time delay %d' % forty) fig, ax1 = plt.subplots() ax1.set_xlabel(r'Time ($\tau\Delta t$)') ax1.set_ylabel(r'$\mathrm{ADFD}$') ax1.plot(tau[1:] * sample, disp[1:]) ax2 = ax1.twinx() ax2.plot(tau[1:] * sample, ddisp, 'g--') ax2.plot(tau[forty + 1] * sample, ddisp[forty], 'o') ax2.set_ylabel(r'$\frac{d}{d\tau}(\mathrm{ADFD}$)')