|
| Algorithm 3 HMM backward-filtering forward-sampling algorithm for block-sampling z1:T
|
|
| 1: let π0 and π = (π1|…|πK)T be the initial and transition distributions |
| 2: let
be the likelihoods p(yt | zt = k) for each k
|
| 3: let
be the backward messages p(yt+1:T | zt = k) at t for each k
|
| 4: normalize each ut to sum to 1, preventing underflow during computations |
| 5: for
t = 1,…,T
do
|
| 6: ũt ← ut/ (1Tut) |
| 7: end for
|
| 8: calculate backward messages over all time points |
| 9: ζ̃T = 1
|
| 10: for
t = T − 1,…,1 do
|
| 11: transmit messages backward : τt+1 ← ũt+1 ∘ ζ̃t+1, ζt ← πτt+1
|
| 12: normalize : ζ̃t ← ζt/ (1Tζt) |
| 13: end for
|
| 14: τ1 ← ũ1 ∘ ζ̃1
|
| 15: sample first time point |
| 16: q1 ← π0 ∘ τ1, q̃1 ← q1/(1Tq) |
| 17: z1 ~ q̃1
|
| 18: sample other time points |
| 19: for
t = 2,…,T
do
|
| 20: qt ← πzt−1 ∘ τt, q̃t ← qt/ (1Tqt) |
| 21: zt ~ q̃t
|
| 22: end for
|
|