phvu / misc

Python scripts for various stuff: Viterbi algorithm, word2vec, etc...
43 stars 53 forks source link

Doubt in Viterbi implementation #3

Open tarunrkk opened 7 years ago

tarunrkk commented 7 years ago

Hi,

I am confused wrt lines 26 and 27 of the viterbi implementation: trellis[:, t] = (trellis[:, t-1, None].dot(self.Obs(obs[t]).T) * self.transProb).max(0) backpt[:, t] = (np.tile(trellis[:, t-1, None], [1, self.N]) * self.transProb).argmax(0)

I am not able to understand why there is no dot product happening in the second line. Why multiply only with transProb without taking obs into account?

Please help.

phvu commented 7 years ago

@tarunrkk: backpt is the backtrace to keep track the maximum decoding path. At timestep t, the backpt array keeps track of the best path so far up to timestep t-1. The observation probabilities obs at time t is taken into account in trellis at timestep t, which is taken into account in backpt at timestep t+1. If it is still confusing, here is the algorithm for your reference: https://phvuresearch.files.wordpress.com/2013/12/viterbi_algo.png?w=1024&h=704