I am confused about the re-erstimation procedure for emissions in HMMs with Baum-Welch (still). I posted two questions concerning this general topic already and I thought I had cleared up my confusion, but not so. At least not in its entirety. The remaining issue I have is this:
Say I have a HMM with some number of states and a set of 4 emissions. Assume for state $s_k$ I have the following distribution of emissions:
e1 e2 e3 e4
.2 .1 .3 .4
Now suppose the next training sequence is e3 e1
Then the re-estimations for the emissions of state $s_k$ are the following:
$$b_{s_k}(e_1) = \frac{\gamma_1(k)}{\gamma_1(k) + \gamma_2(k)}$$
Let's just say this was equal to .3
$$b_{s_k}(e_2) = \frac{0}{\gamma_1(k) + \gamma_2(k)} = 0$$
$$b_{s_k}(e_3) = \frac{\gamma_2(k)}{\gamma_1(k) + \gamma_2(k)}$$
Let's assume this to be .7 then.
$$b_{s_k}(e_4) = \frac{0}{\gamma_1(k) + \gamma_2(k)} = 0$$
Ok so the re-estimated distribution looks like this then:
e1 e2 e3 e4
.3 .0 .7 .0
After doing this re-estimation for all states with the current sequence I assign the newly estimated ditributions to my HMM by swapping them out for the old distributions and go to the next training sequence.
So, for emissions not observed in the current training sequence I have just wiped out all emission probabilities I had estimated so far. If the next sequence would be for example e2 e4
I would end up wipig the estimations for e1
and e3
again. This cannot be correct, so I must (still) be missing something here. What is that though?
Edit 1
The way I now went about this is to just replace the non-zero re-estimates and keep the rest and finally re-normalise all emissions. No idea if that actually does the job or messes with the guanrantee of convergence, but I see no other way.
Edit 2
It does seem to mess with with the rest of the algorithm, because this leads to all transition probabilities per state to converge to 0 with one transition converging to 1.
Why has nobody an answer to this? Is the example confusing? Is my general problem unclear?
Edit 3
Ok, so just to make sure I got this right: I first build expected values like so: I go over the data set and for each sequence I compute $\sum_{t=1}^{|y|} \xi_t(i, j)$ and accumulate these values for instance in a matirx cell $\xi\text{-acc}[i, j]$
So I end up with
$$\forall i, j : \text{expect-trans}[i, j] \leftarrow \sum_{y \in Y} \sum_{t=1}^{|y|} \xi_t(i, j)$$
These are all the expected values for all transitions $i \to j$.
Then I do the same for the gamma values:
$$\forall i : \text{expect-state}[i] \leftarrow \sum_{y \in Y} \sum_{t=1}^{|y|} \gamma_t(i)$$
These are all the expected values for visiting state $i$.
Then I also still need to do this for the emissions
$$\forall i, e : \text{expect-emiss}[i, e] \leftarrow \sum_{y \in Y} \sum_{t=1}^{|y|} \gamma_t(i) \cdot \chi_{[y_t = e]}$$
These are all teh expected counts for emitting $e$ from $i$.
Once I have all of these expected values I can go over to the maximization step: \begin{align*} &\forall i : \text{HMM.init-prob(i)} & \leftarrow &&\frac{\text{expect-state}[i]}{\sum_{j=1}^N \text{expect-state}[j]}\\ \\ &\forall i, j : \text{HMM.trans-prob(i, j)} & \leftarrow &&\frac{\text{expect-trans}[i, j]}{\text{expect-state}[i]}\\ \\ &\forall i, e : \text{HMM.emiss-prob(i, e)} & \leftarrow &&\frac{\text{expect-emiss}[i, e]}{\sum_{j=1}^N \text{expect-state}[j]}\\ \end{align*}
Have I got this right now? :/
Or is it rather this:
\begin{align*} &\forall y \in Y, i, j, t : \text{expect-trans}[i, j, t] &\leftarrow && \xi_t(i, j) + \text{expect-trans}[i, j, t]\\ \\ &\forall y \in Y i, t : \text{expect-state}[i, t] &\leftarrow && \gamma_t(i) + \text{expect-state}[i, t]\\ \\ &\forall y \in Y, i, e, t : \text{expect-emiss}[i, e, t] &\leftarrow && \gamma_t(i) \cdot \chi_{[y_t = e]} + \text{expect-emiss}[i, e, t] \end{align*}
with the max $t$ depending on the length of the current $y$.
\begin{align*} &\forall i : \text{HMM.init-prob(i)} & \leftarrow &&\frac{\text{expect-state}[i, 1]}{\sum_{j=1}^N \text{expect-state}[j, 1]}\\ \\ &\forall i, j : \text{HMM.trans-prob(i, j)} & \leftarrow &&\frac{\sum_{t=1}^T\text{expect-trans}[i, j, t]}{\sum_{t=1}^T\text{expect-state}[i, t]}\\ \\ &\forall i, e : \text{HMM.emiss-prob(i, e)} & \leftarrow &&\frac{\sum_{t=1}^T \text{expect-emiss}[i, e, t]}{\sum_{t=1}^T \sum_{j=1}^N \text{expect-state}[j, t]}\\ \end{align*}
with $T$ the max index of the rows $\text{expect-trans}[i, j, t]$ and $\text{expect-emiss}[i, e]$ respectively.