Juliacon 2024

Fast and generic Hidden Markov Models
2024-07-10 , Method (1.5)

HMMs are a very useful statistical framework, but existing implementations often limit user creativity. With Julia, we can have it all: custom probability distributions, arbitrary types, numerical stability, automatic differentiation, exogenous controls... without giving up on performance!
This talk will introduce the package HiddenMarkovModels.jl and its main features, but also share useful lessons about leveraging abstraction in scientific software.


A Hidden Markov Model is composed of a hidden state sequence and a visible observation sequence. The current state only depends on the previous state, and the current observation only depends on the current state. These assumptions give rise to simple and efficient algorithms for tasks like state inference and parameter estimation. As a result, HMMs are popular in many fields ranging from bioinformatics to speech processing or industrial maintenance.

For lack of imagination (or implementations), people often stick to Gaussian HMMs, where each observation follows a normal distribution whose mean depends on the latent state. But if you are willing to think outside the box, you can ask interesting questions:

  • what if I want to write a custom observation distribution?
  • can I use arbitrary number types for increased precision?
  • my transition matrix is sparse, will it break things?
  • how do I compute gradients of the loglikelihood?
  • the dynamics depend on external control variables, is that even allowed?

All of these demands (and more) are met by HiddenMarkovModels.jl, which is the topic of the present talk. We will embark on a tour of the main design ideas, and find that each layer of abstraction unlocks new features without sacrificing speed. The end result is one of the fastest and most flexible HMM packages out there, suitable for a variety of industrial or academic applications.

Package repository: https://github.com/gdalle/HiddenMarkovModels.jl
Documentation and tutorials: https://gdalle.github.io/HiddenMarkovModels.jl/dev/
Presentation slides: https://gdalle.github.io/JuliaCon2024-HMM/
Video: https://www.youtube.com/live/1c4TTosBzzY?feature=shared&t=9672

See also: GitHub

Postdoctoral researcher at EPFL (Switzerland) in the INDY, IdePHICS and SPOC labs.
Currently working on graph machine learning.
Active member of the JuliaGraphs and JuliaDiff organizations.
Personal website: https://gdalle.github.io/

This speaker also appears in: