I am trying to understand Viterbi Algorithm.
The states are; S1, S2, S3, BEGIN, END
The values are rounded and truncated.
The smoothed State transition table is as follows;
S1 S2 S3 B E
S1 -0.7 -1.6 -1.6 -INF -2.0
S2 -2.0 -1.3 -0.7 -INF -2.0
S3 -1.3 -0.7 -2.0 -INF -2.0
B -1.2 -1.2 -1.2 -INF -1.9
E -INF -INF -INF -INF -INF
The smoothed emission table from states to red, green, blue;
RED GREEN BLUE
S1 -0.9 -1.2 -1.6
S2 -1.6 -0.9 -1.2
S3 -1.6 -1.6 -0.6
B -INF -INF -INF
E -INF -INF -INF
The question is; Symbols have been seen are; RED RED GREEN BLUE
what are the most likely states?
Therefore;
I created the Viterbi algorithm matrix according to values above;
First row represent the S1, S2, S3 values when RED symbol seen, just like that rest of rows for S1,S2,S3 values when red, green and blue seen.
For the first row I calculated it;
values are smoothed by taking natural logarithms of them therefore I am adding values instead of multiplying.
For the first red seen;
δ(S1) = MAX{P(S1|B)+P(R|S1)+δ(B)} = -1.2 - 0.9 + 0= -2.1
δ(S2) = MAX{P(S2|B)+P(R|S2)+δ(B)} = -1.2 - 1.6 + 0= -2.8
δ(S3) = MAX{P(S3|B)+P(R|S3)+δ(B)} = -1.2 - 1.6 + 0= -2.8
Just like above, for the next red seen;
δ(S1) = MAX{ (P(S1|S1)+P(R|S1)+δ(S1) ), ( P(S1|S2)+P(R|S2)+δ(S2) ), ( P(S1|S3)+P(R|S3)+δ(S3) )}
= MAX{ (-0.7-0.9-2.1),(-1.6-1.6-2.8), (-1.6-1.6-2.8) } = MAX{-3.7, -6, -6}
The maximum is -3.7 therefore S1 value when RED is seen; -3.7 . Rest of the values are calculated as above.
Viterbi Algorithm Matrix;
S1 S2 S3 B E
RED -2.1 -2.8 -2.8 -INF -INF
RED -3.7 -5.2 -5.2 -INF -INF
GREEN -5.8 -6.3 -7.0 -INF -INF
BLUE -8.1 -8.6 -7.8 -INF -INF
The answer of this example shows that most likely states are; S1, S1, S2, S3
However shouldn't it be; S1, S1, S1, S3? Because maximum value for the first red is -2.1 which is belong S1 and for second red it is again S1, and for the third one again S1 value is highest and for the blue S3 value is the highest. I can be wrong because I actually couldn't understand the dynamic programming approach for Viterbi.