Home > Blockchain >  Sigma Notation with Numpy
Sigma Notation with Numpy

Time:02-15

I have a one dimensional time series (the x value from a Rossler System). I am looking to coarse grain this series with the following formula, which is in sigma notation:

Coarse grain formula

Here is the link: https://arxiv.org/ftp/physics/papers/0604/0604040.pdf I am definitely not getting the result that I am looking for, as when I look at the later parts of the output, the numbers aren't being summed correctly; here is my attempt:

import numpy as np
from itertools import accumulate

def rossler_system(a, b, c, t, tf, h):
    def derivative(r, t):
        x = r[0]
        y = r[1]
        z = r[2]
        return np.array([- y - z, x   a * y, b   z * (x - c)])

    time = np.array([])
    x = np.array([])
    y = np.array([])
    z = np.array([])
    r = np.array([0.1, 0.1, 0.1])

    while (t <= tf):
        time = np.append(time, t)
        z = np.append(z, r[2])
        y = np.append(y, r[1])
        x = np.append(x, r[0])

        k1 = h * derivative(r, t)
        k2 = h * derivative(r   k1 / 2, t   h / 2)
        k3 = h * derivative(r   k2 / 2, t   h / 2)
        k4 = h * derivative(r   k3, t   h)
        r  = (k1   2 * k2   2 * k3   k4) / 6

        t = t   h

    return x, y, z


a = 0.2
b = 0.2
c = 5.7
t = 0
tf = 100
h = 0.1 # 0.005

x1, y, z = rossler_system(a, b, c, t, tf, h)

data = []
scale_factor = np.arange(1, 21)  # scale factors from 1 to 20
j_length = np.array([int(np.round(len(x1) / scale, 0)) for scale in scale_factor])  # the different lengths of our time series

for scale in scale_factor:
    for length in j_length:
        for j in range(0, length):
            data.append((1/scale) * (np.sum(x1[(j - 1)*scale   1:j*scale 1])))

data = [data[end - length:end] for length, end in zip(j_length, accumulate(j_length))]  # splits list into the lengths of our j's

CodePudding user response:

for scale, length in zip(scale_factor, j_length):
    for j in range(1, length 1):
        data.append((1/scale) * np.sum(x1[(j - 1)*scale:(j*scale)]))

Works perfectly!

  • Related