关于「Jacobi 旋转:只用标准库做对称特征分解与奇异值分解」,《库普曼模态与直播拐点》给出的定量结论是什么?

结论:Jacobi 旋转每次把一个非对角元转成零,非对角能量只会流向对角线,循环扫描在后期二次收敛:程序 p31 在 8 乘 8 的 Gram 矩阵上六轮就从 9.217e-01 降到 1.022e-16,正交性误差 2.7e-15。求奇异值不能走「先乘转置再开方」的捷径:程序 p32 中,十亿分之一的奇异值在那条路上被算成负数,相对误差 8.6e+00,而单边 Jacobi 的误差是 2.6e-08,已经贴着输入舍入的极限。程序 p33 验证了 Eckart 与 Young 的定理:截断误差恰好等于尾部奇异值平方和的平方根。有了这套只用标准库的分解工具,下一章就可以正式搭建动态模态分解:求特征值与模态,并看清噪声怎样把一个永不衰减的起伏伪装成正在消失的信号。

数据口径:书中的直播曲线、店铺流水与参数均为示意;全部计算由书中程序生成;本书是非个人化经营建议,现金流预报不构成融资、借贷或投资建议,书中小工具给出的每一条预警都只是内部提示,须由经营者人工判断。 第一章显示示意直播曲线的前两个模态装下 0.9285 的能量,但随机游走也有 0.872,所以方差解释不是证据,样本外预报才是;去掉 12 分钟起伏的移动平均,拐点迟到 5.89 分钟。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: -01, -15, -16, 1.022, 2.7, 9.217

sweepoff-diagonal norm / norm of G
09.217e-01
14.695e-02
21.819e-03
35.628e-05
44.051e-07
53.454e-12
61.022e-16
eigenvalues / trace:
0.9094 0.0699 0.0139 0.0020
1.3e-03 1.3e-03 1.1e-03 1.0e-03
max |V^T V - I| = 2.7e-15max |V W V^T - G| / max|G| = 4.0e-15
查看完整验算程序
# Chapter 3. p31: cyclic Jacobi rotations on a symmetric Gram matrix.
# Model: the 8 x 8 Gram matrix G = H H^T of the de-meaned p11 curve
# embedded with 8 delay rows (illustrative data, fixed seed). Each sweep
# visits all 28 off-diagonal pairs once; we print the off-diagonal norm
# after every sweep (quadratic convergence), the eigenvalues, and two
# checks: orthogonality of V and the reconstruction G = V diag(w) V^T.


import math
import random


def slow(t):
    # 慢分量:进场与离场两个指数之差(示意参数,单位:人)
    return 800.0 + 5000.0 * (math.exp(-t / 60.0) - math.exp(-t / 20.0))


def cycle(t):
    # 每 12 分钟一轮上新或福袋带来的起伏(示意)
    return 150.0 * math.cos(2.0 * math.pi * t / 12.0)


def session(sd=40.0, n=120, shift=0):
    rng = random.Random(20261113 + shift)
    return [slow(t) + cycle(t) + rng.gauss(0.0, sd) for t in range(n)]


def jacobi_eig(a, max_sweeps=50, log=None):
    # 循环 Jacobi 旋转:对称矩阵 A = V diag(w) V^T,每次把一个非对角元转成 0
    n = len(a)
    a = [row[:] for row in a]
    v = [[1.0 if i == j else 0.0 for j in range(n)] for i in range(n)]
    for sweep in range(max_sweeps):
        off = math.sqrt(math.fsum(a[i][j] ** 2 for i in range(n)
                                  for j in range(n) if i != j))
        if log is not None:
            log.append(off)
        if off <= 1e-15 * math.sqrt(math.fsum(a[i][i] ** 2
                                              for i in range(n))):
            break
        for p in range(n - 1):
            for q in range(p + 1, n):
                if a[p][q] == 0.0:
                    continue
                th = (a[q][q] - a[p][p]) / (2.0 * a[p][q])
                t = math.copysign(1.0, th) / (
                    abs(th) + math.sqrt(th * th + 1.0))
                c = 1.0 / math.sqrt(t * t + 1.0)
                s = t * c
                for k in range(n):
                    akp, akq = a[k][p], a[k][q]
                    a[k][p] = c * akp - s * akq
                    a[k][q] = s * akp + c * akq
                for k in range(n):
                    apk, aqk = a[p][k], a[q][k]
                    a[p][k] = c * apk - s * aqk
                    a[q][k] = s * apk + c * aqk
                for k in range(n):
                    vkp, vkq = v[k][p], v[k][q]
                    v[k][p] = c * vkp - s * vkq
                    v[k][q] = s * vkp + c * vkq
    w = [a[i][i] for i in range(n)]
    order = sorted(range(n), key=lambda i: (-w[i], i))
    return [w[i] for i in order], [[v[k][i] for i in order]
                                   for k in range(n)]


def hankel(x, rows):
    # 延迟嵌入:第 i 行是从第 i 分钟起的一段序列
    k = len(x) - rows + 1
    return [[x[i + j] for j in range(k)] for i in range(rows)]


def dot(a, b):
    return math.fsum(x * y for x, y in zip(a, b))


def matmul(a, b):
    bt = list(zip(*b))
    return [[dot(r, c) for c in bt] for r in a]


def transpose(a):
    return [list(r) for r in zip(*a)]


x = session()
mean = math.fsum(x) / len(x)
h = hankel([q - mean for q in x], 8)
g = matmul(h, transpose(h))
log = []
w, v = jacobi_eig(g, log=log)
scale = math.sqrt(math.fsum(q * q for row in g for q in row))
print("sweep   off-diagonal norm / norm of G")
for k, off in enumerate(log):
    print("%5d   %.3e" % (k, off / scale))
print("eigenvalues / trace:")
tr = math.fsum(w)
print("  " + " ".join("%.4f" % (q / tr) for q in w[:4]))
print("  " + " ".join("%.1e" % (q / tr) for q in w[4:]))
vtv = matmul(transpose(v), v)
orth = max(abs(vtv[i][j] - (1.0 if i == j else 0.0))
           for i in range(8) for j in range(8))
rec = matmul(matmul(v, [[w[i] if i == j else 0.0 for j in range(8)]
                        for i in range(8)]), transpose(v))
err = max(abs(rec[i][j] - g[i][j]) for i in range(8) for j in range(8))
print("max |V^T V - I| = %.1e   max |V W V^T - G| / max|G| = %.1e"
      % (orth, err / max(abs(q) for row in g for q in row)))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《库普曼算子动态模态分解、现金流非线性波动线性化与直播在线曲线拐点预测母典》第 3 章「Jacobi 旋转:只用标准库做对称特征分解与奇异值分解」(版本 1.0.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-238 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026238,
  author    = {Fan, Yafu},
  title     = {Koopman Operators and Dynamic Mode Decomposition: Linearising Nonlinear Cash-Flow Swings and Forecasting Turning Points in Livestream Audience Curves},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论