Beispiel #1
0
def pr2b(file_prefix=None):
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, xxs = rungekutta.rk4(lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64), 0.0001, 1000000)
    xs = xxs.transpose()
    x0 = numpy.array([-30, -40, 4], dtype=numpy.float64)
    d_cap = find_loglog_slope(xs[100000:400000, :], x0, file_prefix=suffixed(file_prefix, "_2b"))
    print "Lorenz\tshort\td_cap = {0:.6f}".format(d_cap)
    return xs
Beispiel #2
0
def runit():
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, xxs = rungekutta.rk4(
                            lfunc, 
                            0.0, 
                            numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64),
                            0.0001,
                            100000
                        )
Beispiel #3
0
def pr2b(file_prefix=None):
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, xxs = rungekutta.rk4(
        lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64),
        0.0001, 1000000)
    xs = xxs.transpose()
    x0 = numpy.array([-30, -40, 4], dtype=numpy.float64)
    d_cap = find_loglog_slope(xs[100000:400000, :],
                              x0,
                              file_prefix=suffixed(file_prefix, '_2b'))
    print 'Lorenz\tshort\td_cap = {0:.6f}'.format(d_cap)
    return xs
Beispiel #4
0
def pr2a(file_prefix=None):
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, xxs = rungekutta.rk4(lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64), 0.0001, 300000)
    xs = xxs.transpose()[:, 0]
    data = numpy.array(zip(xs, ts), dtype=numpy.float64)
    ms = tispy.mutual("-D", 16000, input=data)
    tau = first_min(ms)
    ws = tispy.delay("-d", int(tau), "-m", 7, input=data)
    x0 = numpy.array([-35, -35], dtype=numpy.float64)
    zs = numpy.array(zip(ws[100000:, 0], ws[100000:, 5]), dtype=numpy.float64)
    d_cap = find_loglog_slope(zs, x0, file_prefix=suffixed(file_prefix, "_2a"))
    print "Lorenz\tembed\td_cap = {0:.6f}".format(d_cap)
Beispiel #5
0
    def __init__(self):
        super().__init__()

        self.steps_min = 10
        self.steps_max = 10000
        self.steps = 1000

        # self.dt = 0.001
        self.dt = 0.01
        self.dt_min = 0.0001
        self.dt_max = 0.1
        # self.dt_max = 1
        # self.dt = 1

        self.color = 1

        self.p = np.zeros((self.steps, 3), dtype=np.float64)
        self.p[0] = np.array([1, 0, 0])  # initial conditions

        self.s = 10
        self.r = 28
        self.b = 8 / 3

        self.s_min = 0.5
        self.s_max = 60
        self.r_min = 0.5
        self.r_max = 60
        self.b_min = 0.1
        self.b_max = 10
        # self.b_max = 1

        # self.lastPosition = np.array([0,0,-10])

        self.init_ui()
        self.qt_connections()

        lorenz.lorenz(self.p, self.s, self.r, self.b, self.steps, self.dt)
        lorenz.lorenz(self.p, self.s_slider.value(), self.r_slider.value(),
                      self.b_slider.value(), self.steps, self.dt)
Beispiel #6
0
def pr2a(file_prefix=None):
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, xxs = rungekutta.rk4(
        lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64),
        0.0001, 300000)
    xs = xxs.transpose()[:, 0]
    data = numpy.array(zip(xs, ts), dtype=numpy.float64)
    ms = tispy.mutual('-D', 16000, input=data)
    tau = first_min(ms)
    ws = tispy.delay('-d', int(tau), '-m', 7, input=data)
    x0 = numpy.array([-35, -35], dtype=numpy.float64)
    zs = numpy.array(zip(ws[100000:, 0], ws[100000:, 5]), dtype=numpy.float64)
    d_cap = find_loglog_slope(zs, x0, file_prefix=suffixed(file_prefix, '_2a'))
    print 'Lorenz\tembed\td_cap = {0:.6f}'.format(d_cap)
