I am implementing the Baum-Welch Algorithm for training a Hidden Markov Process, to basically better understand the training process.
I have implemented the iterative procedures described in Rabiner's classic paper. My Implementation is in Wolfram Mathematica
. The problem I am facing is the scaling step, if the sequence is 100 observations long then the probabilities easily cross the bounds of $10^{-30}$.
My question is can anyone explain or provide a link where the calculation of scaled forward and backward matrices is described?
For the forward procedure the code is as follows:
ForwardProcedure[TM_, EM_, P_, N_, M_, Seq_] :=
Module[{DP, i, j, DPPart},
DP = ConstantArray[0, {N, M}];
DP[[1, All]] = Table[P[[i]]*EM[[i, Part[Seq, 1]]], {i, 1, N}];
DP = Table[
If[j == 1, P[[i]]*EM[[i, Part[Seq, 1]]], 0]
, {i, 1, N}, {j, 1, Length@Seq}];
For[j = 2, j <= Length@Seq, j++,
DPPart = DP[[All, j - 1]];
For[i = 1, i <= N, i++,
DP[[i, j]] = Dot[DPPart, TM[[All, i]]]*EM[[i, Part[Seq, j]]];
];
];
DP
]
Essentially DP[[i, j]] = Dot[DPPart, TM[[All, i]]]*EM[[i, Part[Seq, j]]];
This line is the update. Which simply takes the needed columns from Transition (TM), The alpha (DP) matrices and multiplies with the associated Emission value.
How can I have a scaling factor independent of i, when not all the t-s of the row of the DP matrix are filled?