Exemplo n.º 1
0
def test_corrupt():
    # Test utils.corrupt()
    x = np.random.random(100)
    x = x - np.mean(x)
    assert_allclose(utils.corrupt(x, x, snr=16.0), 1.25 * x)
Exemplo n.º 2
0
"""Maximum Lyapunov exponent of a closed noisy curve.

A trajectory in the form of a closed curve should have a Lyapunov
exponent equal to zero (or the average divergence should not vary with
time).  But our curves for the average divergence appear to be
oscillatory and don't look very flat.  What's wrong?
"""

import numpy as np
import matplotlib.pyplot as plt
from nolitsa import lyapunov, utils

t = np.linspace(0, 100 * np.pi, 5000)
x = np.sin(t) + np.sin(2 * t) + np.sin(3 * t) + np.sin(5 * t)
x = utils.corrupt(x, np.random.normal(size=5000), snr=1000)

# Time delay.
tau = 25

window = 100

# Embedding dimension.
dim = [10]

d = lyapunov.mle_embed(x, dim=dim, tau=tau, maxt=300, window=window)[0]

plt.title('Maximum Lyapunov exponent for a closed curve')
plt.xlabel(r'Time $t$')
plt.ylabel(r'Average divergence $\langle d_i(t) \rangle$')
plt.plot(t[:300], d)
Exemplo n.º 3
0
We will compare the effectiveness of a linear filter like the simple
moving average (SMA) and nonlinear noise reduction in filtering a noisy
deterministic time series (from the Henon map).

As we can see, SMA performs quite badly and distorts the structure in
the time series considerably (even with a very small averaging window).
However, nonlinear reduction works well (within limits).
"""

import numpy as np
import matplotlib.pyplot as plt
from nolitsa import data, noise, utils

x = data.henon()[:, 0]
x = utils.corrupt(x, np.random.normal(size=(10 * 1000)), snr=500)

y1 = noise.nored(x, dim=7, tau=1, r=0.10, repeat=5)
y2 = noise.sma(x, hwin=1)

plt.figure(1)
plt.title('Time series from the Henon map with an SNR of 500')
plt.xlabel('$x_1$')
plt.ylabel('$x_2$')
plt.plot(x[:-1], x[1:], '.')

plt.figure(2)
plt.title('After doing an SMA over 3 bins')
plt.xlabel('$x_1$')
plt.ylabel('$x_2$')
plt.plot(y2[:-1], y2[1:], '.')