예제 #1
0
def _get_data():
    """
    Runs the analysis and saves the data to be used later for plotting.
    """
    # get the Roessler trajectory
    print("Roessler trajectory ...")
    t = np.linspace(0., 1000., 100000.)
    params = (0.432, 2., 4.)
    x0 = (1., 3., 5.)
    pos = tm.roessler(x0, t, params)
    i_eq = 90000
    x, y, z = pos[i_eq:, 0], pos[i_eq:, 1], pos[i_eq:, 2]
    t = t[i_eq:]

    # set the X component as our measured signal
    s = x.copy()

    # get mi
    print("MI ...")
    maxlag = np.where(t <= (t[0] + 10.))[0][-1].astype("int")
    mi, mi_lags = rc.mi(s, maxlag)
    mi_filt, _ = utils.boxfilter(mi, filter_width=25, estimate="mean")
    tau_mi = rc.first_minimum(mi_filt)
    print("FNN ...")
    M = 10
    R = 0.50
    fnn_mi, dims_mi = rc.fnn(s, tau_mi, maxdim=M, r=R)
    m_mi = dims_mi[rc.first_zero(fnn_mi)]

    # save data
    print("save output ...")
    FN = "../data/delay_embedding/results"
    np.savez(FN,
             x=x,
             y=y,
             z=z,
             t=t,
             params=params,
             x0=x0,
             i_eq=i_eq,
             s=s,
             maxlag=maxlag,
             mi=mi,
             mi_lags=mi_lags,
             mi_filt=mi_filt,
             tau_mi=tau_mi,
             M=M,
             R=R,
             fnn_mi=fnn_mi,
             dims_mi=dims_mi,
             m_mi=m_mi)
    print("saved to: %s.npz" % FN)
    return None
예제 #2
0
 nR = len(aR)
 mR = 5000
 yR_eq = []
 kR = 5
 x0R = (-1. + 2. * np.random.rand(nR, kR),
        -1. + 2. * np.random.rand(nR, kR), 1. * np.random.rand(nR, kR))
 count = 0
 TOL = 1E-3
 pbar_on = True
 pb = _progressbar_start(max_value=nR * kR, pbar_on=pbar_on)
 for i in range(nR):
     params = (aR[i], bR, cR)
     yR_eq_ = []
     for l in range(kR):
         x0R_ = (x0R[0][i, l], x0R[1][i, l], x0R[2][i, l])
         XR = tm.roessler(x0R_, TR, params)
         xR_ = XR[-mR:, 0]
         yR_ = XR[-mR:, 1]
         if np.all((yR_[1:] - yR_[:-1]) < TOL):
             yR_eq_.extend(yR_)
         else:
             d2y = np.diff(np.sign(np.diff(yR_)))
             iipos = np.where(d2y == -2.)[0] + 1
             if len(iipos) > 0:
                 yR_eq_.extend(yR_[iipos])
             iineg = np.where(d2y == 2.)[0] + 1
             if len(iineg) > 0:
                 yR_eq_.extend(yR_[iineg])
         _progressbar_update(pb, count)
         count += 1
     np.random.shuffle(yR_eq_)
    for k in range(m):
        xe[k] = x[ne:] + E * std * re[k]
    xhi = np.percentile(xe, 97.5, axis=0)
    xlo = np.percentile(xe, 2.5, axis=0)
    # 2) plot
    ax1.plot(t, x, "-", c=main_clr, zorder=10, alpha=0.75)
    ax1.fill_between(te, xhi, xlo, color=err_clr)
    ax1.axvline(te[0], color="IndianRed", linestyle="--")

    # nonlinear example
    # -----------------
    print("nonlinear example ...")
    # 1) get primary time series
    params = (0.3, 0.4, 7.5)
    x0 = (0.0, -1., 1.)
    pos = tm.roessler(x0, t, params)
    x, y, z = pos[:, 0], pos[:, 1], pos[:, 2]
    # 2) get noise limit based on variance of main trajectory
    std = np.std(x)
    # 3) get upper and lower bounds on trajectory using erroneous IC
    ne = int(n / 2)
    te = t[ne:]
    xe = np.zeros((m, len(te)))
    re = np.random.randn(m)
    for k in range(m):
        xe0 = (x[ne] + E * std * re[k], y[ne], z[ne])
        pose = tm.roessler(xe0, t[ne:], params)
        xe[k] = pose[:, 0]
    xhi = np.percentile(xe, 97.5, axis=0)
    xlo = np.percentile(xe, 2.5, axis=0)
    # 2) plot
