Esempio n. 1
0
def test_gprange():
    # Test utils.gprange()
    num = 10
    pi = np.pi

    # Start and end are both positive.
    start, end = pi, pi * pi**(num - 1)
    desired = pi * pi**np.arange(num)
    assert_allclose(utils.gprange(start, end, num=num), desired)

    # Start and end have different signs.
    start, end = pi, pi * (-pi)**(num - 1)
    desired = pi * (-pi)**np.arange(num)
    assert_allclose(utils.gprange(start, end, num=num), desired)
Esempio n. 2
0
def test_ttmle():
    # Test d2.ttmle()
    r_min, r_max = 1.0, 10.0
    r = utils.gprange(r_min, r_max, 100)
    c = np.e * r ** np.pi

    desired = np.pi
    assert_allclose(desired, d2.ttmle(r, c, zero=True)[1])

    desired = np.pi * (c[1:] / (c[1:] - c[0]))
    assert_allclose(desired, d2.ttmle(r, c, zero=False)[1])
Esempio n. 3
0
def test_c2_embed():
    # Test d2.c2_embed()
    t = np.linspace(0, 10 * 2 * np.pi, 5000)
    y = np.array([np.sin(t), np.cos(t)]).T
    r = utils.gprange(0.01, 1, 1000)
    desired = d2.c2(y, r=r)[1]

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

    assert_allclose(desired, d2.c2_embed(x, dim=dim, tau=tau, r=r)[0][1],
                    atol=1e-3)
Esempio n. 4
0
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()
Esempio n. 5
0
# -*- 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()
Esempio n. 6
0
Thus, the estimated correlation dimension would heavily depend on the
Theiler window used.  However, the values of C(r) at large r's would
roughly be the same.
"""

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

phi = np.linspace(2 * np.pi, 52 * np.pi, 1000)
x = phi * np.cos(phi)
x = utils.rescale(x)

dim = np.arange(1, 10 + 1)
tau = 10
r = utils.gprange(0.01, 1.0, 100)

plt.figure(1)
plt.title('Correlation sum $C(r)$ without any Theiler window')
plt.xlabel(r'Distance $r$')
plt.ylabel(r'Correlation sum $C(r)$')

for r, c in d2.c2_embed(x, tau=tau, dim=dim, window=0, r=r):
    plt.loglog(r, c)

plt.figure(2)
plt.title('Correlation sum $C(r)$ with a Theiler window of 100')
plt.xlabel(r'Distance $r$')
plt.ylabel(r'Correlation sum $C(r)$')

for r, c in d2.c2_embed(x, tau=tau, dim=dim, window=100, r=r):