Example #1
0
def LLE(x):
    dt = 0.01
    meanperiod = 10
    maxt = 150
    # d = lyapunov.mle(x, maxt=maxt, window=meanperiod)
    d = lyapunov.mle_embed(np.squeeze(x),
                           dim=[5],
                           maxt=maxt,
                           window=meanperiod,
                           parallel=False)
    d = np.squeeze(d)
    t = np.arange(maxt) * dt
    coefs = poly_fit(t, d, 1)
    print('LLE = ', coefs[0])

    plt.figure()
    plt.title('Maximum Lyapunov exponent for the ' + system_name)
    plt.xlabel(r'Time $t$')
    plt.ylabel(r'Average divergence $\langle d_i(t) \rangle$')
    plt.plot(t, d, label='divergence')
    plt.plot(t, coefs[1] + coefs[0] * t, '--', label='RANSAC')
    plt.legend()
    # plt.show()

    return coefs[0]
Example #2
0
def test_mle_embed():
    # Test lyapunov.mle_embed()
    t = np.linspace(0, 10 * 2 * np.pi, 5000)
    y = np.array([np.sin(t), np.cos(t)]).T
    desired = lyapunov.mle(y, maxt=25)

    dim = [2]
    tau = 125
    x = y[:, 0]

    assert_allclose(desired,
                    lyapunov.mle_embed(x, dim=dim, tau=tau, maxt=25)[0],
                    atol=1e-1)
Example #3
0
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)

plt.show()
Example #4
0
 def _max_lyap(self, signal, ac_zero):
     y = mle_embed(signal, [self.Q], ac_zero, maxt=self.lyap_maxt)[0]
     x = np.arange(len(y))
     return np.polyfit(x, y, 1)[0]
Example #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Maximum Lyapunov exponent exponent of the Henon map.

The "accepted" value is ~ 0.419, which is quite close to the estimates
we get here.  See Fig. 3(b) of Rosenstein et al. (1993).
"""

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

x = data.henon(length=5000)[:, 0]

# Time delay.
tau = 1

# Embedding dimension.
dim = [2]

d = lyapunov.mle_embed(x, dim=dim, tau=tau, maxt=25)[0]
t = np.arange(25)

plt.title('Maximum Lyapunov exponent for the Henon system')
plt.xlabel(r'Time $t$')
plt.ylabel(r'Average divergence $\langle d_i(t) \rangle$')
plt.plot(t, d)
plt.plot(t, t * 0.419 + d[0], '--')

plt.show()