关于「收费站的每日累积和:P99 延迟、转化暗降与证伪方案」,《累积和告警》给出的定量结论是什么?
结论:第八章给出收费站 P99 延迟与转化率的每日累积和流程,转化率下降一成时累积和平均 13.7 天告警,固定计数规则需 52.8 天;并给出蒸馏小工具「累积和告警器」与预注册检验方案。书中以标注框区分已发表的证据、可运行的 Python 计算(23 段程序)、原典与作者的假说。
数据口径:书中参数为示意;全部计算由书中程序生成;本书属于非个人化经营建议,第八章只做离线模型,不访问任何服务器。 书中以标注框区分已发表的证据、可运行的 Python 计算(23 段程序)、原典与作者的假说。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 13.7, 52.8
| expected conversions per day | 60 |
| fixed rule: alarm when y < | 39, ARL0 = 443.1 days |
| CUSUM: h | 4.428, chain ARL0 = 442.8 days |
| CUSUM ARL0 by simulation (10000 runs) | 430.5 +/- 8.3 |
| drop p fixed ARL1 CUSUM ARL1 sim | |
| 0.10 | 0.0270 52.8 13.7 13.5 |
| 0.15 | 0.0255 21.2 6.6 6.6 |
| 0.20 | 0.0240 9.6 4.3 4.3 |
| 0.30 | 0.0210 2.8 2.6 2.6 |
查看完整验算程序
# Chapter 8. p82: a Bernoulli log-likelihood CUSUM for a silent drop in
# conversion, checked once a day.
# Model: each day n = 2000 visitors convert independently with p0 = 0.030
# in control. The chart is tuned to a 15 per cent drop (p1 = 0.0255): a
# day with y conversions adds y log(p1/p0) + (n - y) log((1-p1)/(1-p0))
# to S = max(0, S + llr), the per-visitor Bernoulli CUSUM summed over a
# day. The fixed rule alarms when y <= c, with c the largest count that
# keeps ARL0 >= 365 days; h is then solved so the CUSUM has the same
# ARL0. ARL comes from a Markov chain on [0, h] (m = 100 cells, binomial
# moves rounded to the nearest cell) and is checked by a fixed-seed
# simulation; rounding discrete moves to cells costs a few per cent in
# ARL0. Traffic and rates are illustrative.
import bisect
import math
import random
N, P0, P1 = 2000, 0.030, 0.0255
YMAX = 200
def solve(a, b):
# Gaussian elimination with partial pivoting; back substitution
# adds its terms with math.fsum
n = len(b)
m = [list(row) + [b[i]] for i, row in enumerate(a)]
for p in range(n):
q = max(range(p, n), key=lambda r: abs(m[r][p]))
m[p], m[q] = m[q], m[p]
piv = m[p]
for r in range(p + 1, n):
f = m[r][p] / piv[p]
if f != 0.0:
m[r] = m[r][:p] + [x - f * y for x, y in
zip(m[r][p:], piv[p:])]
x = [0.0] * n
for i in range(n - 1, -1, -1):
s = math.fsum(m[i][j] * x[j] for j in range(i + 1, n))
x[i] = (m[i][n] - s) / m[i][i]
return x
def pmf(p):
out = []
for y in range(YMAX + 1):
lg = (math.lgamma(N + 1) - math.lgamma(y + 1)
- math.lgamma(N - y + 1) + y * math.log(p)
+ (N - y) * math.log(1.0 - p))
out.append(math.exp(lg))
return out
def llr(y):
return (y * math.log(P1 / P0)
+ (N - y) * math.log((1.0 - P1) / (1.0 - P0)))
def arl(h, f, m=100):
w = 2.0 * h / (2 * m - 1)
a = [[0.0] * m for _ in range(m)]
for i in range(m):
for y, q in enumerate(f):
s = i * w + llr(y)
if s > h:
continue
j = 0 if s <= w / 2.0 else min(m - 1, int(s / w + 0.5))
a[i][j] = a[i][j] - q
a[i][i] = a[i][i] + 1.0
return solve(a, [1.0] * m)[0]
def simulate(rng, h, cum, runs):
# returns the mean run length and its standard error
out = []
for _ in range(runs):
s, t = 0.0, 0
while True:
t = t + 1
y = bisect.bisect_left(cum, rng.random())
s = max(0.0, s + llr(y))
if s > h:
out.append(t)
break
mean = math.fsum(out) / runs
var = math.fsum((x - mean) ** 2 for x in out) / (runs - 1)
return mean, math.sqrt(var / runs)
if __name__ == "__main__":
f0 = pmf(P0)
c = 0
while 1.0 / math.fsum(f0[:c + 2]) >= 365.0:
c = c + 1
a0 = 1.0 / math.fsum(f0[:c + 1])
lo, hi = 0.5, 20.0
for _ in range(30):
mid = 0.5 * (lo + hi)
if arl(mid, f0) < a0:
lo = mid
else:
hi = mid
h = 0.5 * (lo + hi)
print("expected conversions per day: {:.0f}".format(N * P0))
print("fixed rule: alarm when y <= {}, ARL0 = {:.1f} days".format(c, a0))
print("CUSUM: h = {:.3f}, chain ARL0 = {:.1f} days".format(
h, arl(h, f0)))
rng = random.Random(20261113)
cum0 = [math.fsum(f0[:j + 1]) for j in range(len(f0))]
mean, se = simulate(rng, h, cum0, 10000)
print("CUSUM ARL0 by simulation (10000 runs): {:.1f} +/- {:.1f}".format(
mean, 1.96 * se))
print(" drop p fixed ARL1 CUSUM ARL1 sim")
for drop in (0.10, 0.15, 0.20, 0.30):
p = P0 * (1.0 - drop)
f = pmf(p)
fx = 1.0 / math.fsum(f[:c + 1])
cum = [math.fsum(f[:j + 1]) for j in range(len(f))]
print(" {:4.2f} {:.4f} {:10.1f} {:11.1f} {:6.1f}".format(
drop, p, fx, arl(h, f), simulate(rng, h, cum, 4000)[0]))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《累积和控制图与平均运行长度、延迟漂移与转化暗降的最快无误报告警母典》第 8 章「收费站的每日累积和:P99 延迟、转化暗降与证伪方案」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-305 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026305,
author = {Fan, Yafu},
title = {CUSUM Control Charts and Average Run Length: the Fastest Alarm within a False-Alarm Budget for Latency Drift and Silent Conversion Drops},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}