Decoding Hidden Markov Models Faster Than Viterbi Via Online Matrix-Vector (max, +)-Multiplication

Massimo Cairo, Gabriele Farina, Romeo Rizzi

Abstract

We present a novel algorithm for the maximum a posteriori decoding (MAPD) of time-homogeneous Hidden Markov Models (HMM), improving the worst-case running time of the classical Viterbi algorithm by a logarithmic factor. By reinterpreting the Viterbi algorithm as a repeated computation of online matrix-vector (max, +)-multiplications, we achieve a complexity of $O(mn^2/\log n)$ for an HMM of size $n$ and observation sequence of length $m$. This is the first algorithm for the MAPD problem requiring subquadratic time per observation under standard time-homogeneity assumptions.

Introduction

Hidden Markov Models (HMMs) are fundamental to sequence analysis in fields ranging from bioinformatics to speech recognition. The Maximum A Posteriori Decoding (MAPD) task—finding the most likely sequence of hidden states for a given set of observations—has been dominated by the Viterbi algorithm for nearly five decades. However, Viterbi's $O(mn^2)$ complexity poses a significant bottleneck as model sizes ($n$) grow. This paper introduces a subquadratic approach for time-homogeneous HMMs, where the transition matrix remains constant over time.

Methodology: From Algebra to Geometry

The core innovation lies in viewing Viterbi decoding as an online matrix-vector (max, +)-multiplication problem. In the (max, +) semiring, standard multiplication is replaced by addition, and addition is replaced by the maximum operator. For time-homogeneous HMMs, the transition matrix is fixed, allowing for a polynomial-time preprocessing step.

The authors introduce the Geometric Dominance Faster Viterbi (GDFV) algorithm. The process involves:

  1. Matrix Preprocessing: Leveraging the constant nature of the transition matrix to build efficient data structures.
  2. Geometric Reduction: Mapping the (max, +) multiplication to a "geometric dominance reporting" problem. This involves identifying points in a multi-dimensional space that are dominated by a specific query point.
  3. Recursive Divide-and-Conquer: Solving the resulting geometric problem in subquadratic time.

This approach overcomes the "online" constraint of HMM decoding, where each state probability vector depends on the preceding one, preventing the use of standard batch matrix-matrix multiplication speedups.

Experimental Evaluation

The algorithm was tested using synthetic datasets with matrices and vectors sampled from a uniform distribution $(0, 1]$. These tests measured scaling across various model sizes ($n$) and sequence lengths ($m$).

Key Results

The GDFV algorithm achieves a theoretical complexity of $O(mn^2 / \log n)$. Empirically, the algorithm demonstrates significant speedups over the standard Viterbi implementation.

Speedup ratios for GDFV across different parameters and model sizes.

As shown in Figure 2, the speedup ratio relative to the "Trivial" Viterbi baseline increases as the number of rows ($n$) grows. For specific configurations, the geometric approach can be up to 4-5 times faster than the traditional quadratic approach.

Performance comparison for smaller model sizes.

For smaller models (Figure 5), the algorithm maintains a steady performance advantage, typically performing 1.4 to 1.8 times faster than Viterbi in the most computationally intensive phases.

Discussion and Limitations

While GDFV represents a major theoretical milestone, it introduces a larger memory footprint due to the decision trees generated during preprocessing. This can lead to cache misses in very large models, potentially offsetting some computational gains. Furthermore, the algorithm is specifically designed for time-homogeneous HMMs; time-inhomogeneous models, where transitions vary at each step, cannot currently benefit from this specific preprocessing technique.

Future work may explore more succinct data structures to reduce memory overhead or the implementation of these geometric queries on specialized hardware like FPGAs to further enhance throughput.

Summary updated

BibTeX
@inproceedings{cairo2016decoding,
  author = {Massimo Cairo and Gabriele Farina and Romeo Rizzi},
  title = {{Decoding Hidden Markov Models Faster Than Viterbi Via Online Matrix-Vector (max, +)-Multiplication}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2016},
  url = {https://openreview.net/forum?id=SkEyA1Z_-S},
}
Figure