Abstract
PyHHMM is an open-source Python library designed to address the limitations of standard Hidden Markov Model (HMM) implementations when dealing with real-world, "messy" sequential data. While traditional tools often assume homogeneous data types and complete datasets, PyHHMM natively supports heterogeneous observations (mixed continuous and discrete data), missing value inference, and semi-supervised learning. This paper introduces the library's architecture, its core algorithms, and its unique features aimed at improving model interpretability and robustness in practical applications.
Introduction
Hidden Markov Models (HMMs) are fundamental tools in time-series analysis, widely applied in fields ranging from speech recognition to bioinformatics. However, a significant "reality gap" exists between theoretical HMMs and their application to real-world datasets. Most existing frameworks, such as hmmlearn or pomegranate, typically assume that observation sequences are either entirely continuous (e.g., Gaussian) or entirely discrete (e.g., Multinoulli).
In practice, data is often heterogeneous, comprising a mix of categorical and numerical measurements. Furthermore, real-world data is frequently characterized by missing values and a lack of ground-truth labels, which complicates the training of interpretable models. PyHHMM was developed to bridge this gap by providing a unified framework for Heterogeneous Hidden Markov Models (HHMMs).
The PyHHMM Framework
PyHHMM is built on an object-oriented architecture centered around three primary model classes: DiscreteHMM, GaussianHMM, and the novel HeterogenousHMM. The latter is specifically designed to handle mixed-type data by modifying the joint distribution calculation, allowing hidden states to depend on both continuous and discrete observation sequences simultaneously.
The library implements the standard "big three" HMM algorithms to ensure comprehensive functionality:
- Forward-Backward Algorithm: Used for estimating the probability of observed sequences.
- Viterbi Algorithm: Employed for decoding the most likely sequence of hidden states.
- Baum-Welch Algorithm: An Expectation-Maximization (EM) approach for determining optimal model parameters.
Key Features and Innovations
PyHHMM introduces several functionalities that distinguish it from existing libraries:
Handling Data Heterogeneity
The core innovation of PyHHMM is its ability to model mixed-type data within a single architecture. This allows researchers to leverage the strengths of both continuous and discrete data streams without needing to force one into the format of the other.
Robustness to Missing Data
The library provides native support for missing data. It can train models even when observation sequences are incomplete and can further serve as a preprocessing tool to infer missing values based on the learned model dynamics.
Interpretability through Semi-Supervised Training
A common criticism of HMMs is the "black box" nature of hidden states. PyHHMM addresses this by allowing users to fix specific emission probabilities. This semi-supervised approach enables "guided learning," where hidden states are forced to align with known labels or categories, significantly enhancing model explainability.
Model Selection and Integration
To streamline the research workflow, PyHHMM integrates model selection criteria such as the Akaike Information Criterion (AIC) and the Bayesian Information Criterion (BIC). This reduces the boilerplate code required to determine the optimal number of hidden states. Furthermore, the library is built upon the standard scientific Python stack (numpy, scipy, scikit-learn), ensuring seamless integration into existing data science pipelines.
Conclusion
PyHHMM offers a robust and flexible solution for analyzing complex sequential data. By addressing the challenges of data heterogeneity, missing values, and model interpretability, it provides a valuable tool for both researchers and practitioners. Distributed under the Apache-2.0 License, PyHHMM is a community-driven project available for installation via PyPI. Future work will focus on expanding the range of supported emission distributions and optimizing computational performance.
Availability: PyHHMM can be installed via pip install pyhhmm. The source code is hosted on GitHub at github.com/fmorenopino/HeterogeneousHMM.
Summary updated