What does Koopman Modes for Audience Turning Points conclude, in numbers, about “Two or Three Modes: the Low-Rank Structure of a Livestream Audience Curve and the Built-In Lag of Moving Averages”?
Answer: Chapter 1 shows that the first two modes of an illustrative audience curve hold 0.9285 of its energy, but a random walk also reaches 0.872, so explained variance is not evidence and out-of-sample forecasting is; a moving average that removes a 12-minute swing turns 5.89 minutes late.
Scope of the numbers: Marked boxes separate published evidence, runnable Python calculations (19 programs), classical sources and the author's hypotheses.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 0.9285, 12
| Hankel 24 x 97 of the de-meaned curve, share of energy | |
| k | 1 0.7656 k=2 0.9285 k=3 0.9628 |
| k | 4 0.9889 k=5 0.9916 k=6 0.9923 |
| DMD rank 5 on minutes 0-59 (true | 1, tau 60, tau 20, period 12) |
| noise-free |lambda| angle tau(min) period(min) | |
| 1.00000 | -0.5236 inf 12.0 |
| 1.00000 | 0.0000 inf inf |
| 1.00000 | 0.5236 inf 12.0 |
| 0.98347 | 0.0000 60.0 inf |
| 0.95123 | 0.0000 20.0 inf |
| noisy |lambda| angle tau(min) period(min) | |
| 0.99862 | -0.5214 723.5 12.1 |
| 0.99862 | 0.5214 723.5 12.1 |
| 0.98552 | 0.0000 68.6 inf |
| 0.97277 | 3.1416 36.2 2.0 |
| 0.95794 | 0.0000 23.3 inf |
| true turning point of the slow part: minute 32.96, level 2724.5 |
Show the full program
# Chapter 1. p11: a noisy livestream curve, its Hankel energy and modes.
# Model: an illustrative 120-minute audience curve = constant 800 + an
# arrival-minus-departure hump 5000 * (exp(-t/60) - exp(-t/20)) + a
# 12-minute cycle of amplitude 150 + Gaussian noise (sd 40), one sample
# per minute, fixed seed. All parameters are illustrative, not data
# from any platform. Hankel delay embedding, SVD by one-sided Jacobi
# rotations, exact DMD with rank 5 on the first 60 minutes.
import math
import cmath
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 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)]
def svd(a):
# 单边 Jacobi(Hestenes):两两旋转列直到正交,A = U S V^T
m, n = len(a), len(a[0])
if n > m:
u, s, v = svd(transpose(a))
return v, s, u
cols = [[a[i][j] for i in range(m)] for j in range(n)]
vc = [[1.0 if i == j else 0.0 for i in range(n)] for j in range(n)]
for sweep in range(60):
rotated = False
for p in range(n - 1):
for q in range(p + 1, n):
al = dot(cols[p], cols[p])
be = dot(cols[q], cols[q])
ga = dot(cols[p], cols[q])
if ga == 0.0 or abs(ga) <= 1e-15 * math.sqrt(al * be):
continue
rotated = True
ze = (be - al) / (2.0 * ga)
t = math.copysign(1.0, ze) / (
abs(ze) + math.sqrt(1.0 + ze * ze))
c = 1.0 / math.sqrt(1.0 + t * t)
s = c * t
cp, cq = cols[p], cols[q]
cols[p] = [c * x - s * y for x, y in zip(cp, cq)]
cols[q] = [s * x + c * y for x, y in zip(cp, cq)]
vp, vq = vc[p], vc[q]
vc[p] = [c * x - s * y for x, y in zip(vp, vq)]
vc[q] = [s * x + c * y for x, y in zip(vp, vq)]
if not rotated:
break
sig = [math.sqrt(dot(c_, c_)) for c_ in cols]
order = sorted(range(n), key=lambda j: (-sig[j], j))
s = [sig[j] for j in order]
u = [[cols[j][i] / sig[j] if sig[j] > 0.0 else 0.0 for j in order]
for i in range(m)]
v = [[vc[j][i] for j in order] for i in range(n)]
return u, s, v
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 dmd(x, rows, r):
# Hankel 上的精确 DMD:X、Y 为错开一列的两块,A~ = U^T Y V S^-1
h = hankel(x, rows)
xs = [row[:-1] for row in h]
ys = [row[1:] for row in h]
u, s, v = svd(xs)
ur = [row[:r] for row in u]
vr = [row[:r] for row in v]
at = matmul(matmul(transpose(ur), ys), vr)
at = [[at[i][j] / s[j] for j in range(r)] for i in range(r)]
return ur, at, s, h
def charpoly(a):
# Faddeev-LeVerrier:特征多项式 z^n + c1 z^(n-1) + c2 z^(n-2) 直到 cn
n = len(a)
m = [[0.0] * n for _ in range(n)]
coef = [1.0]
for k in range(1, n + 1):
m = matmul(a, m)
for i in range(n):
m[i][i] += coef[-1]
am = matmul(a, m)
coef.append(-math.fsum(am[i][i] for i in range(n)) / k)
return coef
def roots(coef):
# Durand-Kerner 同时迭代求全部复根(cmath)
n = len(coef) - 1
z = [cmath.rect(0.9, 0.4 + 2.0 * math.pi * k / n) for k in range(n)]
def p(x):
r = complex(1.0, 0.0)
for c in coef[1:]:
r = r * x + c
return r
for _ in range(800):
new = []
for i in range(n):
den = complex(1.0, 0.0)
for j in range(n):
if j != i:
den *= z[i] - z[j]
new.append(z[i] - p(z[i]) / den)
moved = max(abs(a - b) for a, b in zip(new, z))
z = new
if moved < 1e-14:
break
return z
def eigvals(a):
z = roots(charpoly(a))
z = [complex(w.real, 0.0) if abs(w.imag) < 1e-12 else w for w in z]
return sorted(z, key=lambda w: (-round(abs(w), 9), w.imag))
x = session()
n = len(x)
mean = math.fsum(x) / n
u, s, v = svd(hankel([q - mean for q in x], 24))
energy = [q * q for q in s]
total = math.fsum(energy)
print("Hankel 24 x 97 of the de-meaned curve, share of energy")
row = []
for k in range(1, 7):
row.append("k=%d %.4f" % (k, math.fsum(energy[:k]) / total))
print(" " + " ".join(row[:3]))
print(" " + " ".join(row[3:]))
print("DMD rank 5 on minutes 0-59 (true: 1, tau 60, tau 20, period 12)")
for label, data in (("noise-free", session(sd=0.0)), ("noisy", x)):
ur, at, s60, h = dmd(data[:60], 20, 5)
print(" %-10s |lambda| angle tau(min) period(min)" % label)
for lam in eigvals(at):
mod, ang = abs(lam), cmath.phase(lam)
tau = -1.0 / math.log(mod) if mod < 0.999999 else float("inf")
per = 2.0 * math.pi / abs(ang) if abs(ang) > 1e-9 else float("inf")
print(" %10s %.5f %7.4f %8.1f %11.1f"
% ("", mod, ang, tau, per))
tstar = 30.0 * math.log(3.0)
print("true turning point of the slow part: minute %.2f, level %.1f"
% (tstar, slow(tstar)))Single source and citation
Fan, Y. (2026). Koopman Operators and Dynamic Mode Decomposition: Linearising Nonlinear Cash-Flow Swings and Forecasting Turning Points in Livestream Audience Curves (Version 1.0.0), Chapter 1: Two or Three Modes: the Low-Rank Structure of a Livestream Audience Curve and the Built-In Lag of Moving Averages. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 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}
}Other chapter answers in this book
- Chapter 2 · The Koopman Operator: Lifting Nonlinear Dynamics into Linear Ones, and the Limits of the Lift
- Chapter 3 · Jacobi Rotations: Symmetric Eigendecomposition and the Singular Value Decomposition with the Standard Library Alone
- Chapter 4 · Dynamic Mode Decomposition: Eigenvalues, Amplitudes and the False Decay Caused by Noise
- Chapter 5 · Lead Time at the Turning Point: a Mode-Based Warning Every Five Minutes against Moving Averages
- Chapter 6 · Cash Flow: Linearising Daily, Weekly and Monthly Swings with Modes, and Choosing the Observable
- Chapter 7 · East and West in the Sources: "Knowing the Incipient" in the Book of Changes and Fourier's Analysis of Heat
- Chapter 8 · Closing the Empirical Loop: a Mode Fit Every Five Minutes, a Cooling Warning and a Pre-Registered Test