Implemented viterbi algorithm. Needs testing.
Viterbi algorithm seems to work now. Tests pass.