def draw_attractor() -> None: tspan = np.linspace(0, tEnd, dSize) ys = odeint(sys, startPoint, tspan, rtol=0.0000000001, atol=0.0000000001) xx, yy = np.meshgrid(ys[:, 0], ys[:, 0]) I = (abs(xx - yy) - epsillon) > 0 tspan = np.linspace(0, tEnd, tSize) yso = ys ys = odeint(sys, startPoint, tspan) lag = np.arange(250) x = ys[:, 0] r = delay.acorr(x, maxtau=250) i = delay.dmi(x, maxtau=250) i_delay = localmin(noise.sma(i, hwin=1)) + 1 r_delay = np.argmax(r < 1.0 / np.e) print(r'Minima of delayed mutual information = %s' % i_delay) print(r'Autocorrelation time = %d' % r_delay) dim = np.arange(1, 15 + 1) tau_here = (localmin(noise.sma(delay.dmi(x, maxtau=250), hwin=1)) + 1)[0] tau_here = np.argmax(delay.acorr(yso[:, 0], maxtau=250) < 1.0 / np.e) f = dimension.fnn(yso[:, 0], tau=tau_here, dim=dim, window=0, metric='euclidean') fig = plt.figure(1) ax = plt.axes(projection='3d') ax.plot3D(ys[:, 0], ys[:, 1], ys[:, 2], alpha=0.75) plt.figure(2) plt.imshow(I, cmap=plt.cm.gray, origin='lower') plt.figure(3) plt.subplot(211) plt.plot(tspan, ys[:, 0]) plt.subplot(212) plt.plot(tspan, ys[:, 1]) plt.figure(4) plt.subplot(121) plt.plot(ys[:, 0], ys[:, 1]) plt.subplot(122) plt.plot(ys[:, 0], ys[:, 2]) plt.figure(5) # ~ plt.subplot(121) # ~ plt.title(r'Time delay = %d' % r_delay) # ~ plt.xlabel(r'$x(t)$') # ~ plt.ylabel(r'$x(t + \tau)$') # ~ plt.plot(ys[:-r_delay,0], ys[r_delay:,0]) # ~ plt.subplot(122) plt.title(r'Time delay = %d' % i_delay[0]) plt.xlabel(r'$x(t)$') plt.ylabel(r'$x(t + \tau)$') plt.plot(ys[:-i_delay[0], 0], ys[i_delay[0]:, 0]) plt.figure(6) plt.ylabel(r'Delayed mutual information') plt.plot(lag, i, i_delay, i[i_delay], 'o') plt.figure(7) plt.plot(dim, f[0], dim, f[1], dim, f[2]) plt.xlabel(r'Embedding dimension $d$') plt.ylabel(r'FNN (%)') plt.figure(8) ax = plt.axes(projection='3d') ax.plot3D(ys[:-2 * i_delay[0], 0], ys[i_delay[0]:-i_delay[0], 0], ys[2 * i_delay[0]:, 0], alpha=0.75) print(ys[-1]) plt.show()
1D scalar data set. Returns ------- i : array Array containing location of all local minima. """ return (np.diff(np.sign(np.diff(x))) > 0).nonzero()[0] + 1 x = data.lorenz()[1][:, 0] # Compute autocorrelation and delayed mutual information. lag = np.arange(100) r = delay.acorr(x, maxtau=100) i = delay.dmi(x, maxtau=100) # While looking for local minima in the DMI curve, it's useful to do an # SMA to remove "kinky" minima. i_delay = localmin(noise.sma(i, hwin=1)) + 1 r_delay = np.argmax(r < 1.0 / np.e) print(r'Minima of delayed mutual information = %s' % i_delay) print(r'Autocorrelation time = %d' % r_delay) plt.figure(1) plt.subplot(211) plt.title(r'Delay estimation for Lorenz attractor') plt.ylabel(r'Delayed mutual information') plt.plot(lag, i, i_delay, i[i_delay], 'o')
of the delayed mutual information (DMI) of the series. The probabilities required for its computation are estimated by binning the time series. For many examples, the DMI at a lag of zero computed with 2^m bins is approximately m bits. This is because the distribution is nearly flat when the number of bins is small, making the probability of being in a bin ~ 2^-m. Surprisingly, using a small number of bins doesn't seem to affect the estimation of the delay. Even with two bins, the extremas of the DMI are clearly visible. (Why?) """ import numpy as np import matplotlib.pyplot as plt from nolitsa import data, delay x = data.mackey_glass() plt.title(r'Delayed mutual information for the Mackey-Glass system') plt.xlabel(r'$\tau$') plt.ylabel(r'$I(\tau)$') for bins in (2**np.arange(1, 8 + 1)): ii = delay.dmi(x, maxtau=500, bins=bins) plt.plot(ii, label=(r'Bins = $%d$' % bins)) plt.legend() plt.show()
1D scalar data set. Returns ------- i : array Array containing location of all local minima. """ return (np.diff(np.sign(np.diff(x))) > 0).nonzero()[0] + 1 x = data.roessler()[1][:, 0] # Compute autocorrelation and delayed mutual information. lag = np.arange(250) r = delay.acorr(x, maxtau=250) i = delay.dmi(x, maxtau=250) # While looking for local minima in the DMI curve, it's useful to do an # SMA to remove "kinky" minima. i_delay = localmin(noise.sma(i, hwin=1)) + 1 r_delay = np.argmax(r < 1.0 / np.e) print(r'Minima of delayed mutual information = %s' % i_delay) print(r'Autocorrelation time = %d' % r_delay) plt.figure(1) plt.subplot(211) plt.title(r'Delay estimation for Rössler oscillator') plt.ylabel(r'Delayed mutual information') plt.plot(lag, i, i_delay, i[i_delay], 'o')
of the delayed mutual information (DMI) of the series. The probabilities required for its computation are estimated by binning the time series. For many examples, the DMI at a lag of zero computed with 2^m bins is approximately m bits. This is because the distribution is nearly flat when the number of bins is small, making the probability of being in a bin ~ 2^-m. Surprisingly, using a small number of bins doesn't seem to affect the estimation of the delay. Even with two bins, the extremas of the DMI are clearly visible. (Why?) """ import numpy as np import matplotlib.pyplot as plt from nolitsa import data, delay x = data.roessler()[1][:, 0] plt.title(r'Delayed mutual information for the Rössler oscillator') plt.xlabel(r'$\tau$') plt.ylabel(r'$I(\tau)$') for bins in (2**np.arange(1, 8 + 1)): ii = delay.dmi(x, maxtau=250, bins=bins) plt.plot(ii, label=(r'Bins = $%d$' % bins)) plt.legend() plt.show()