Skip to content

Introduction

glmhmmt is a Python package that implements a Softmax Generalised Linear Model Hidden Markov Model (GLM-HMM) on top of Dynamax — Google DeepMind’s JAX-based library for probabilistic state space models.

It was developed as part of a Master’s thesis (TFM, MAMME) in collaboration with IDIBAPS to analyse decision-making strategies in cognitive neuroscience experiments.

In behavioural neuroscience, subjects (humans or animals) perform repeated decision tasks across many sessions. A key question is:

Does the subject’s decision strategy change over time, and how many latent strategies are being used?

A Hidden Markov Model captures this naturally — discrete hidden states represent latent strategies, and the model infers when and how often each strategy is active.

The GLM emission connects observable covariates (stimulus contrast, previous choice, reward history…) to the probability of each observable choice, making the emission model interpretable.

FeatureDynamax baseglmhmmt
JAX/JIT acceleration
GLM-HMM model classPartialSoftmaxGLMHMM with softmax emissions
Per-subject session-aware EM
Feature engineering helpersbuild_sequence_from_df
Postprocessing utilitiesbuild_trial_df, build_emission_weights_df
Rich diagnostic plotsFull plots.py module
glmhmmt/
├── model.py # SoftmaxGLMHMM — core model class
├── features.py # build_sequence_from_df — raw data → tensors
├── postprocess.py # build_trial_df, build_emission_weights_df, …
├── views.py # SubjectFitView, build_views — fit result containers
└── plots.py # Matplotlib diagnostic figures