关于「看几条就够:似然比、序贯检验与变点报警」,《公域反垃圾检测与合规桥接页》给出的定量结论是什么?
结论:第二章用似然比与瓦尔德序贯检验计算样本量,泊松定时器也只需 15 个间隔。
数据口径:书中参数为示意;全部计算由书中程序生成;本书是非个人化的经营分析,不构成经营、法律或理财建议,法规与平台规则以上架前人工复核为准。 书中以标注框区分已发表的证据、可运行的 Python 计算(20 段程序)、原典与作者的假说。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 15
| shape k D(f1||f0) mu0 s0 s1 n gaps alpha power | |
| 100 | 2.765 -200.359 189.674 0.700 5 0.000 1.000 |
| 9 | 1.614 -16.039 16.731 0.621 6 0.003 1.000 |
| 2 | 0.982 -2.552 3.465 0.697 8 0.004 0.978 |
| 1 | 0.612 -0.899 1.621 0.833 15 0.004 0.989 |
| k 100: fixed timer; k 9: loose timer; k 1: Poisson timer | |
| target alpha 0.01 and power 0.99; accounts per check | 2,000 |
查看完整验算程序
# Chapter 2. p21: Neyman-Pearson likelihood ratio and fixed sample size.
# Model: the detector compares two densities for one inter-post gap t
# (hours): human-like f0 = 0.6 Exp(mean 0.25) + 0.4 LogNormal(ln 8, 1.0)
# and a scheduler f1 = Gamma(shape k, mean 6). Per gap the log
# likelihood ratio L = ln f1(t) - ln f0(t) has mean mu1 and sd s1 when
# the account is a scheduler and mu0, s0 when it is human; mu1 is the
# Kullback-Leibler divergence D(f1||f0). With alpha = beta = 0.01 the
# normal approximation gives n = ((z s0 + z s1) / (mu1 - mu0))^2 gaps.
# Integrals by Simpson's rule on u = ln t. A seeded check draws 2,000
# accounts of each kind at that n. Parameters are illustrative.
import math
import random
import statistics
Z = statistics.NormalDist().inv_cdf(0.99)
def log_f0(t):
a = math.log(0.6) + math.log(4.0) - 4.0 * t
z = (math.log(t) - math.log(8.0)) / 1.0
b = math.log(0.4) - math.log(t * math.sqrt(2 * math.pi)) - z * z / 2
m = max(a, b)
return m + math.log(math.exp(a - m) + math.exp(b - m))
def log_f1(t, k):
th = 6.0 / k
return ((k - 1) * math.log(t) - t / th - math.lgamma(k)
- k * math.log(th))
def moments(k, under):
lo, hi, m = math.log(1e-4), math.log(400.0), 4000
h = (hi - lo) / m
w0, w1, w2 = [], [], []
for i in range(m + 1):
u = lo + i * h
t = math.exp(u)
lf = log_f1(t, k) if under == 1 else log_f0(t)
dens = math.exp(lf) * t
c = 1 if i in (0, m) else (4 if i % 2 else 2)
llr = log_f1(t, k) - log_f0(t)
w0.append(c * dens)
w1.append(c * dens * llr)
w2.append(c * dens * llr * llr)
tot = math.fsum(w0)
mu = math.fsum(w1) / tot
return mu, math.sqrt(math.fsum(w2) / tot - mu * mu)
def human_gap(rng):
if rng.random() < 0.6:
return rng.expovariate(4.0)
return rng.lognormvariate(math.log(8.0), 1.0)
def check(rng, k, n, c, reps=2000):
fp = tp = 0
for _ in range(reps):
s = math.fsum(log_f1(g, k) - log_f0(g)
for g in (human_gap(rng) for _ in range(n)))
fp += s > c
s = math.fsum(log_f1(g, k) - log_f0(g)
for g in (rng.gammavariate(k, 6.0 / k)
for _ in range(n)))
tp += s > c
return fp / reps, tp / reps
if __name__ == "__main__":
rng = random.Random(20261122)
print("shape k D(f1||f0) mu0 s0 s1 n gaps alpha power")
for k in (100.0, 9.0, 2.0, 1.0):
mu1, s1 = moments(k, 1)
mu0, s0 = moments(k, 0)
n = math.ceil(((Z * s0 + Z * s1) / (mu1 - mu0)) ** 2)
c = n * mu0 + Z * s0 * math.sqrt(n)
a, p = check(rng, k, n, c)
print("{:>7.0f} {:>10.3f} {:>7.3f} {:>6.3f} {:>6.3f} {:>8} "
"{:>6.3f} {:>6.3f}".format(k, mu1, mu0, s0, s1, n, a, p))
print("k 100: fixed timer; k 9: loose timer; k 1: Poisson timer")
print("target alpha 0.01 and power 0.99; accounts per check: {:,}"
.format(2000))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《公域社交图谱反垃圾检测边界、合规联盟桥接页转化与限流自愈动力学母典》第 2 章「看几条就够:似然比、序贯检验与变点报警」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-342 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026342,
author = {Fan, Yafu},
title = {Social-Graph Anti-Spam Detection Bounds, Compliant Affiliate Bridge-Page Funnels and the Kinetics of Recovery after Reach Throttling},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}