Beispiel #7
0
    def params_changed(self):
        # print(self.p.min(), self.p.max())

        self.s = util.fit(self.s_slider.value(), 0, self.sliders_positions,
                          self.s_min, self.s_max)
        self.r = util.fit(self.r_slider.value(), 0, self.sliders_positions,
                          self.r_min, self.r_max)
        self.b = util.fit(self.b_slider.value(), 0, self.sliders_positions,
                          self.b_min, self.b_max)
        print(self.dt_slider.value(), '$$$$$$')
        self.dt = util.fit(self.dt_slider.value(), 0, self.sliders_positions,
                           self.dt_min, self.dt_max)

        lorenz.lorenz(self.p, self.s, self.r, self.b, self.steps, self.dt)

        # self.main_scatter_plot.setData(pos=self.p, size=np.ones(self.p.shape[0])*0.3, color=self.color, pxMode=False)
        self.main_scatter_plot.setData(pos=self.p,
                                       size=0.3,
                                       color=self.color,
                                       pxMode=False)

        self.xcurve.setData(self.p[:, 0], connect='finite')
        self.ycurve.setData(self.p[:, 1], connect='finite')
        self.zcurve.setData(self.p[:, 2], connect='finite')

        # print(self.steps, self.dt, f'min = {np.min(self.p)} max = {np.max(self.p)}')
        # self.xplot.setYRange(np.min(self.p[:, 0]), np.max(self.p[:, 0]))
        # self.yplot.setYRange(np.min(self.p[:, 1]), np.max(self.p[:, 0]))
        # self.zplot.setYRange(np.min(self.p[:, 2]), np.max(self.p[:, 1]))

        print(self.dt, '<<<<')
        # print(self.steps)
        self.steps_label.setText(f'steps {self.steps}')
        self.dt_label.setText(f'dt {self.dt}')
        self.s_label.setText(f'σ {self.s}')
        self.r_label.setText(f'ρ {self.r}')
        self.b_label.setText(f'β {self.b}')
Beispiel #8
0
def extrema():
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, xxs = rungekutta.rk4(lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64), 0.0001, 300000)
    xs = xxs.transpose()[:, 0]
    data = numpy.array(zip(xs, ts), dtype=numpy.float64)
    ms = tispy.mutual("-D", 16000, input=data)
    tau = first_min(ms)
    print "Tau: {0:.6f}".format(tau)
    ws = tispy.delay("-d", int(tau), "-m", 7, input=data)
    zs = ws[100000:, :]
    mins = numpy.empty(7, dtype=numpy.float64)
    maxs = numpy.empty(7, dtype=numpy.float64)
    for i in xrange(7):
        mins[i] = min(zs[:, i])
        maxs[i] = max(zs[:, i])
    print "Mins: {0}".format(mins)
    print "Maxs: {0}".format(maxs)
 def __init__(self):
     super().__init__()
     surface_format = QtGui.QSurfaceFormat()
     surface_format.setMajorVersion(3)
     surface_format.setMajorVersion(2)
     surface_format.setProfile(QtGui.QSurfaceFormat.CoreProfile)
     surface_format.setOption(QtGui.QSurfaceFormat.DebugContext)
     self.setFormat(surface_format)
     self.update_timer = QtCore.QTimer()
     self.update_timer.timeout.connect(self.update_tick)
     self.update_timer.start(1000//60)
     self.tick = 0
     self.t1 = self.t2 = 0
     self.q = 0
     y = lorenz.lorenz(num_steps=2000000)
     self.data = y.astype('float32')
     self.newdata = False
Beispiel #10
0
def extrema():
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, xxs = rungekutta.rk4(
        lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64),
        0.0001, 300000)
    xs = xxs.transpose()[:, 0]
    data = numpy.array(zip(xs, ts), dtype=numpy.float64)
    ms = tispy.mutual('-D', 16000, input=data)
    tau = first_min(ms)
    print 'Tau: {0:.6f}'.format(tau)
    ws = tispy.delay('-d', int(tau), '-m', 7, input=data)
    zs = ws[100000:, :]
    mins = numpy.empty(7, dtype=numpy.float64)
    maxs = numpy.empty(7, dtype=numpy.float64)
    for i in xrange(7):
        mins[i] = min(zs[:, i])
        maxs[i] = max(zs[:, i])
    print 'Mins: {0}'.format(mins)
    print 'Maxs: {0}'.format(maxs)
Beispiel #11
0
def pr6(file_prefix=None):
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, vs = rungekutta.rk4(lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64), 0.001, 30000)
    xs = vs.transpose()[:, 0]
    data = numpy.array(zip(xs, ts), dtype=numpy.float64)
    ms = tispy.mutual("-D", 1600, input=data)
    tau = first_min(ms)
    ws = tispy.delay("-d", int(tau), "-m", 7, input=data)
    col1 = 0
    col2 = 5
    plot.render(
        ws[:, col1],
        ws[:, col2],
        "k.",
        markersize=0.6,
        title=r"Delay Coordinate Embedding: {0}, $\tau={1}$ s".format(r"lorenz", 0.001 * tau),
        xlabel=r"$x(t+{0:.3f})$".format(col1 * 0.001 * tau),
        ylabel=r"$x(t+{0:.3f})$".format(col2 * 0.001 * tau),
        file_prefix=suffixed(file_prefix, "_6"),
    )
    return tau
