<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=Viterbi_algorithm</id>
	<title>Viterbi algorithm - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=Viterbi_algorithm"/>
	<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=Viterbi_algorithm&amp;action=history"/>
	<updated>2026-05-15T06:18:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>http://en.zaoniao.it/index.php?title=Viterbi_algorithm&amp;diff=7508&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;&lt;amp/&gt; '''Viterbi algorithm''' is a dynamic programming algorithm for finding the most likely sequence of hidden states&amp;mdash;called the '''Vit...&quot;</title>
		<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=Viterbi_algorithm&amp;diff=7508&amp;oldid=prev"/>
		<updated>2019-08-23T10:18:29Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;amp/&amp;gt; &amp;#039;&amp;#039;&amp;#039;Viterbi algorithm&amp;#039;&amp;#039;&amp;#039; is a &lt;a href=&quot;/index.php?title=Dynamic_programming&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Dynamic programming (page does not exist)&quot;&gt;dynamic programming&lt;/a&gt; &lt;a href=&quot;/index.php?title=Algorithm&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Algorithm (page does not exist)&quot;&gt;algorithm&lt;/a&gt; for finding the most &lt;a href=&quot;/index.php?title=Likelihood_function&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Likelihood function (page does not exist)&quot;&gt;likely&lt;/a&gt; sequence of hidden states—called the &amp;#039;&amp;#039;&amp;#039;Vit...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;amp/&amp;gt;&lt;br /&gt;
