Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Viterbi algorithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Pseudocode == '''function''' Viterbi(states, init, trans, emit, obs) '''is''' '''input''' states: S hidden states '''input''' init: initial probabilities of each state '''input''' trans: S Γ S transition matrix '''input''' emit: S Γ O emission matrix '''input''' obs: sequence of T observations prob β T Γ S matrix of zeroes prev β empty T Γ S matrix '''for''' '''each''' state s '''in''' states '''do''' prob[0][s] = init[s] * emit[s][obs[0]] '''for''' t = 1 '''to''' T - 1 '''inclusive do''' ''// t = 0 has been dealt with already'' '''for''' '''each''' state s '''in''' states '''do''' '''for''' '''each''' state r '''in''' states '''do''' new_prob β prob[t - 1][r] * trans[r][s] * emit[s][obs[t]] '''if''' new_prob > prob[t][s] '''then''' prob[t][s] β new_prob prev[t][s] β r path β empty array of length T path[T - 1] β the state s with maximum prob[T - 1][s] '''for''' t = T - 2 '''to''' 0 '''inclusive do''' path[t] β prev[t + 1][path[t + 1]] '''return''' path '''end''' The time complexity of the algorithm is <math>O(T\times\left|{S}\right|^2)</math>. If it is known which state transitions have non-zero probability, an improved bound can be found by iterating over only those <math>r</math> which link to <math>s</math> in the inner loop. Then using [[amortized analysis]] one can show that the complexity is <math>O(T\times(\left|{S}\right| + \left|{E}\right|))</math>, where <math>E</math> is the number of edges in the graph, i.e. the number of non-zero entries in the transition matrix.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)