P*(i,s',s) = P(y1...yk observed AND i-th state transition is s--> s')Notice that c is defined in terms of P*. In turn, P* can be computed from intermediate quantities alphai(s) and betai(s) defined as follows:c(s --> s') = sum from i=0 to i=k of P*(i, s', s)
alphai(s) = P(y1...yi observed AND i-th state is s)In fact, we have:betai(s) = P(yi+1...yk observed AND i-th state is s)
P*(i,s',s) = alphai(s)*ps'<--s*q(yi+1 | s'<--s)*betai+1(s')The forward-backward algorithm updates the alphas and betas and then computes maximum likelihood estimates for P* and c using the preceding expressions. See the pseudocode below.
For each state s: alphai+1(s) = sumall states s' alphai(s')*ps,s'*q(yi+1 | s <-- s')
For each state s: betai-1(s) = sumall states s' ps',s*q(yi | s' <-- s)*betai(s')
P*(i, s', s) = alphai(s)*ps',s*q(yi+1 | s' <-- s)*betai+1(s')and
c(s',s) = sumi=0...k-1 P*(i,s',s)Then update the HMM parameters using the following maximum likelihood estimates:
ps',s = c(s',s) / sumall states s'' leaving s c(s'',s)q(y | s' <-- s) = sumeach i=0...k-1 such that yi=y P*(i,s',s) / c(s',s)