'''Viterbi algorithm''' is a [[dynamic programming]] [[algorithm]] for finding the most [[likelihood function|likely]] sequence of hidden states&amp;amp;mdash;called the '''Viterbi path'''&amp;amp;mdash;that results in a sequence of observed events, especially in the context of [[Markov information source]]s and [[hidden Markov model]]s.&lt;br /&gt;
&lt;br /&gt;
The algorithm has found universal application in decoding the [[convolutional code]]s used in both [[CDMA]] and [[GSM]] digital cellular, [[dial-up]] modems, satellite, deep-space communications, and [[802.11]] wireless LANs. It is now also commonly used in [[speech recognition]], [[speech synthesis]], [[diarization]], [[keyword spotting]], [[computational linguistics]], and [[bioinformatics]]. For example, in [[speech-to-text]] (speech recognition), the acoustic signal is treated as the observed sequence of events, and a string of text is considered to be the &amp;quot;hidden cause&amp;quot; of the acoustic signal. The Viterbi algorithm finds the most likely string of text given the acoustic signal.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
The Viterbi algorithm is named after [[Andrew Viterbi]], who proposed it in 1967 as a decoding algorithm for [[Convolution code|convolutional codes]] over noisy digital communication links. It has, however, a history of [[multiple invention]], with at least seven independent discoveries, including those by Viterbi, [[Needleman–Wunsch algorithm|Needleman and Wunsch]], and [[Wagner–Fischer algorithm|Wagner and Fischer]].&amp;lt;!-- Jurafsky and Martin specifically refer to the papers that presented the Needleman–Wunsch and Wagner–Fischer algorithms, hence the wikilinks to those--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Viterbi path&amp;quot; and &amp;quot;Viterbi algorithm&amp;quot; have become standard terms for the application of dynamic programming algorithms to maximization problems involving probabilities.&lt;br /&gt;
&lt;br /&gt;
==Extensions==&lt;br /&gt;
A generalization of the Viterbi algorithm, termed the ''max-sum algorithm'' (or ''max-product algorithm'') can be used to find the most likely assignment of all or some subset of [[latent variable]]s in a large number of [[graphical model]]s, e.g. [[Bayesian network]]s, [[Markov random field]]s and [[conditional random field]]s. The latent variables need in general to be connected in a way somewhat similar to an HMM, with a limited number of connections between variables and some type of linear structure among the variables. The general algorithm involves ''message passing'' and is substantially similar to the [[belief propagation]] algorithm (which is the generalization of the [[forward-backward algorithm]]).&lt;br /&gt;
&lt;br /&gt;
With the algorithm called [[iterative Viterbi decoding]] one can find the subsequence of an observation that matches best (on average) to a given [[hidden Markov model]]. This algorithm is proposed by Qi Wang et al. to deal with [[turbo code]]. Iterative Viterbi decoding works by iteratively invoking a modified Viterbi algorithm, reestimating the score for a filler until convergence.&lt;br /&gt;
&lt;br /&gt;
An alternative algorithm, the [[Lazy Viterbi algorithm]], has been proposed recently. For many codes of practical interest, under reasonable noise conditions, the lazy&lt;br /&gt;
decoder (using Lazy Viterbi algorithm) is much faster than the original [[Viterbi decoder]] (using Viterbi algorithm). This algorithm works by not expanding any nodes until it really needs to, and usually manages to get away with doing a lot less work (in software) than the ordinary Viterbi algorithm for the same result&amp;amp;mdash;however, it is not so easy to parallelize in hardware.&lt;br /&gt;
&lt;br /&gt;
==Pseudocode==&lt;br /&gt;
This algorithm generates a path &amp;lt;math&amp;gt; X=(x_1,x_2,\ldots,x_T) &amp;lt;/math&amp;gt;, which is a sequence of states &amp;lt;math&amp;gt;x_n \in S=\{s_1,s_2,\dots,s_K\}&amp;lt;/math&amp;gt; that generate the observations &amp;lt;math&amp;gt; Y=(y_1,y_2,\ldots, y_T) \in \{1,2,\dots,N\}^T&amp;lt;/math&amp;gt; (&amp;lt;math&amp;gt;N&amp;lt;/math&amp;gt; being the count of observations (observation space, see below)).&lt;br /&gt;
&lt;br /&gt;
Two 2-dimensional tables of size &amp;lt;math&amp;gt;K \times T&amp;lt;/math&amp;gt; are constructed:&lt;br /&gt;
&lt;br /&gt;
* Each element &amp;lt;math&amp;gt;T_1[i,j]&amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;T_1&amp;lt;/math&amp;gt; stores the probability of the most likely path so far &amp;lt;math&amp;gt; \hat{X}=(\hat{x}_1,\hat{x}_2,\ldots,\hat{x}_j) &amp;lt;/math&amp;gt; with &amp;lt;math&amp;gt;\hat{x}_j=s_i &amp;lt;/math&amp;gt; that generates &amp;lt;math&amp;gt; Y=(y_1,y_2,\ldots, y_j)&amp;lt;/math&amp;gt;.&lt;br /&gt;
* Each element &amp;lt;math&amp;gt;T_2[i,j] &amp;lt;/math&amp;gt; of &amp;lt;math&amp;gt;T_2 &amp;lt;/math&amp;gt; stores &amp;lt;math&amp;gt;\hat{x}_{j-1} &amp;lt;/math&amp;gt; of the most likely path so far &amp;lt;math&amp;gt; \hat{X}=(\hat{x}_1,\hat{x}_2,\ldots,\hat{x}_{j-1},\hat{x}_j = s_i)&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt;\forall j, 2\leq j \leq T &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The table entries &amp;lt;math&amp;gt; T_1[i,j],T_2[i,j]&amp;lt;/math&amp;gt; are filled by increasing order of &amp;lt;math&amp;gt;K\cdot j+i &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;T_1[i,j]=\max_{k}{(T_1[k,j-1]\cdot A_{ki}\cdot B_{iy_j})} &amp;lt;/math&amp;gt;, and&lt;br /&gt;
:&amp;lt;math&amp;gt; T_2[i,j]=\operatorname{argmax}_{k}{(T_1[k,j-1]\cdot A_{ki}\cdot B_{iy_j})} &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
with &amp;lt;math&amp;gt;A_{ki}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;B_{iy_j}&amp;lt;/math&amp;gt; as defined below. Note that &amp;lt;math&amp;gt;B_{iy_j}&amp;lt;/math&amp;gt; does not need to appear in the latter expression, as it's non-negative and independent of &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and thus does not affect the argmax.&lt;br /&gt;
&lt;br /&gt;
;INPUT:&lt;br /&gt;
* The [[observation space]] &amp;lt;math&amp;gt; O=\{o_1,o_2,\dots,o_N\}&amp;lt;/math&amp;gt;&lt;br /&gt;
* the [[state space]] &amp;lt;math&amp;gt; S=\{s_1,s_2,\dots,s_K\} &amp;lt;/math&amp;gt;&lt;br /&gt;
* an array of initial probabilities &amp;lt;math&amp;gt; \Pi = (\pi_1,\pi_2,\dots,\pi_K)&amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt; \pi_i &amp;lt;/math&amp;gt; stores the probability that &amp;lt;math&amp;gt; x_1 == s_i &amp;lt;/math&amp;gt;&lt;br /&gt;
* a sequence of observations &amp;lt;math&amp;gt; Y=(y_1,y_2,\ldots, y_T) &amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt; y_t==i &amp;lt;/math&amp;gt; if the observation at time &amp;lt;math&amp;gt; t &amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt; o_i &amp;lt;/math&amp;gt;&lt;br /&gt;
* [[transition matrix]] &amp;lt;math&amp;gt; A &amp;lt;/math&amp;gt; of size &amp;lt;math&amp;gt; K\times K &amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt; A_{ij} &amp;lt;/math&amp;gt; stores the [[transition probability]] of transiting from state &amp;lt;math&amp;gt; s_i &amp;lt;/math&amp;gt; to state &amp;lt;math&amp;gt; s_j &amp;lt;/math&amp;gt;&lt;br /&gt;
* [[emission matrix]] &amp;lt;math&amp;gt; B &amp;lt;/math&amp;gt; of size &amp;lt;math&amp;gt; K\times N &amp;lt;/math&amp;gt; such that &amp;lt;math&amp;gt; B_{ij} &amp;lt;/math&amp;gt; stores the probability of observing &amp;lt;math&amp;gt; o_j &amp;lt;/math&amp;gt; from state &amp;lt;math&amp;gt; s_i &amp;lt;/math&amp;gt; &lt;br /&gt;
;OUTPUT: &lt;br /&gt;
*The most likely hidden state sequence &amp;lt;math&amp;gt; X=(x_1,x_2,\ldots,x_N) &amp;lt;/math&amp;gt;&lt;br /&gt;
 '''function''' ''VITERBI''&amp;lt;math&amp;gt;(O,S,\Pi,Y,A,B):X&amp;lt;/math&amp;gt;&lt;br /&gt;
 '''for''' each state &amp;lt;math&amp;gt;i \in \{1,2,\ldots,K\}&amp;lt;/math&amp;gt; '''do'''&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 '''end for'''&lt;br /&gt;
 '''for''' each observation &amp;lt;math&amp;gt;i = 2,3,\ldots,T&amp;lt;/math&amp;gt; '''do'''&lt;br /&gt;
 '''for''' each state &amp;lt;math&amp;gt;j \in \{1,2,\ldots,K\}&amp;lt;/math&amp;gt; '''do'''&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 '''end for'''&lt;br /&gt;
 '''end for'''&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 '''for''' '''do'''&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 '''end for'''&lt;br /&gt;
 '''return''' &lt;br /&gt;
 '''end function'''&lt;br /&gt;
