Skip to content

Bayesian Changepoint Detection

Find the points where a time series changes regime, with calibrated posterior probabilities instead of a threshold. Online (Adams & MacKay 2007) and offline (Fearnhead 2006) Bayesian changepoint detection on PyTorch tensors, with conjugate Normal-Gamma and Normal-Wishart likelihoods for univariate and multivariate series.

CI PyPI Docs Python 3.9+ License: MIT

Features

  • 🔭 Online detection: the run-length posterior after every observation (Adams & MacKay 2007), for streams and for measuring how quickly a change would have been noticed
  • 🔍 Offline detection: the exact posterior probability of a changepoint at every position given the whole series (Fearnhead 2006)
  • 🎯 Calibrated outputs: probabilities you can threshold, MAP segment starts, and the single most probable segmentation (viterbi_changepoints)
  • 📐 Conjugate likelihoods: Student-t predictive for univariate data (unknown mean and variance), multivariate-t for vector data (unknown mean and covariance), independent-features and covariance-only variants, Gamma-Poisson for counts, and Normal with known variance for mean changes at a known noise level
  • 🧮 Verified mathematics: closed forms checked against scipy and against exhaustive enumeration of segmentations; every pinned number in the test suite says where it comes from
  • ⚡ Vectorized recursions: both detectors are O(T²) with the inner work on tensors, not Python loops; 1 000 points offline in under 4 s on a laptop CPU
  • 🖥️ Runs where your tensors are: CPU, CUDA or Apple MPS through one device argument, with measured guidance on when an accelerator is not worth it
  • 🪶 One dependency: torch; NumPy, SciPy and Matplotlib are only needed for the tests and examples

Where to go next

  • Installation: pip install bayesian-changepoint, and the older package names.
  • Usage: the online and offline detectors, multivariate data, and a table of the API.
  • Devices: CPU, CUDA and MPS, what has been measured, and memory.
  • API reference: every public function and class, generated from the docstrings.