关于「回看与补洞:RTS 平滑、缺测日与伪读数」,《可穿戴读数与广告日报的卡尔曼滤波》给出的定量结论是什么?
结论:回看平滑在复盘时把中间日子的误差从 0.940 降到 0.705,但对最后一天毫无帮助。缺测日不需要插补,滤波器会让不确定性如实增大,读数恢复后自动加快追赶。伪读数应当用新息门限在进入估计之前拦下并交人复核。到这里,本书一直假设我们知道两种噪音的方差 \(q\) 与 \(r\)。现实中没有人告诉我们这两个数。只凭读数本身,能把它们估出来吗?四周的数据够不够?下一章回答。
数据口径:本书用局部水平与局部趋势的状态空间模型检验这一常识:一个读数等于真实水平加测量误差,当误差方差远大于真实日变化方差时,按原始读数做是或否的决定会对噪音过度反应;示意参数下原始读数每百天翻转 23.6 次,卡尔曼滤波估计只翻转 5.5 次。 书中的噪音方差、漂移、回报率与预算均为示意参数;全部计算由书中程序生成。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 0.705, 0.940
log of 28 days middle day: sd filter 0.940 smoother 0.705 (theory) middle day: RMSE filter 0.937 smoother 0.695 last day: RMSE filter 0.951 smoother 0.951 log of 120 days middle day: sd filter 0.940 smoother 0.704 (theory) middle day: RMSE filter 0.953 smoother 0.710 last day: RMSE filter 0.941 smoother 0.941 single reading sd 2.000 for comparison
核心公式
\[m^s_t=m_t+C_t\,(m^s_{t+1}-m_t),\qquad C_t=\frac{p_t}{P_{t+1}}.\]
查看完整验算程序
# Chapter 4. p41: Looking back with the RTS smoother.
# Rauch, Tung and Striebel (1965): after the forward Kalman pass, a
# backward pass m_s[t] = m_f[t] + C (m_s[t+1] - m_f[t]),
# C = P_f[t] / P_p[t+1], P_s[t] = P_f[t] + C^2 (P_s[t+1] - P_p[t+1]).
# Local level, q = 0.25 and r = 4 as in p11; 28-day logs (four weeks)
# and 120-day logs. Reported: theoretical sd of the filtered and the
# smoothed estimate at the middle and at the last day, and the RMSE of
# both over 600 simulated logs. Fixed seed; illustrative numbers.
import math
import random
import statistics
Q, R = 0.25, 4.0
rng = random.Random(20261118)
def forward(ys, m=0.0, p=100.0):
mf, pf, pp_ = [], [], []
for y in ys:
pp = p + Q
k = pp / (pp + R)
m = m + k * (y - m)
p = pp * (1 - k)
mf.append(m)
pf.append(p)
pp_.append(pp)
return mf, pf, pp_
def rts(mf, pf, pp_):
ms, ps = mf[:], pf[:]
for t in range(len(mf) - 2, -1, -1):
c = pf[t] / pp_[t + 1]
ms[t] = mf[t] + c * (ms[t + 1] - mf[t])
ps[t] = pf[t] + c * c * (ps[t + 1] - pp_[t + 1])
return ms, ps
for n in (28, 120):
ef, es, el_f, el_s = [], [], [], []
for _ in range(600):
mu, mus, ys = 0.0, [], []
for _ in range(n):
mu += rng.gauss(0, math.sqrt(Q))
mus.append(mu)
ys.append(mu + rng.gauss(0, math.sqrt(R)))
mf, pf, pp_ = forward(ys)
ms, ps = rts(mf, pf, pp_)
mid = n // 2
ef.append((mf[mid] - mus[mid]) ** 2)
es.append((ms[mid] - mus[mid]) ** 2)
el_f.append((mf[-1] - mus[-1]) ** 2)
el_s.append((ms[-1] - mus[-1]) ** 2)
print("log of %d days" % n)
print(" middle day: sd filter %.3f smoother %.3f (theory)"
% (math.sqrt(pf[mid]), math.sqrt(ps[mid])))
print(" middle day: RMSE filter %.3f smoother %.3f"
% (math.sqrt(statistics.fmean(ef)),
math.sqrt(statistics.fmean(es))))
print(" last day: RMSE filter %.3f smoother %.3f"
% (math.sqrt(statistics.fmean(el_f)),
math.sqrt(statistics.fmean(el_s))))
print("single reading sd %.3f for comparison" % math.sqrt(R))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《卡尔曼滤波状态空间同化、可穿戴读数观测噪音与广告归因真实信号提纯母典》第 4 章「回看与补洞:RTS 平滑、缺测日与伪读数」(版本 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}
}