TheViterbi algorithm is adynamic programmingalgorithm that finds the most likely sequence of hidden events that would explain a sequence of observed events. The result of the algorithm is often called theViterbi path. It is most commonly used withhidden Markov models (HMMs). For example, if a doctor observes a patient's symptoms over several days (the observed events), the Viterbi algorithm could determine the most probable sequence of underlying health conditions (the hidden events) that caused those symptoms.
The algorithm has found universal application in decoding theconvolutional codes used in bothCDMA andGSM digital cellular,dial-up modems, satellite, deep-space communications, and802.11 wireless LANs. It is also commonly used inspeech recognition,speech synthesis,diarization,[1]keyword spotting,computational linguistics, andbioinformatics. For instance, inspeech-to-text (speech recognition), the acoustic signal is the observed sequence, and a string of text is the "hidden cause" of that signal. The Viterbi algorithm finds the most likely string of text given theacoustic signal.
The Viterbi algorithm is named afterAndrew Viterbi, who proposed it in 1967 as a decoding algorithm forconvolutional codes over noisy digital communication links.[2] It has, however, a history ofmultiple invention, with at least seven independent discoveries, including those by Viterbi,Needleman and Wunsch, andWagner and Fischer.[3] It was introduced tonatural language processing as a method ofpart-of-speech tagging as early as 1987.
Viterbi path andViterbi algorithm have become standard terms for the application of dynamic programming algorithms to maximization problems involving probabilities.[3]For example, in statistical parsing a dynamic programming algorithm can be used to discover the single most likely context-free derivation (parse) of a string, which is commonly called the "Viterbi parse".[4][5][6] Another application is intarget tracking, where the track is computed that assigns a maximum likelihood to a sequence of observations.[7]
Given a hidden Markov model with a set of hidden states and a sequence of observations, the Viterbi algorithm finds the most likely sequence of states that could have produced those observations. At each time step, the algorithm solves the subproblem where only the observations up to are considered.
Two matrices of size are constructed:
Let and be the initial and transition probabilities respectively, and let be the probability of observing at state. Then the values of are given by the recurrence relation[8]The formula for is identical for, except that is replaced with, and.The Viterbi path can be found by selecting the maximum of at the final timestep, and following in reverse.
function Viterbi(states, init, trans, emit, obs)isinput states: S hidden statesinput init: initial probabilities of each stateinput trans: S × S transition matrixinput emit: S × O emission matrixinput obs: sequence of T observations prob ← T × S matrix of zeroes prev ← empty T × S matrixforeach state sin statesdo prob[0][s] = init[s] * emit[s][obs[0]]for t = 1to T - 1inclusive do// t = 0 has been dealt with alreadyforeach state sin statesdoforeach state rin statesdo 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 - 2to 0inclusive do path[t] ← prev[t + 1][path[t + 1]]return pathend
The time complexity of the algorithm is. If it is known which state transitions have non-zero probability, an improved bound can be found by iterating over only those which link to in the inner loop. Then usingamortized analysis one can show that the complexity is, where is the number of edges in the graph, i.e. the number of non-zero entries in the transition matrix.
A doctor wishes to determine whether patients are healthy or have a fever. The only information the doctor can obtain is by asking patients how they feel. The patients may report that they either feel normal, dizzy, or cold.
It is believed that the health condition of the patients operates as a discreteMarkov chain. There are two states, "healthy" and "fever", but the doctor cannot observe them directly; they arehidden from the doctor. On each day, the chance that a patient tells the doctor "I feel normal", "I feel cold", or "I feel dizzy", depends only on the patient's health condition on that day.
Theobservations (normal, cold, dizzy) along with thehidden states (healthy, fever) form a hidden Markov model (HMM). From past experience, the probabilities of this model have been estimated as:
init = {"Healthy": 0.6, "Fever": 0.4}trans = { "Healthy": {"Healthy": 0.7, "Fever": 0.3}, "Fever": {"Healthy": 0.4, "Fever": 0.6},}emit = { "Healthy": {"normal": 0.5, "cold": 0.4, "dizzy": 0.1}, "Fever": {"normal": 0.1, "cold": 0.3, "dizzy": 0.6},}In this code,init represents the doctor's belief about how likely the patient is to be healthy initially. Note that the particular probability distribution used here is not the equilibrium one, which would be{'Healthy': 0.57, 'Fever': 0.43} according to the transition probabilities. The transition probabilitiestrans represent the change of health condition in the underlying Markov chain. In this example, a patient who is healthy today has only a 30% chance of having a fever tomorrow. The emission probabilitiesemit represent how likely each possible observation (normal, cold, or dizzy) is, given the underlying condition (healthy or fever). A patient who is healthy has a 50% chance of feeling normal; one who has a fever has a 60% chance of feeling dizzy.