&lt;br /&gt;
;EXPLANATION:&lt;br /&gt;
Suppose we are given a [[hidden Markov model]] (HMM) with state space &amp;lt;math&amp;gt;S&amp;lt;/math&amp;gt;, initial probabilities &amp;lt;math&amp;gt;\pi_i&amp;lt;/math&amp;gt; of being in state &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; and transition probabilities &amp;lt;math&amp;gt;a_{i,j}&amp;lt;/math&amp;gt; of transitioning from state &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; to state &amp;lt;math&amp;gt;j&amp;lt;/math&amp;gt;. Say we observe outputs &amp;lt;math&amp;gt;y_1,\dots, y_T&amp;lt;/math&amp;gt;. The most likely state sequence &amp;lt;math&amp;gt;x_1,\dots,x_T&amp;lt;/math&amp;gt; that produces the observations is given by the recurrence relations:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{array}{rcl}&lt;br /&gt;
V_{1,k} &amp;amp;=&amp;amp; \mathrm{P}\big( y_1 \ | \ k \big) \cdot \pi_k \\&lt;br /&gt;
V_{t,k} &amp;amp;=&amp;amp; \max_{x \in S} \left( \mathrm{P}\big( y_t \ | \ k \big) \cdot a_{x,k} \cdot V_{t-1,x}\right)&lt;br /&gt;
\end{array}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;V_{t,k}&amp;lt;/math&amp;gt; is the probability of the most probable state sequence &amp;lt;math&amp;gt;\mathrm{P}\big(x_1,\dots,x_T,y_1,\dots, y_T\big)&amp;lt;/math&amp;gt; responsible for the first &amp;lt;math&amp;gt;t&amp;lt;/math&amp;gt; observations that have &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; as its final state. The Viterbi path can be retrieved by saving back pointers that remember which state &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; was used in the second equation. Let &amp;lt;math&amp;gt;\mathrm{Ptr}(k,t)&amp;lt;/math&amp;gt; be the function that returns the value of &amp;lt;math&amp;gt;x&amp;lt;/math&amp;gt; used to compute &amp;lt;math&amp;gt;V_{t,k}&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t &amp;gt; 1&amp;lt;/math&amp;gt;, or &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; if &amp;lt;math&amp;gt;t=1&amp;lt;/math&amp;gt;. Then:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;&lt;br /&gt;
\begin{array}{rcl}&lt;br /&gt;
x_T &amp;amp;=&amp;amp; \arg\max_{x \in S} (V_{T,x}) \\&lt;br /&gt;
x_{t-1} &amp;amp;=&amp;amp; \mathrm{Ptr}(x_t,t)&lt;br /&gt;
\end{array}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
Here we're using the standard definition of [[arg max]].&amp;lt;br&amp;gt;&lt;br /&gt;
The complexity of this algorithm is &amp;lt;math&amp;gt;O(T\times\left|{S}\right|^2)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
Consider a village where all villagers are either healthy or have a fever and only the village doctor can determine whether each has a fever. The doctor diagnoses fever by asking patients how they feel. The villagers may only answer that they feel normal, dizzy, or cold.&lt;br /&gt;
&lt;br /&gt;
The doctor believes that the health condition of his patients operate as a discrete [[Markov chain]]. There are two states, &amp;quot;Healthy&amp;quot; and &amp;quot;Fever&amp;quot;, but the doctor cannot observe them directly; they are ''hidden'' from him. On each day, there is a certain chance that the patient will tell the doctor he/she is &amp;quot;normal&amp;quot;, &amp;quot;cold&amp;quot;, or &amp;quot;dizzy&amp;quot;, depending on their health condition.&lt;br /&gt;
&lt;br /&gt;
The ''observations'' (normal, cold, dizzy) along with a ''hidden'' state (healthy, fever) form a hidden Markov model (HMM), and can be represented as follows in the [[Python (programming language)|Python programming language]]:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
obs = ('normal', 'cold', 'dizzy')&lt;br /&gt;
states = ('Healthy', 'Fever')&lt;br /&gt;
start_p = {'Healthy': 0.6, 'Fever': 0.4}&lt;br /&gt;
trans_p = {&lt;br /&gt;
 'Healthy' : {'Healthy': 0.7, 'Fever': 0.3},&lt;br /&gt;
 'Fever' : {'Healthy': 0.4, 'Fever': 0.6}&lt;br /&gt;
 }&lt;br /&gt;
