Clustering Sequences with Hidden Markov Models

Padhraic Smyth

Standard clustering algorithms like $k$-means or Gaussian Mixture Models (GMMs) are designed for "feature space"—fixed-length vectors of numbers. However, real-world data often comes in sequences, such as speech signals, protein chains, or time-series data, that vary in length and possess internal temporal dynamics.

This paper by Padhraic Smyth presents a robust probabilistic framework for grouping these variable-length sequences into meaningful clusters using Hidden Markov Models (HMMs). It proposes a "mixture of HMMs" approach, introducing a clever initialization strategy based on pairwise log-likelihoods and demonstrating that Monte-Carlo cross-validation can automatically determine the "true" number of clusters in a dataset.

The Challenge of Sequence Clustering

Two major hurdles exist when trying to cluster sequences:

  1. Distance Metrics: It is not immediately obvious how to define the "distance" between two sequences of different lengths without resorting to computationally heavy or heuristic alignment methods like Dynamic Time Warping.
  2. Initialization: Probabilistic models are typically trained using the Expectation-Maximization (EM) algorithm. EM is notorious for getting stuck in "local optima" if it does not start with a good initial guess, making robust initialization critical.

A Probabilistic Solution: Mixtures of HMMs

The author frames the problem as a Finite Mixture Model, where the data is assumed to be generated by one of $K$ different HMMs. A mixture of $K$ HMMs can be represented as one giant "composite" HMM. The transition matrix of this global model is block-diagonal, meaning the system can move between states within a cluster but cannot "jump" between different clusters once a sequence starts. Viewing a mixture as a single large, constrained HMM allows researchers to use existing, highly optimized HMM training tools (like the Baum-Welch algorithm) without reinventing the wheel.

Log-Likelihood Initialization

To solve the EM initialization problem, the author introduces a four-step "HMM-Clustering" algorithm. The most powerful insight here is that the probability of a sequence being generated by a model is a "natural" way to measure similarity.

  1. Individual Fitting: Fit a small, basic HMM to every single sequence in the dataset.
  2. Distance Matrix: Build an $N \times N$ matrix where the "distance" between sequence $i$ and sequence $j$ is the average log-likelihood of one sequence given the other's model.
Symmetric Log-Likelihood Distance Matrix
  1. Hierarchical Clustering: Use this distance matrix to group sequences into $K$ initial clusters.
  2. Refinement: Use these groups to initialize the parameters of the global mixture model, and then run the standard EM algorithm to fine-tune them.

Model Selection ($K$)

To find the right number of clusters ($K$), the paper uses Monte-Carlo cross-validation. The data is repeatedly split into training and testing sets. The value of $K$ that yields the highest average log-likelihood on the "out-of-sample" test data is chosen as the winner.

Experimental Results

The paper evaluates the method on a synthetic "toy" dataset consisting of 1-dimensional feature data generated by a 2-component HMM mixture ($K=2$). The two clusters have identical marginal statistics (mean and variance) and only differ in their temporal dynamics (how fast they switch between states). There are 40 sequences total, each with a length of 200.

Superior Initialization and Robustness

The paper shows that starting EM with a block-diagonal structure informed by pairwise distances leads to much higher likelihoods and more stable results than standard random or uniform starts.

Initialization Method Performance

In the toy problem, the proposed "HMM-Clustering" initialization achieved a mean log-likelihood of 50.4, compared to 0.0 for an unstructured approach and 8.1 for a basic block-uniform approach. Furthermore, the HMM-Clustering method showed much lower variability (standard deviation of 0.9) across different runs compared to other methods (standard deviation of 28.7), proving it is far less sensitive to random seeds.

Additionally, the cross-validation procedure produced a clear, sharp peak at $K=2$, successfully identifying the true underlying structure of the data.

Limitations and Future Work

While highly effective, the approach has a few limitations:

  • Computational Complexity: The initialization requires training $N$ individual models and calculating $N^2$ distances. For very large datasets (thousands of sequences), this becomes computationally expensive. Random sampling is suggested as a potential fix.
  • Fixed State Count: The paper assumes the number of states ($m$) within each HMM is known beforehand. A more advanced version would need to learn both the number of clusters ($K$) and the internal complexity of each cluster ($m$) simultaneously.
  • Simple Emissions: The experiments focused on 1D Gaussian emissions; further work is needed to see how this scales to high-dimensional, discrete, or non-Gaussian data.

Summary updated

BibTeX
@inproceedings{smyth1996clustering,
  author = {Padhraic Smyth},
  title = {{Clustering Sequences with Hidden Markov Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {1996},
}
Figure