关于「维特比格子:对数域动态规划、回溯与下溢」,《隐马尔可夫与客户决策阶段》给出的定量结论是什么?

结论:第二章在格子图上展开维特比,说明直接相乘约在第 368 次点击下溢,最优路径只占全部概率的 0.0357。

数据口径:书中阶段、页面类型与全部概率均为示意;全部计算由书中程序生成;本书是非个人化经营建议,只使用站内匿名化与客户同意的数据,不跨站追踪,不推断敏感属性,阶段解码不用于施压、差别定价或主动联系客户,紧迫感只来自真实库存与真实截止。 第一章在示意参数下量出:前向滤波的四分类准确率比最后一次点击高 0.0410,就绪判别从 0.6990 提高到 0.7630;增益随阶段黏性与页面区分力在 0.0307 到 0.1187 之间变化,维特比最后一格在页面模糊时反而低 0.1007。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 368

smallest positive double: 4.941e-324
Traw log Plog-domainscaledraw path = log path
50-105.41-105.41-105.411.000
200-410.93-410.93-410.931.000
400-inf(0.0)-818.24-818.240.943
600-inf(0.0)-1228.56-1228.560.632
1000-inf(0.0)-2042.15-2042.150.408
2000-inf(0.0)-4042.20-4042.200.255
log-probability per click: -2.021 nats
raw products die near T = 368 clicks

核心公式

\[\delta_t(j) = \max_i \left[ \delta_{t-1}(i)\, a_{ij} \right] b_j(o_t),\]
查看完整验算程序
# Chapter 2. p22: why decoding must run in logs (or with scaling).
# Model: the four-stage HMM of p11 (illustrative). One long click stream
# is simulated with a fixed seed, as if a member's consented, anonymised
# clicks over many visits were decoded together. At several lengths T
# the program runs the Viterbi recursion three ways: raw products of
# probabilities, natural logs, and per-step rescaling (divide by the
# column maximum and keep the log of the divisor). Raw products sink
# below the smallest double and the decoded path turns to nonsense.
import math
import random

PI = [0.70, 0.20, 0.08, 0.02]
A = [[0.70, 0.22, 0.06, 0.02],
     [0.08, 0.64, 0.23, 0.05],
     [0.02, 0.10, 0.66, 0.22],
     [0.01, 0.03, 0.16, 0.80]]
B = [[0.45, 0.30, 0.08, 0.07, 0.06, 0.04],
     [0.15, 0.35, 0.25, 0.12, 0.08, 0.05],
     [0.08, 0.22, 0.15, 0.30, 0.17, 0.08],
     [0.05, 0.12, 0.08, 0.15, 0.30, 0.30]]
K = 4


def draw(rng, probs):
    u, acc = rng.random(), 0.0
    for k, p in enumerate(probs):
        acc += p  # step
        if u < acc:
            return k
    return len(probs) - 1


def decode(obs, mode):
    # mode: raw 原始乘积;log 对数域;scale 每步按列最大值缩放
    if mode == "log":
        d = [math.log(PI[k] * B[k][obs[0]]) for k in range(K)]
    else:
        d = [PI[k] * B[k][obs[0]] for k in range(K)]
    logc = []
    back = []
    for o in obs[1:]:
        if mode == "log":
            ptr = [max(range(K), key=lambda i: d[i] + math.log(A[i][j]))
                   for j in range(K)]
            d = [d[ptr[j]] + math.log(A[ptr[j]][j] * B[j][o])
                 for j in range(K)]
        else:
            ptr = [max(range(K), key=lambda i: d[i] * A[i][j])
                   for j in range(K)]
            d = [d[ptr[j]] * A[ptr[j]][j] * B[j][o] for j in range(K)]
            if mode == "scale":
                c = max(d)
                logc.append(math.log(c))
                d = [x / c for x in d]
        back.append(ptr)
    best = max(range(K), key=lambda k: d[k])
    path = [best]
    for ptr in reversed(back):
        path.append(ptr[path[-1]])
    if mode == "log":
        score = d[best]
    elif mode == "scale":
        score = math.log(d[best]) + math.fsum(logc)
    else:
        score = math.log(d[best]) if d[best] > 0 else -math.inf
    return path[::-1], score


rng = random.Random(20261113)
s = [0]
for _ in range(1999):
    s.append(draw(rng, A[s[-1]]))
o = [draw(rng, B[k]) for k in s]
print("smallest positive double: %.3e" % (5e-324))
print("    T   raw log P   log-domain   scaled   raw path = log path")
for t_len in (50, 200, 400, 600, 1000, 2000):
    obs = o[:t_len]
    p_raw, sc_raw = decode(obs, "raw")
    p_log, sc_log = decode(obs, "log")
    p_sc, sc_sc = decode(obs, "scale")
    agree = len([1 for a, b in zip(p_raw, p_log) if a == b]) / t_len
    raw_txt = "%10.2f" % sc_raw if sc_raw > -math.inf else "  -inf(0.0)"
    print("%5d  %s  %11.2f  %8.2f  %8.3f%s"
          % (t_len, raw_txt, sc_log, sc_sc, agree,
             "" if p_sc == p_log else "  scaled path differs"))
per_click = sc_log / 2000
print("log-probability per click: %.3f nats" % per_click)
print("raw products die near T = %d clicks"
      % int(math.log(5e-324) / per_click))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《隐马尔可夫维特比解码、浏览点击序列反推客户隐藏决策阶段与出手时机母典》第 2 章「维特比格子:对数域动态规划、回溯与下溢」(版本 1.0.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-300 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026300,
  author    = {Fan, Yafu},
  title     = {Hidden Markov Models and Viterbi Decoding: Inferring a Customer's Hidden Decision Stage from Click Sequences and Timing the Offer},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论