Beispiel #12
0
def pr6(file_prefix=None):
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, vs = rungekutta.rk4(
        lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64),
        0.001, 30000)
    xs = vs.transpose()[:, 0]
    data = numpy.array(zip(xs, ts), dtype=numpy.float64)
    ms = tispy.mutual('-D', 1600, input=data)
    tau = first_min(ms)
    ws = tispy.delay('-d', int(tau), '-m', 7, input=data)
    col1 = 0
    col2 = 5
    plot.render(ws[:, col1],
                ws[:, col2],
                'k.',
                markersize=0.6,
                title=r'Delay Coordinate Embedding: {0}, $\tau={1}$ s'.format(
                    r'lorenz', 0.001 * tau),
                xlabel=r'$x(t+{0:.3f})$'.format(col1 * 0.001 * tau),
                ylabel=r'$x(t+{0:.3f})$'.format(col2 * 0.001 * tau),
                file_prefix=suffixed(file_prefix, '_6'))
    return tau
def lorenz(reservoir_size, spectral_radius, train_len, future):

    # Load in mackey-glass numpy array
    data_full = lz.lorenz()
    data = data_full[0]

    #Initialize ESN
    esn = ESN(n_inputs=1,
              n_outputs=1,
              n_reservoir=reservoir_size,
              spectral_radius=spectral_radius,
              random_state=42)

    # Fit the model
    pred_training = esn.fit(np.ones(train_len), data[:train_len])

    # Predict and find the error
    prediction = esn.predict(np.ones(future))
    error = np.sqrt(
        np.mean(
            (prediction.flatten() - data[train_len:train_len + future])**2))

    return error, prediction, reservoir_size, spectral_radius, train_len, future
Beispiel #14
0
def pr6x1(tau, file_prefix=None):
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, vs = rungekutta.rk4(
        lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64),
        0.001, 30000)
    xs = vs.transpose()[:, 0]
    data = numpy.array(zip(xs, ts), dtype=numpy.float64)
    ms = tispy.lyap_k('-d', int(tau), '-m', 7, '-M', 7, input=data)
    pargs = cut(ms[:, 0], ms[:, 1])

    total = 0.0
    count = len(pargs) / 2
    for i in xrange(0, len(pargs), 2):
        xs = 0.31 * pargs[i][:50]
        ys = pargs[i + 1][:50]
        ps = numpy.polyfit(xs, ys, 1)
        total += ps[0]
    print 'Lorenz lyapunov exponent: {0}'.format(total / count)

    plot.render(*pargs,
                xlabel='Iterations',
                ylabel='Logarithm of the Stretching Factor',
                title='Calculating the Lyapunov Exponent',
                file_prefix=suffixed(file_prefix, '_7'))
Beispiel #15
0
def pr6x1(tau, file_prefix=None):
    lfunc = lorenz.lorenz(16, 45, 4)
    ts, vs = rungekutta.rk4(lfunc, 0.0, numpy.array([-13.0, -12.0, 52.0], dtype=numpy.float64), 0.001, 30000)
    xs = vs.transpose()[:, 0]
    data = numpy.array(zip(xs, ts), dtype=numpy.float64)
    ms = tispy.lyap_k("-d", int(tau), "-m", 7, "-M", 7, input=data)
    pargs = cut(ms[:, 0], ms[:, 1])

    total = 0.0
    count = len(pargs) / 2
    for i in xrange(0, len(pargs), 2):
        xs = 0.31 * pargs[i][:50]
        ys = pargs[i + 1][:50]
        ps = numpy.polyfit(xs, ys, 1)
        total += ps[0]
    print "Lorenz lyapunov exponent: {0}".format(total / count)

    plot.render(
        *pargs,
        xlabel="Iterations",
        ylabel="Logarithm of the Stretching Factor",
        title="Calculating the Lyapunov Exponent",
        file_prefix=suffixed(file_prefix, "_7")
    )
Beispiel #16
0
# -------------------------------------------------------------------------
#
# PYTHON for DUMMIES 18-19
# Problème 7
#
# Script de test
#  Vincent Legat
#
# -------------------------------------------------------------------------
#

from numpy import *
from matplotlib import pyplot as plt
from lorenz import lorenz

plt.figure("Lorenz Equations")
Xstart = 0
Xend = 100
Ustart = [0, 1, 0]
n = 10000

X, U = lorenz(Xstart, Xend, Ustart, n)
plt.plot(U[:, 0], U[:, 2], '-r', linewidth=0.5)
plt.show()