GLHMM — Gaussian-Linear Hidden Markov Models

GLHMM logo

Documentation Status

GLHMM is a Python toolbox for fitting Hidden Markov Models (HMMs) to time series data, with a focus on neuroscience. It can identify recurring brain states from fMRI, MEG, EEG, or ECoG recordings, and relate those states to behaviour or other variables.


Where to start

Getting Started

Install the toolbox, understand the data format, and train your first model in a few lines of code.

Getting Started
How it works

Understand the main parameters — K, covtype, δ, γ, and free energy — before diving into the code.

How it works
Examples

Worked examples for Gaussian HMMs, GLHMMs, TDE-HMMs, and more.

Tutorial
Large datasets and GPU

Stochastic training for datasets that do not fit in memory, and GPU acceleration to speed up training.

Large datasets and GPU

What can GLHMM do?

  • Identify brain states: find recurring patterns of activity or connectivity that the brain cycles through over time

  • Work with multiple data modalities: fMRI, MEG, EEG, ECoG, and more

  • Relate brain dynamics to behaviour: predict cognitive scores, classify clinical groups, or test for statistical relationships

  • Scale to large datasets: stochastic training processes data file by file without loading everything into memory

  • GUI available: a code-free interface is available at github.com/Nick7900/glhmm_protocols


Citing GLHMM

If you use GLHMM in your research, please cite the toolbox paper:

Vidaurre et al. (2023). GLHMM: A Python toolbox for Generalised Linear Hidden Markov Modelling. Imaging Neuroscience. https://doi.org/10.1162/imag_a_00460

If you use the statistical testing protocols, please also cite:

Larsen, N.Y., Paulsen, L.B., Ahrends, C., Winkler, A.M. & Vidaurre, D. (2026). A comprehensive framework for statistical testing of brain dynamics. Nature Protocols, 21, 3148–3179. https://doi.org/10.1038/s41596-025-01300-2

The protocols and a code-free GUI for the statistical tests are available at github.com/Nick7900/glhmm_protocols.