Differentiable Algorithm for Marginalising Changepoints

Hyoungjin Lim, Gwonsoo Che, Wonyeol Lee, Hongseok Yang

Abstract

This paper introduces a differentiable, $O(mn)$-time algorithm for marginalising out discrete changepoints in time-series models. By transforming a discrete problem into a continuous, differentiable one, the authors enable the use of powerful gradient-based tools like Hamiltonian Monte Carlo (HMC) and Variational Inference for models that were previously too complex or "jagged" to optimize efficiently.

Introduction: The Challenge of Discrete Changepoints

Many time-series—from stock market shifts to heart rate changes—exhibit "changepoints," where the underlying statistical regime abruptly changes. Modeling these is crucial for accurate forecasting and anomaly detection. However, changepoints present a major technical hurdle: discreteness.

Because changepoints occur at specific integer time steps, one cannot take a gradient with respect to their locations. This prevents researchers from using modern gradient-based machine learning techniques like backpropagation or HMC. To circumvent this, one can "marginalise" (sum out) all possible changepoint locations. However, a naive summation over $m$ changepoints in $n$ time steps has a staggering complexity of $O(n^m)$, making it computationally impossible for anything beyond a few points.

Methods: Efficient Differentiable Marginalisation

The authors propose a new algorithm that performs this marginalisation in just $O(mn)$ time. The core innovation lies in identifying recursive relationships within the marginal likelihood. They define two key quantities:

  1. $L_{k,t}$: The sum of probabilities for all possible configurations of the first $k$ changepoints ending at time $t$.
  2. $R_{k,t}$: A ratio that describes how the probability changes when a segment is shifted by one time step.

By using Dynamic Programming (DP), the algorithm builds up the total marginal likelihood step-by-step. Crucially, because the DP process consists entirely of differentiable arithmetic operations (additions and multiplications), the entire algorithm is compatible with automated differentiation (like PyTorch or TensorFlow). This allows gradients to flow through the marginalisation step to the underlying model parameters or latent variables.

Visualizing the recursive relationships in the Dynamic Programming algorithm for marginalising changepoints.

Experimental Evaluation

The authors evaluated their approach on two types of data:

  • Synthetic Data: Generated from Gaussian distributions with abrupt mean and variance shifts to test the algorithm's speed and accuracy under controlled conditions.
  • Well-log Data: A classic real-world benchmark in changepoint literature consisting of 1,000 measurements of rock density from a probe lowered into a wellbore. This data is notoriously noisy and contains several distinct geological regimes.

Key Results

Computational Speedup

In log-log plots of computation time, the proposed method showed a linear relationship with both $n$ and $m$, whereas the naive approach exploded exponentially. This efficiency makes marginalisation a viable technique for real-time or large-scale applications.

Comparison of computation time per sample between the proposed differentiable method (HMC-ours) and a naive marginalisation approach (HMC-naive).

Sample Quality and Convergence

Compared to non-gradient methods like Interacting Particle MCMC (IPMCMC) and Lightweight Metropolis-Hastings (LMH), the proposed method achieved significantly better Effective Sample Size (ESS) and converged much faster (measured by the Gelman-Rubin $\hat{R}$ statistic). Furthermore, the authors successfully demonstrated that they could learn the parameters of a neural network embedded within a changepoint model by maximizing the Evidence Lower Bound (ELBO) using their differentiable marginalisation.

Discussion and Future Work

Marginalising discrete variables often "smooths" the posterior distribution, making it easier for algorithms like HMC to explore the parameter space without getting stuck in local minima. Interestingly, the authors found that using a higher number of changepoints ($m$) sometimes made the posterior easier to sample, likely because more changepoints lower the "barriers" between different modes in the marginal space.

Limitations: The current algorithm assumes the number of changepoints ($m$) is fixed and known beforehand. Additionally, while $O(mn)$ is efficient in time, storing the DP table for very large $n$ and $m$ could become a memory bottleneck. Future work may explore extending this to non-Markovian models and integrating it into end-to-end deep learning pipelines.

Summary updated

BibTeX
@inproceedings{lim2020differentiable,
  author = {Hyoungjin Lim and Gwonsoo Che and Wonyeol Lee and Hongseok Yang},
  title = {{Differentiable Algorithm for Marginalising Changepoints}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2020},
  doi = {10.1609/aaai.v34i04.5918},
}
Figure