예제 #4
0
    clr3 = "IndianRed"

    # time vector
    T = np.linspace(0., 600., 600001)
    n = len(T)
    i = int(n / 2)
    t1 = T[:i]
    t2 = T[i:]
    neq = 50000

    # spiral-type chaos
    # -----------------
    print("spiral-type chaos ...")
    params = (0.32, 0.3, 4.5)
    x0 = (0.0, -1., 1.)
    pos = tm.roessler(x0, t1, params)
    x1, y1, z1 = pos[neq:, 0], pos[neq:, 1], pos[neq:, 2]

    # screw-type chaos
    # ----------------
    print("screw-type chaos ...")
    params = (0.38, 0.4, 4.820)
    x0 = (x1[-1], y1[-1], z1[-1])
    pos = tm.roessler(x0, t2, params)
    x2, y2, z2 = pos[neq:, 0], pos[neq:, 1], pos[neq:, 2]

    # get full time series and the mean and variance filter
    print("mean and variance ...")
    X = np.r_[x1, x2]
    T = T[:-2 * neq]
    n = len(T)
예제 #5
0
    ax2.imshow(R,
               cmap=pl.cm.gray_r,
               interpolation="none",
               origin="lower",
               rasterized=True)
    del R
    ax2.set_title(r"$\tau_e = %d, m_e = %d, \varepsilon = 0.15$" %
                  (tau_mi, m_mi),
                  fontsize=axlabfs)

    # C. Chaotic Roessler
    print("C. Chaotic Roessler ...")
    t = np.linspace(0., 1000., 100000.)
    params = (0.432, 2., 4.)
    x0 = (1., 3., 5.)
    pos = tm.roessler(x0, t, params)
    i_eq = 50000
    sample_every = 10
    t = t[i_eq::sample_every]
    # set the X component as our measured signal
    x = pos[i_eq::sample_every, 0]
    # get mi
    maxlag = np.where(t <= (t[0] + 10.))[0][-1].astype("int")
    mi, mi_lags = rc.mi(x, maxlag)
    mi_filt, _ = utils.boxfilter(mi, filter_width=25, estimate="mean")
    tau_mi = rc.first_minimum(mi_filt)
    # FNN
    M = 10
    R = 0.025
    fnn_mi, dims_mi = rc.fnn(x, tau_mi, maxdim=M, r=R)
    m_mi = dims_mi[rc.first_zero(fnn_mi)]
예제 #6
0
    clrs = ["MediumTurquoise", "GoldenRod", "IndianRed"]

    # Lorenz butterfly
    # ----------------
    print("Roessler ...")
    Tx = np.linspace(0., 1000., 100000.)
    params = (0.432, 2., 4.)
    x0 = {
        1: (1., 3., 5.),
        2: (7.5, -4.5, 1.),
        3: (-2.5, -4.5, 0.),
    }
    X = {}
    for i in range(1, 4):
        print("\tinitial condition #%d" % i)
        X[i] = tm.roessler(x0[i], Tx, params)

    # Henon map
    # ---------
    print("Henon map ...")
    Ty = np.arange(0, 10000, 1)
    params = (1.4, 0.30)
    y0 = {
        1: (-1., 0.),
        2: (1., -0.1),
        3: (0.5, 0.1),
    }
    Y = {}
    for i in range(1, 4):
        print("\tinitial condition #%d" % i)
        Y[i] = tm.henon(y0[i], Ty[-1], params)