コード例 #1
0
ファイル: test_utils.py プロジェクト: mirgee/nolitsa
def test_spectrum():
    # Test utils.spectrum()
    # Parseval's theorem.
    for length in (2**10, 3**7):
        x = np.random.random(length)
        power = utils.spectrum(x)[1]
        assert_allclose(np.mean(x**2), np.sum(power))
コード例 #2
0
ファイル: test_data.py プロジェクト: yanyan-cas/nolitsa
def test_falpha():
    # Tests data.falpha()
    x = data.falpha(length=(2**10), mean=np.pi, var=np.e)
    assert_allclose(np.mean(x), np.pi)
    assert_allclose(np.std(x)**2, np.e)

    for length in (2**10, 3**7):
        for alpha in (1.0, 2.0, 3.0):
            mean, var = 1.0 + np.random.random(2)
            x = data.falpha(alpha=alpha, length=length, mean=mean, var=var)

            # Estimate slope of power spectrum.
            freq, power = utils.spectrum(x)
            desired = np.mean(
                np.diff(np.log(power[1:])) / np.diff(np.log(freq[1:])))

            assert_allclose(-alpha, desired)
コード例 #3
0
ファイル: roessler.py プロジェクト: yanyan-cas/nolitsa
"""Maximum Lyapunov exponent of the Rössler oscillator.

The "accepted" value is 0.0714, which is quite close to what we get.
"""
from nolitsa import data, lyapunov, utils
import numpy as np
import matplotlib.pyplot as plt

sample = 0.2
x0 = [-3.2916983, -1.42162302, 0.02197593]
x = data.roessler(length=3000, x0=x0, sample=sample)[1][:, 0]

# Choose appropriate Theiler window.
# Since Rössler is an aperiodic oscillator, the average time period is
# a good choice.
f, p = utils.spectrum(x)
window = int(1 / f[np.argmax(p)])

# Time delay.
tau = 7

# Embedding dimension.
dim = [3]

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

plt.title(u'Maximum Lyapunov exponent for the Rössler oscillator')
plt.xlabel(r'Time $t$')
plt.ylabel(r'Average divergence $\langle d_i(t) \rangle$')
plt.plot(sample * t, d)