关于「趋势与台阶:慢漂移要几周才看得出,真突变要付几天迟钝」,《可穿戴读数与广告日报的卡尔曼滤波》给出的定量结论是什么?
结论:加一个斜率状态,局部水平模型就变成局部趋势模型。在示意参数下,单次读数误差是每日漂移的十二倍,用两次读数比较趋势几乎没有信息;滤波要连续记录约八周,才有 0.882 的机会看出趋势。对于真实的台阶,滤波确实需要几天,但在误报相同的条件下,它不比按原始读数报警更慢。前三章都在实时地看今天;如果我们愿意回头看,用今天的读数去修正对上周的判断,又能把误差压低多少?缺测的日子和明显荒唐的读数又该怎样处理?下一章回答。
数据口径:本书用局部水平与局部趋势的状态空间模型检验这一常识:一个读数等于真实水平加测量误差,当误差方差远大于真实日变化方差时,按原始读数做是或否的决定会对噪音过度反应;示意参数下原始读数每百天翻转 23.6 次,卡尔曼滤波估计只翻转 5.5 次。 书中的噪音方差、漂移、回报率与预算均为示意参数;全部计算由书中程序生成。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 0.882
| true drift 0.05 per day, reading sd 0.6 | |||
| naive week-over-week slope sd: 0.1212 | |||
| days | filter sd | OLS sd | share |slope| > 2 sd |
| 7 | 0.1201 | 0.1134 | 0.060 |
| 14 | 0.0494 | 0.0398 | 0.182 |
| 21 | 0.0323 | 0.0216 | 0.340 |
| 28 | 0.0251 | 0.0140 | 0.510 |
| 42 | 0.0187 | 0.0076 | 0.725 |
| 56 | 0.0157 | 0.0050 | 0.882 |
核心公式
\[\ell_{t+1}=\ell_t+b_t+u_t,\qquad b_{t+1}=b_t+w_t,\qquad y_t=\ell_t+\varepsilon_t.\]
查看完整验算程序
# Chapter 3. p31: A slow drift needs weeks, not two readings, to show.
# Local linear trend: level l[t+1] = l[t] + b[t] + u, slope
# b[t+1] = b[t] + w, reading y = l + e. Illustrative scale-like units:
# true drift 0.05 per day, level noise sd 0.1, slope noise sd 0.001,
# reading error sd 0.6. Columns: posterior sd of the slope from the
# filter (exact Riccati recursion), the least-squares slope sd for a
# straight line with no level noise, the sd of the naive "this week's
# reading minus last week's / 7", and the share of 400 runs where the
# filter's slope is more than two sd away from zero. Fixed seed.
import math
import random
B0, QL, QB, R = 0.05, 0.1 ** 2, 0.001 ** 2, 0.6 ** 2
rng = random.Random(20261116)
CHECK = (7, 14, 21, 28, 42, 56)
def filt(ys):
a0, a1 = ys[0], 0.0
p00, p01, p11 = R, 0.0, 1.0
rows = []
for t, y in enumerate(ys[1:], 2):
a0 = a0 + a1
p00, p01, p11 = (p00 + 2 * p01 + p11 + QL, p01 + p11, p11 + QB)
s = p00 + R
k0, k1 = p00 / s, p01 / s
v = y - a0
a0, a1 = a0 + k0 * v, a1 + k1 * v
p00, p01, p11 = (p00 - k0 * p00, p01 - k0 * p01, p11 - k1 * p01)
rows.append((t, a1, math.sqrt(p11)))
return rows
hits = {n: 0 for n in CHECK}
sds = {}
for _ in range(400):
lvl, b, ys = 0.0, B0, []
for _ in range(max(CHECK)):
ys.append(lvl + rng.gauss(0, math.sqrt(R)))
lvl += b + rng.gauss(0, math.sqrt(QL))
b += rng.gauss(0, math.sqrt(QB))
for t, slope, sd in filt(ys):
if t in hits:
sds[t] = sd
if abs(slope) > 2 * sd:
hits[t] += 1
naive = math.sqrt(2 * R) / 7
print("true drift %.2f per day, reading sd %.1f" % (B0, math.sqrt(R)))
print("naive week-over-week slope sd: %.4f" % naive)
print("days filter sd OLS sd share |slope| > 2 sd")
for n in CHECK:
ols = math.sqrt(R * 12 / (n * (n * n - 1)))
print("%4d %.4f %.4f %.3f" % (n, sds[n], ols, hits[n] / 400))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《卡尔曼滤波状态空间同化、可穿戴读数观测噪音与广告归因真实信号提纯母典》第 3 章「趋势与台阶:慢漂移要几周才看得出,真突变要付几天迟钝」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-245 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026245,
author = {Fan, Yafu},
title = {Kalman Filtering and State-Space Assimilation: Separating Observation Noise from True Signals in Wearable Readings and Advertising Reports},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}