Viterbi Algorithm

A dynamic programming algorithm that finds the most likely sequence of hidden states in a Markov model by efficiently computing the optimal path through a trellis structure.

Viterbi Algorithm

The Viterbi algorithm, developed by Andrew Viterbi in 1967, is a fundamental technique in dynamic programming that efficiently determines the most probable sequence of hidden states in a Hidden Markov Model system.

Core Principles

The algorithm operates on two key assumptions:

  1. The Markov property - each state depends only on the previous state
  2. Time-invariant transitions - state transition probabilities remain constant

Algorithm Structure

The Viterbi algorithm builds a trellis structure representing:

  • States at each time step
  • Transition probabilities between states
  • Observation probabilities for each state

Key Components

  1. State Probabilities (δ)

    • Tracks the probability of the most likely path
    • Updated recursively for each time step
  2. Backpointers (ψ)

    • Store the previous state in the optimal path
    • Enable path reconstruction through backtracking

Applications

The algorithm finds widespread use in:

Implementation

def viterbi(observations, states, start_prob, trans_prob, emit_prob):
    V = [{}]  # Viterbi matrix
    path = {}
    
    # Initialize
    for state in states:
        V[0][state] = start_prob[state] * emit_prob[state][observations[0]]
        path[state] = [state]

Computational Complexity

The algorithm achieves efficiency through:

  • Time complexity: O(TN²)
  • Space complexity: O(TN)

Where:

  • T = sequence length
  • N = number of states

Historical Impact

The Viterbi algorithm revolutionized digital communication systems and continues to influence modern technologies including:

Limitations and Extensions

While powerful, the algorithm has some constraints:

  • Assumes discrete state spaces
  • Requires known transition probabilities
  • Memory intensive for long sequences

Recent extensions include:

The Viterbi algorithm remains a cornerstone of sequence analysis and probabilistic inference, bridging classical dynamic programming with modern applications in machine learning and signal processing.