def test_d2(): # Test d2.d2() # Compute the local slope of 2x + 3x^2 and verify that # it is equal to 2 + 6x. x = np.linspace(-5, 5, 1000) y = 2 * x + 3 * x ** 2 p, q = np.exp(x), np.exp(y) assert_allclose(d2.d2(p, q), (2 + 6 * x[3:-3]))
Expected: D2 = 2 / (alpha - 1) = 2.0 Of course, this value is not due to the existence of any invariant measure. What is being measured here is the fractal dimension of the Brownian trail. The scaling region would vanish if we impose a nonzero Theiler window, telling us that the underlying system is not low dimensional. """ import numpy as np import matplotlib.pyplot as plt from nolitsa import d2, data, utils np.random.seed(101) x = utils.rescale(data.falpha(alpha=2.0, length=(2 ** 14))[:10 * 1000]) dim = np.arange(1, 10 + 1) tau = 500 plt.title('Local $D_2$ vs $r$ for Brown noise') plt.xlabel(r'Distance $r$') plt.ylabel(r'Local $D_2$') for r, c in d2.c2_embed(x, tau=tau, dim=dim, window=0, r=utils.gprange(0.001, 1.0, 100)): plt.semilogx(r[2:-2], d2.d2(r, c, hwin=2), color='#4682B4') plt.semilogx(utils.gprange(0.001, 1.0, 100), 2.0 * np.ones(100), color='#000000') plt.show()
# -*- coding: utf-8 -*- """D2 of the Ikeda map. The estimates here match the "accepted" value of 1.690 quite closely. """ import numpy as np import matplotlib.pyplot as plt from nolitsa import d2, data, utils x = utils.rescale(data.ikeda(length=5000)[:, 0]) dim = np.arange(1, 10 + 1) tau = 1 plt.title('Local $D_2$ vs $r$ for Ikeda map') plt.xlabel(r'Distance $r$') plt.ylabel(r'Local $D_2$') for r, c in d2.c2_embed(x, tau=tau, dim=dim, window=2, r=utils.gprange(0.001, 1.0, 100)): plt.semilogx(r[3:-3], d2.d2(r, c), color='#4682B4') plt.semilogx(utils.gprange(0.001, 1.0, 100), 1.690 * np.ones(100), color='#000000') plt.show()
np.random.seed(882) n = np.random.normal(size=(N), loc=0, scale=1.0) a = 0.998 x[0] = n[0] for i in range(1, N): x[i] = a * x[i - 1] + n[i] # Delay is the autocorrelation time. tau = 400 dim = np.arange(1, 10 + 1) plt.figure(1) plt.title(r'Local $D_2$ vs $r$ for AR(1) time series with $W = 0$') plt.xlabel(r'Distance $r$') plt.ylabel(r'Local $D_2$') for r, c in d2.c2_embed(x, tau=tau, dim=dim, window=0): plt.semilogx(r[3:-3], d2.d2(r, c)) plt.figure(2) plt.title(r'Local $D_2$ vs $r$ for AR(1) time series with $W = 400$') plt.xlabel(r'Distance $r$') plt.ylabel(r'Local $D_2$') for r, c in d2.c2_embed(x, tau=tau, dim=dim, window=400): plt.semilogx(r[3:-3], d2.d2(r, c)) plt.show()
def _corr_dim(self, signal, ac_zero): r, C_r = c2_embed(signal, [self.Q], ac_zero)[0] return d2(r[:self.Q], C_r[:self.Q])[0]
#!/usr/bin/env python # -*- coding: utf-8 -*- """D2 for white noise. D2 is (theoretically) equal to the embedding dimension for white noise. """ import numpy as np import matplotlib.pyplot as plt from nolitsa import d2, utils x = np.random.random(5 * 1000) dim = np.arange(1, 10 + 1) tau = 1 plt.title('Local $D_2$ vs $r$ for white noise') plt.xlabel(r'Distance $r$') plt.ylabel(r'Local $D_2$') for r, c in d2.c2_embed(x, tau=tau, dim=dim, window=2, r=utils.gprange(0.001, 1.0, 100)): plt.semilogx(r[1:-1], d2.d2(r, c, hwin=1), color='#4682B4') plt.show()