GLHMM — Gaussian-Linear Hidden Markov Models¶
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¶
Install the toolbox, understand the data format, and train your first model in a few lines of code.
Understand the main parameters — K, covtype, δ, γ, and free energy — before diving into the code.
Worked examples for Gaussian HMMs, GLHMMs, TDE-HMMs, and more.
Stochastic training for datasets that do not fit in memory, and GPU acceleration to speed up training.
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.