What does Hidden Markov Models for Customer Decision Stages conclude, in numbers, about “Forward and Backward: Posterior Marginals, the Best Path and "Wait Two More Clicks"”?
Answer: Chapter 3 covers forward-backward and the two optimality criteria; judging two clicks later adds 0.0413 in accuracy.
Scope of the numbers: Marked boxes separate published evidence, runnable Python calculations (18 programs), classical sources and the author's hypotheses.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 0.0413
| stage at clicks 1-6 of 3000 visits, judged with L later clicks | |||
| lag L | 4-stage acc | ready acc | gain over L=0 |
| 0 | 0.5596 | 0.7832 | +0.0000 |
| 1 | 0.5873 | 0.8062 | +0.0277 |
| 2 | 0.6009 | 0.8146 | +0.0413 |
| 3 | 0.6015 | 0.8169 | +0.0419 |
| 4 | 0.6026 | 0.8167 | +0.0429 |
| 8 | 0.6057 | 0.8186 | +0.0461 |
Key formula
Show the full program
# Chapter 3. p33: what waiting a few clicks buys, fixed-lag smoothing.
# Model: the four-stage HMM of p11 (illustrative). 3,000 visits of 10
# to 16 clicks, fixed seed. The stage at click t is judged from clicks
# 1 to t + L. L = 0 is the real-time filter, the only rule a live reply
# can use; larger L means answering L clicks later. Reported: 4-stage
# accuracy and ready-or-not accuracy (ready = compare or decide) at
# each lag, over clicks 1 to 6 of every visit so all lags are defined.
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
la = [[math.log(x) for x in r] for r in A]
lb = [[math.log(x) for x in r] for r in B]
LAGS = (0, 1, 2, 3, 4, 8)
def lse(xs):
top = max(xs)
return top + math.log(math.fsum(math.exp(x - top) for x in xs))
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 smoothed(obs, t):
# 用前 len(obs) 次点击判断第 t 次点击时的阶段
al = [math.log(PI[k]) + lb[k][obs[0]] for k in range(K)]
for u in range(1, t + 1):
al = [lse([al[i] + la[i][j] for i in range(K)]) + lb[j][obs[u]]
for j in range(K)]
be = [0.0] * K
for u in range(len(obs) - 2, t - 1, -1):
be = [lse([la[i][j] + lb[j][obs[u + 1]] + be[j]
for j in range(K)]) for i in range(K)]
return max(range(K), key=lambda k: al[k] + be[k])
rng = random.Random(20261113)
N = 3000
acc = {L: [] for L in LAGS}
rdy = {L: [] for L in LAGS}
for _ in range(N):
t_len = rng.randint(10, 16)
s = [draw(rng, PI)]
for _ in range(t_len - 1):
s.append(draw(rng, A[s[-1]]))
o = [draw(rng, B[k]) for k in s]
for t in range(6):
for L in LAGS:
g = smoothed(o[:t + L + 1], t)
acc[L].append(1.0 if g == s[t] else 0.0)
rdy[L].append(1.0 if (g >= 2) == (s[t] >= 2) else 0.0)
print("stage at clicks 1-6 of %d visits, judged with L later clicks" % N)
print("lag L 4-stage acc ready acc gain over L=0")
base = math.fsum(acc[0]) / len(acc[0])
for L in LAGS:
a = math.fsum(acc[L]) / len(acc[L])
r = math.fsum(rdy[L]) / len(rdy[L])
print("%5d %11.4f %9.4f %+12.4f" % (L, a, r, a - base))Single source and citation
Fan, Y. (2026). Hidden Markov Models and Viterbi Decoding: Inferring a Customer's Hidden Decision Stage from Click Sequences and Timing the Offer (Version 1.0.0), Chapter 3: Forward and Backward: Posterior Marginals, the Best Path and "Wait Two More Clicks". 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 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}
}Other chapter answers in this book
- Chapter 1 · The Last-Click Illusion: Whole Sequences against a Single Page
- Chapter 2 · The Viterbi Trellis: Dynamic Programming in Logarithms, Backtracking and Underflow
- Chapter 4 · Baum–Welch: Estimating Parameters from Unlabelled Clickstreams
- Chapter 5 · Identifiability and Label Switching: What Clickstreams Cannot Say
- Chapter 6 · Timing the Offer: the Inquiry as Evidence, a Cost Threshold and Calibration
- Chapter 7 · Classical Sources East and West: Markov's Letter Chain in Onegin and the Chuai Chapter of the Guiguzi
- Chapter 8 · Closing the Loop: a Weekly Stage Review, the Customer Stage Decoder and Pre-Registered Tests