A particular patient visits three days in a row, and reports feeling normal on the first day, cold on the second day, and dizzy on the third day.
Firstly, the probabilities of being healthy or having a fever on the first day are calculated. The probability that a patient will be healthy on the first day and report feeling normal is. Similarly, the probability that a patient will have a fever on the first day and report feeling normal is.
The probabilities for each of the following days can be calculated from the previous day directly. For example, the highest chance of being healthy on the second day and reporting to be cold, following reporting being normal on the first day, is the maximum of and. This suggests it is more likely that the patient was healthy for both of those days, rather than having a fever and recovering.
The rest of the probabilities are summarised in the following table:
| Day | 1 | 2 | 3 |
|---|---|---|---|
| Observation | Normal | Cold | Dizzy |
| Healthy | 0.3 | 0.084 | 0.00588 |
| Fever | 0.04 | 0.027 | 0.01512 |
From the table, it can be seen that the patient most likely had a fever on the third day. Furthermore, there exists a sequence of states ending on "fever", of which the probability of producing the given observations is 0.01512. This sequence is precisely (healthy, healthy, fever), which can be found be tracing back which states were used when calculating the maxima (which happens to be the best guess from each day but will not always be). In other words, given the observed activities, the patient was most likely to have been healthy on the first day and also on the second day (despite feeling cold that day), and only to have contracted a fever on the third day.
The operation of Viterbi's algorithm can be visualized by means of atrellis diagram. The Viterbi path is essentially the shortest path through this trellis.
A generalization of the Viterbi algorithm, termed themax-sum algorithm (ormax-product algorithm) can be used to find the most likely assignment of all or some subset oflatent variables in a large number ofgraphical models, e.g.Bayesian networks,Markov random fields andconditional random fields. The latent variables need, in general, to be connected in a way somewhat similar to ahidden Markov model (HMM), with a limited number of connections between variables and some type of linear structure among the variables. The general algorithm involvesmessage passing and is substantially similar to thebelief propagation algorithm (which is the generalization of theforward-backward algorithm).
With an algorithm callediterative 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 withturbo code.[9] Iterative Viterbi decoding works by iteratively invoking a modified Viterbi algorithm, reestimating the score for a filler until convergence.
An alternative algorithm, theLazy Viterbi algorithm, has been proposed.[10] For many applications of practical interest, under reasonable noise conditions, the lazy decoder (using Lazy Viterbi algorithm) is much faster than the originalViterbi decoder (using Viterbi algorithm). While the original Viterbi algorithm calculates every node in thetrellis of possible outcomes, the Lazy Viterbi algorithm maintains a prioritized list of nodes to evaluate in order, and the number of calculations required is typically fewer (and never more) than the ordinary Viterbi algorithm for the same result. However, it is not so easy[clarification needed] to parallelize in hardware.
This sectiondoes notcite anysources. Please helpimprove this section byadding citations to reliable sources. Unsourced material may be challenged andremoved.(September 2023) (Learn how and when to remove this message) |
Thesoft output Viterbi algorithm (SOVA) is a variant of the classical Viterbi algorithm.
SOVA differs from the classical Viterbi algorithm in that it uses a modified path metric which takes into account thea priori probabilities of the input symbols, and produces asoft output indicating thereliability of the decision.
The first step in the SOVA is the selection of the survivor path, passing through one unique node at each time instant,t. Since each node has 2 branches converging at it (with one branch being chosen to form theSurvivor Path, and the other being discarded), the difference in the branch metrics (orcost) between the chosen and discarded branches indicate theamount of error in the choice.
Thiscost is accumulated over the entire sliding window (usually equalsat least five constraint lengths), to indicate thesoft output measure of reliability of thehard bit decision of the Viterbi algorithm.
{{cite conference}}: CS1 maint: multiple names: authors list (link)