Numpy 的西格玛符号

Sigma Notation with Numpy

我有一个一维时间序列(来自罗斯勒系统的 x 值)。我希望使用以下公式对这个系列进行粗粒度处理,该公式采用 sigma 表示法:

这是link:https://arxiv.org/ftp/physics/papers/0604/0604040.pdf 我肯定没有得到我想要的结果,因为当我查看输出的后面部分时,数字没有被正确求和;这是我的尝试:

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
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)]))

完美运行!