emit_p = {&lt;br /&gt;
 'Healthy' : {'normal': 0.5, 'cold': 0.4, 'dizzy': 0.1},&lt;br /&gt;
 'Fever' : {'normal': 0.1, 'cold': 0.3, 'dizzy': 0.6}&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In this piece of code, &amp;lt;code&amp;gt;start_probability&amp;lt;/code&amp;gt; represents the doctor's belief about which state the HMM is in when the patient first visits (all he knows is that the patient tends to be healthy). The particular probability distribution used here is not the equilibrium one, which is (given the transition probabilities) approximately &amp;lt;code&amp;gt;{'Healthy': 0.57, 'Fever': 0.43}&amp;lt;/code&amp;gt;. The &amp;lt;code&amp;gt;transition_probability&amp;lt;/code&amp;gt; represents the change of the health condition in the underlying Markov chain. In this example, there is only a 30% chance that tomorrow the patient will have a fever if he is healthy today. The &amp;lt;code&amp;gt;emission_probability&amp;lt;/code&amp;gt; represents how likely the patient is to feel on each day. If he is healthy, there is a 50% chance that he feels normal; if he has a fever, there is a 60% chance that he feels dizzy.&lt;br /&gt;
&lt;br /&gt;
The patient visits three days in a row and the doctor discovers that on the first day he feels normal, on the second day he feels cold, on the third day he feels dizzy. The doctor has a question: what is the most likely sequence of health conditions of the patient that would explain these observations? This is answered by the Viterbi algorithm.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
def viterbi(obs, states, start_p, trans_p, emit_p):&lt;br /&gt;
 V = [{}]&lt;br /&gt;
 for st in states:&lt;br /&gt;
 V[0][st] = {&amp;quot;prob&amp;quot;: start_p[st] * emit_p[st][obs[0]], &amp;quot;prev&amp;quot;: None}&lt;br /&gt;
 # Run Viterbi when t &amp;gt; 0&lt;br /&gt;
 for t in range(1, len(obs)):&lt;br /&gt;
 V.append({})&lt;br /&gt;
 for st in states:&lt;br /&gt;
 max_tr_prob = max(V[t-1][prev_st][&amp;quot;prob&amp;quot;]*trans_p[prev_st][st] for prev_st in states)&lt;br /&gt;
 for prev_st in states:&lt;br /&gt;
 if V[t-1][prev_st][&amp;quot;prob&amp;quot;] * trans_p[prev_st][st] == max_tr_prob:&lt;br /&gt;
 max_prob = max_tr_prob * emit_p[st][obs[t]]&lt;br /&gt;
 V[t][st] = {&amp;quot;prob&amp;quot;: max_prob, &amp;quot;prev&amp;quot;: prev_st}&lt;br /&gt;
 break&lt;br /&gt;
 for line in dptable(V):&lt;br /&gt;
 print line&lt;br /&gt;
 opt = []&lt;br /&gt;
 # The highest probability&lt;br /&gt;
 max_prob = max(value[&amp;quot;prob&amp;quot;] for value in V[-1].values())&lt;br /&gt;
 previous = None&lt;br /&gt;
 # Get most probable state and its backtrack&lt;br /&gt;
 for st, data in V[-1].items():&lt;br /&gt;
 if data[&amp;quot;prob&amp;quot;] == max_prob:&lt;br /&gt;
 opt.append(st)&lt;br /&gt;
 previous = st&lt;br /&gt;
 break&lt;br /&gt;
 # Follow the backtrack till the first observation&lt;br /&gt;
 for t in range(len(V) - 2, -1, -1):&lt;br /&gt;
 opt.insert(0, V[t + 1][previous][&amp;quot;prev&amp;quot;])&lt;br /&gt;
 previous = V[t + 1][previous][&amp;quot;prev&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
 print 'The steps of states are ' + ' '.join(opt) + ' with highest probability of %s' % max_prob&lt;br /&gt;
&lt;br /&gt;
def dptable(V):&lt;br /&gt;
 # Print a table of steps from dictionary&lt;br /&gt;
 yield &amp;quot; &amp;quot;.join((&amp;quot;%12d&amp;quot; % i) for i in range(len(V)))&lt;br /&gt;
 for state in V[0]:&lt;br /&gt;
 yield &amp;quot;%.7s: &amp;quot; % state + &amp;quot; &amp;quot;.join(&amp;quot;%.7s&amp;quot; % (&amp;quot;%f&amp;quot; % v[state][&amp;quot;prob&amp;quot;]) for v in V)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The function &amp;lt;code&amp;gt;viterbi&amp;lt;/code&amp;gt; takes the following arguments: &amp;lt;code&amp;gt;obs&amp;lt;/code&amp;gt; is the sequence of observations, e.g. &amp;lt;code&amp;gt;['normal', 'cold', 'dizzy']&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;states&amp;lt;/code&amp;gt; is the set of hidden states; &amp;lt;code&amp;gt;start_p&amp;lt;/code&amp;gt; is the start probability; &amp;lt;code&amp;gt;trans_p&amp;lt;/code&amp;gt; are the transition probabilities; and &amp;lt;code&amp;gt;emit_p&amp;lt;/code&amp;gt; are the emission probabilities. For simplicity of code, we assume that the observation sequence &amp;lt;code&amp;gt;obs&amp;lt;/code&amp;gt; is non-empty and that &amp;lt;code&amp;gt;trans_p[i][j]&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;emit_p[i][j]&amp;lt;/code&amp;gt; is defined for all states i,j.&lt;br /&gt;
&lt;br /&gt;
In the running example, the forward/Viterbi algorithm is used as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
viterbi(obs,&lt;br /&gt;
 states,&lt;br /&gt;
 start_p,&lt;br /&gt;
 trans_p,&lt;br /&gt;
 emit_p)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output of the script is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ python viterbi_example.py&lt;br /&gt;
 0 1 2&lt;br /&gt;
Healthy: 0.30000 0.08400 0.00588&lt;br /&gt;
Fever: 0.04000 0.02700 0.01512&lt;br /&gt;
The steps of states are Healthy Healthy Fever with highest probability of 0.01512&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This reveals that the observations &amp;lt;code&amp;gt;['normal', 'cold', 'dizzy']&amp;lt;/code&amp;gt; were most likely generated by states &amp;lt;code&amp;gt;['Healthy', 'Healthy', 'Fever']&amp;lt;/code&amp;gt;. In other words, given the observed activities, the patient was most likely to have been healthy both on the first day when he felt normal as well as on the second day when he felt cold, and then he contracted a fever the third day.&lt;br /&gt;
&lt;br /&gt;
The operation of Viterbi's algorithm can be visualized by means of a&lt;br /&gt;
[[Trellis diagram#Trellis diagram|trellis diagram]]. The Viterbi path is essentially the shortest&lt;br /&gt;
path through this trellis. The trellis for the clinic example is shown below; the corresponding&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Soft output Viterbi algorithm]]&lt;br /&gt;
* [[Viterbi decoder]]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Source==&lt;br /&gt;
&lt;br /&gt;
[http://wikipedia.org/ http://wikipedia.org/]&lt;br /&gt;
&lt;br /&gt;
[[Category:Cryptographic algorithms]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
		
	</entry>
</feed>