alphaFeedback

WorksMathematics

Bagel: A Fast Bayesian Online Changepoint Detection Algorithm for Linear Models via Posterior Merging

AI contributions
Not recorded for this paper
View details
Ancillary data
1 code link
View

Abstract

Bayesian online changepoint detection provides a natural framework for quantifying uncertainty about whether and when a change has occurred. It also enables the use of prior information which can increase detection power. Exact Bayesian inference sequentially updates the posterior of whether and when a change has occurred. We present a unified approach to calculating and updating this posterior for a class of regression models covering standard changepoint scenarios, such as changes in mean and slope, whilst also allowing common structure such as seasonal effects. However, naive implementation has a computational cost that increases linearly over time. We, further, introduce approximate updates that keep this cost constant. These are based on novel ideas of merging changepoint times, and are an alternative to existing pruning approaches. We show that merging enables better approximations of the posterior of when a change occurs. Furthermore, we introduce a novel condition for merging that accounts for both the posterior probability of the changepoint times and the similarity of their corresponding post-change parameters. We show that this is more accurate than conditions that only consider the former. We demonstrate the advantage of our approach on simulated data, and the Azure LLM inference traces.

Introduction

Detecting structural changes in time-series is important across many areas such as climate change [16], environmental science [10], finance [2], bioinformatics [11], medical imaging [27], software reliability (Ke and Huang, 2020) and physics [29], amongst many others. See Li et al. (2026) for a recent review of the area and applications. Whilst traditionally the focus of methods to detect these changepoints has been on offline analysis, there has been increasing interest in online methods for detecting changepoints due to the importance of detecting changes in real-time, from data such as medical monitoring signals [15], telecommunications network data [21], and industrial sensor measurements [32].

Frequentist approaches to online changepoint detection are well established and include approaches based on sequential likelihood ratio tests [18, 17, 22] (Yu et al. 2023) and moving window approaches [13]. However, for some applications there are advantages of using a Bayesian approach. Such methods can incorporate prior information about the type and size of change, and they directly quantify uncertainty in both the presence and location of a change. For offline analysis, Bayesian changepoint methods allow inference for multiple changes and tend to involve Markov Chain Monte Carlo [26, 9, 5, 4]. For a certain class of models, exact calculation and simulation from the posterior is possible [3, 6, 8] through solving a set of recursions.

The latter class of recursive methods can be implemented in an online manner. These apply to models where the likelihood of the data after a change does not depend on the parameters associated with segments before that change. Exact inference has a computational cost that increases linearly with time, so processing the observation at time TT has an O(T)O(T) cost. This cost can be reduced to O(1)O(1) by introducing an appropriate approximation [7, 1].

For online applications, we often only need to detect whether or not there has been a changepoint prior to the current time. This then involves only considering models for the data with no or just one change. In this paper we consider such a setting. We specifically consider models where the data can be written as a unknown signal plus noise, and where a change corresponds to a change in the structure of the signal. It is straightforward to construct a general recursion for calculating the posterior in such a model. Importantly, as we are only allowing at most one change, this recursion can be applied to a wider range of models than those of Fearnhead and Liu [7] and Adams and MacKay [1] as the data after the change can depend on the parameters associated with the pre-change data. This allows us to, for example, detect changes in slope and changes in mean in the presence of seasonal effects.

Solving our recursion exactly leads to a computational cost per iteration that increases linearly with the amount of data. To avoid this we could use the pruning (or resampling) ideas from Fearnhead and Liu [7] and Adams and MacKay [1]: the increasing computational cost comes from having to consider all possible changepoint locations prior to the current time, and pruning involves ignoring some of these possibilities which have lowest probability. We instead propose an alternative, novel approach to reducing the computational cost. This involves merging rather than pruning: we partition the set of possible changepoint locations into a set of consecutive intervals, and then jointly update the posterior probabilities associated with values within an interval. This has the advantage over pruning in that it retains an approximation to the posterior distribution of a change at all time-points, and we show that this leads to a more accurate approximation of the posterior of the change location.

Merging has previously been suggested, for a different class of changepoint models, by Shamp et al. [24], though without the idea of approximating the posterior distribution on the time of a change that motivates our use. Our implementation of how we merge is also different. Merging involves two steps: deciding which two current intervals of changepoint times to merge, and then choosing an approximate posterior for the parameters of the model given a change occurring within the merged interval. The approximation of merging comes from assuming the same posterior for the parameters for each changepoint time in the interval – as the true posteriors will differ for different changepoints. Shamp et al. [24] choose to merge the two intervals with the lowest current posterior probability, and then approximate the posterior for this merged interval based on minimising some distance to the posteriors that were associated with the two intervals that have been merged. We instead use a criterion that aims to minimise the difference between the posteriors on the post-change parameters prior to and after merging. Importantly, we do not just merge intervals based on their current posterior probability, but also on how similar the posteriors associated with each interval are.

The intuition behind our merging criteria is that the future updates of the posterior probabilities associated with each changepoint location depend on the posterior for the post-change parameter given a change at that location. By merging intervals with similar posteriors for the post-change parameter, we ensure that future approximations to the posterior on the changepoint location are more accurate. We demonstrate empirically that this is the case, and that often we can get substantially more accurate results with our merging criteria than if we just merged based on the posterior probabilities associated with a change in each interval. We name our approach Bagel, from BAyesian online chanGEpoint detection for Linear models.

The outline of the paper is as follows. In Section 2, we define the Bayesian real-time changepoint detection problem and introduce our proposed algorithm. Sections 3, and 4 show the performance of our algorithm on simulated data and real datasets. More examples, proofs, and detailed simulation results can be found in Supplement A. Data and reproducible code can be found in Supplement B.

Throughout this paper, all vectors are assumed to be column vectors unless explicitly stated otherwise. We denote by 11:t\mathbf{1}_{1:t} the column vector (1,⋯ ,t)T(1,\cdots,t)^{\mathsf{T}}, 11:t\mathbf{1}_{1:t} and 01:t\mathbf{0}_{1:t} are column vectors of length tt of ones and zeros respectively, and y1:t\mathbf{y}_{1:t} represents the column vector (y1,⋯ ,yt)T(y_1,\cdots,y_t)^{\mathsf{T}}. The probability density function (pdf) of the normal distribution with mean μ\mu and variance σ2\sigma^2 is denoted by N(x;μ,σ2)N(x;\mu,\sigma^2), the pdf of the Student-t distribution with ν\nu degrees of freedom, location ll, and scale ee is denoted by tν(x;l,e)t_\nu(x;l,e), and the pdf of the Inverse-Gamma distribution with shape ν\nu and scale ι\iota is denoted by IG(x;ν,ι)IG(x;\nu,\iota). For a matrix AA, we use Ai:j×k:lA_{i:j\times k:l} to denote the sub-matrix formed by rows ii to jj and columns kk to ll.

Univariate real-time Bayesian changepoint detection

The changepoint problem

The model

Assume an independent data stream y1,y2,…,yty_1,y_2,\ldots,y_t is observed in real-time, we wish to detect the presence, or not, of a changepoint at each time step. More precisely, at a given time tt, we wish to detect whether there has been a change prior to tt under an appropriate model for the data. We will consider a class of linear models that encompasses the standard change-in-mean and change-in-slope problem, as well as more complex models, for example incorporating seasonality.

Let τ\tau be the unknown time of the changepoint, where τ=∞\tau= \infty denotes no change. The observed data yty_t at any time tt is modelled as:

yt=atTβ+bt,τTγ+σϵt.y_t = a_t^{\mathsf{T}}\beta+ b_{t,\tau}^{\mathsf{T}}\gamma+ \sigma\epsilon_t.

Here ata_t and bt,τb_{t,\tau} are known d1d_1 and d2d_2 dimensional vectors, while β\beta and γ\gamma are unknown d1d_1 and d2d_2 dimensional parameters. The term atTβa_t^{\mathsf{T}}\beta gives the mean of the model if there has been no change prior to time tt, while bt,τTγb_{t,\tau}^{\mathsf{T}}\gamma specifies the change in this mean due to a changepoint. To be consistent with this we have bt,τ=01:d2b_{t,\tau} = 0_{1:d_2} if τ≥t\tau\geq t. Finally, ϵt\epsilon_t, is the realisation of a standard Gaussian random variable, and σ>0\sigma> 0 is the standard deviation of the noise in the model.

Consequently, at any time tt, the model for the data up to time tt, y1:ty_{1:t}, can be written as:

y1:t=A1:tβ+B1:t,τγ+σϵ1:t,y_{1:t} = A_{1:t}\beta+ B_{1:t,\tau}\gamma+ \sigma\epsilon_{1:t},

where ϵ1:t\epsilon_{1:t} is a column vector of i.i.d Gaussian N(0,1)N(0,1) realisations, and the ttth rows of matrices A1:tA_{1:t} and B1:t,τB_{1:t,\tau} are atTa_t^{\mathsf{T}} and bt,τTb_{t,\tau}^{\mathsf{T}} respectively. If τ≥t\tau\geq t then B1:t,τB_{1:t,\tau} is the zero matrix. Since τ\tau is unknown, at each time tt we consider tt potential models: one corresponding to no change and others where change occurs at τ=1,2,…,t−1\tau= 1,2,\ldots,t-1. Our task is to determine whether there is significant evidence supporting the presence of a change and to infer the posterior distribution of the location of any change.

The prior for the model parameters

The likelihood of the observation depends on the parameters (β,γ)(\beta,\gamma), if the variance of the observations is known, or (β,γ,σ)(\beta,\gamma,\sigma) otherwise. We take a Bayesian approach and assume a prior for these parameters. Furthermore, to enable efficient calculation of the posterior for the presence and location of a changepoint we will use conjugate priors.

For our model, the conjugate priors are Gaussian for (β,γ)(\beta,\gamma) conditional on σ\sigma, with, if it is unknown, an independent inverse gamma prior for σ\sigma. We will have fixed priors for β\beta (and if unknown, σ\sigma), but we will allow the conditional prior for γ\gamma to potentially depend on both τ\tau and β\beta. Specifically, the joint prior for (β,γ)(\beta,\gamma) given σ\sigma and τ\tau is

β,γ∣σ2,τ∼N(μτ,σ2Στ)\beta,\gamma\mid\sigma^2,\tau\sim N(\mu^\tau,\sigma^2\Sigma^\tau)

with prior mean μτ∈Rd1+d2\mu^\tau\in\mathbb{R}^{d_1+d_2} and prior scaled covariance matrix Στ∈R(d1+d2)×(d1+d2)\Sigma^\tau\in\mathbb{R}^{(d_1+d_2)\times(d_1+d_2)}. The constraint of a fixed prior for β\beta given σ\sigma means that μ1:d1τ\mu^\tau_{1:d_1} and Σ1:d1×1:d1τ\Sigma^\tau_{1:d_1\times1:d_1}, that is the marginal prior mean and variance of β\beta, are constant as we vary τ\tau. If σ\sigma is unknown, the prior is given by:

σ2∼IG(ν,ι).\sigma^2 \sim IG(\nu,\iota).

While it is often possible to use improper priors for β\beta and σ\sigma - the conditional prior for γ\gamma must be proper in order to have a well-defined posterior probability for whether there is a changepoint prior to any given time tt. The choice of the prior for γ\gamma will affect the power of detecting different sizes and types of change.

Here we give three examples to illustrate our model framework (with derivations of the stated priors given in Appendix § 6). In each case we present the priors for the case where the noise variance is known, but extending them to the unknown variance case only requires specifying the inverse Gamma prior for the variance. Through we denote user-chosen constants in the prior mean by μi\mu_i, for i=1,2,…i=1,2,\ldots and in the variance by δi>0\delta_i > 0 for i=1,2,…i=1,2,\ldots.

Example 1 (Change-in-mean model): We first consider the change-in-mean model where d1=d2=1d_1=d_2=1. The model can be written as:

A1:t=11:t,B1:t,τ=[01:τ1τ+1:t]A_{1:t}=1_{1:t}, B_{1:t,\tau} = \begin{bmatrix} 0_{1:\tau}\\ 1_{\tau+1:t} \end{bmatrix}

Here β\beta is the mean before the change and γ\gamma represents the shift in the mean after the changepoint. There are two natural choices for the prior

distribution in this setting: one where the pre-change mean and the change in mean are independent, and another where the pre-change and post-change means are independent and identically distributed.

For the former case we have μ=[μ10]\mu= \begin{bmatrix} \mu_1 \\ 0 \end{bmatrix} and Σ=[δ100δ2]\Sigma= \begin{bmatrix} \delta_1 & 0 \\ 0 & \delta_2 \end{bmatrix}. For the latter case, we have the same prior mean, but the covariance structure changes to Σ=[δ1−δ1−δ12δ1]\Sigma= \begin{bmatrix} \delta_1 & -\delta_1 \\ -\delta_1 & 2\delta_1 \end{bmatrix}.

Example 2 (Change-in-slope models): Next, we consider the change-in-slope where d1=d2=2d_1 = d_2 = 2. The model can be written as:

A1:t=[11:t  1:t],B1:t,τ=[01:τ01:τ1(τ+1):t(τ+1):t]A_{1:t} = [1_{1:t}\ \ 1:t], \quad B_{1:t,\tau} = \begin{bmatrix} 0_{1:\tau} & 0_{1:\tau} \\ 1_{(\tau+1):t} & (\tau+1):t \end{bmatrix}

Here β\beta defines the linear trend before the change, and γ\gamma specifies the shift in the intercept and slope at the changepoint.

There are two natural types of change we can allow in this model, depending on whether or not we require continuity of the trend line at the changepoint, as illustrated in Figure 1. If we wish to detect a continuous change, also known as a change-in-slope ([8]), then a natural model is that the change-in-slope, γ2\gamma_2, has mean 0 and is independent of the pre-change trend. The distribution of γ1\gamma_1 conditional on γ2\gamma_2 is then deterministic due to the continuity constraint. This constraint implies for a change at τ\tau that the trend is continuous at τ\tau: γ1+τγ2=0\gamma_1 + \tau\gamma_2 = 0. This gives a prior for (β,γ)(\beta,\gamma) that has mean and covariance defined by the parameters:

Scatterplots illustrating continuous and discontinuous change in a linear trend model

Figure 1. An example of continuous change (left) and discontinuous change (right) in a linear trend model.

μτ=(μ1,μ2,0,0)T,andΣτ=[δ10000δ20000τ2δ3−τδ300−τδ3δ3].\mu^\tau= (\mu_1,\mu_2,0,0)^\mathsf{T}, \quad\text{and} \quad\Sigma^\tau= \begin{bmatrix} \delta_1 & 0 & 0 & 0 \\ 0 & \delta_2 & 0 & 0 \\ 0 & 0 & \tau^2\delta_3 & -\tau\delta_3 \\ 0 & 0 & -\tau\delta_3 & \delta_3 \end{bmatrix}.

References

  1. [1]Adams, R. P. and MacKay, D. J. (2007). Bayesian online changepoint detection. arXiv preprint arXiv:0710.3742 . 2, 3, 13arxiv.org/abs/0710.3742
  2. [2]Banerjee, S. and Guhathakurta, K. (2020). Change-point analysis in financial networks. Stat 9(1), e269. 2arxiv.org/abs/1911.05952
  3. [3]Barry, D. and Hartigan, J. A. (1993). A Bayesian analysis for change point problems. Journal of the American Statistical Association 88(421), 309–319. 2DOI
  4. [4]Benson, A. and Friel, N. (2018). Adaptive MCMC for multiple changepoint analysis with applications to large datasets. Electronic Journal of Statistics 12(2), 3365 – 3396. 2
  5. [5]Chib, S. (1998). Estimation and comparison of multiple change-point models. Journal of Econometrics 86(2), 221–241. 2DOI
  6. [6]Fearnhead, P. (2006). Exact and efficient Bayesian inference for multiple changepoint problems. Statistics and Computing 16, 203–213. 2DOI
  7. [7]Fearnhead, P. and Liu, Z. (2007). Online inference for multiple changepoint problems. Journal of the Royal Statistical Society Series B: Statistical Methodology 69(4), 589–605. 2, 3DOI
  8. [8]Fearnhead, P. and Liu, Z. (2011). Efficient Bayesian analysis of multiple changepoint models with dependence across segments. Statistics and Computing 21, 217–229. 2, 7, 30
  9. [9]Green, P. J. (1995). Reversible jump Markov chain Monte Carlo computation and Bayesian model determination. Biometrika 82(4), 711–732. 2DOI
  10. [10]Harris, T., Li, B. and Tucker, J. D. (2022). Scalable multiple changepoint detection for functional data sequences. Environmetrics 33(2), e2710. 2arxiv.org/abs/2008.01889
  11. [11]Jewell, S. W., Hocking, T. D., Fearnhead, P. and Witten, D. M. (2020). Fast nonconvex deconvolution of calcium imaging data. Biostatistics 21(4), 709–726. 2
  12. [13]Kirch, C. and Weber, S. (2018). Modified sequential change point procedures based on estimating functions. Electronic Journal of Statistics 12(1), 1579–1613. 2DOI
  13. [15]Li, L. and Li, J. (2023). Online change-point detection in high-dimensional covariance structure with application to dynamic networks. Journal of Machine Learning Research 24(51), 1–44. 2
  14. [16]Lund, R. B., Beaulieu, C., Killick, R., Lu, Q. and Shi, X. (2023). Good practices and common pitfalls in climate time series changepoint techniques: A review. Journal of Climate 36(23), 8041–8057. 2arxiv.org/abs/2212.02674
  15. [17]Page, E. (1955). A test for a change in a parameter occurring at an unknown point. Biometrika 42(3/4), 523–527. 2DOI
  16. [18]Page, E. S. (1954). Continuous inspection schemes. Biometrika 41(1/2), 100–115. 2DOI
  17. [19]Pinsker, M. S. (1964). Information and information stability of random variables and processes. Holden-Day . 17
  18. [20]Polunchenko, A. S. and Tartakovsky, A. G. (2010). On optimality of the shiryaev–roberts procedure for detecting a change in distribution. The Annals of Statistics 38, 3445–3457.DOI
  19. [21]Romano, G., Eckley, I. A. and Fearnhead, P. (2023a). A log-linear non-parametric online changepoint detection algorithm based on functional pruning. IEEE Transactions on Signal Processing 72, 594–606.DOI
  20. [22]Romano, G., Eckley, I. A., Fearnhead, P. and Rigaill, G. (2023b). Fast online changepoint detection via functional pruning cusum statistics. Journal of Machine Learning Research 24, 1–36.
  21. [23]Saatçi, Y., Turner, R. D. and Rasmussen, C. E. (2010). Gaussian process change point models. In: Proceedings of the 27th International Conference on Machine Learning (ICML-10), 927–934.
  22. [24]Shamp, W., Varbanov, R., Chicken, E., Linero, A. and Yang, Y. (2021). Computationally efficient Bayesian sequential function monitoring. Journal of Quality Technology 54(1), 1–19.
  23. [25]Soch, J. and Allefeld, C. (2016). Kullback-Leibler divergence for the normal-gamma distribution. arXiv preprint arXiv:1611.01437 .arxiv.org/abs/1611.01437
  24. [26]Stephens, D. A. (1994). Bayesian retrospective multiple-changepoint identification. Journal of the Royal Statistical Society: Series C (Applied Statistics) 43(1), 159–178.DOI
  25. [27]Stoehr, C., Aston, J. A. and Kirch, C. (2021). Detecting changes in the covariance structure of functional time series with application to fmri data. Econometrics and Statistics 18, 44–62.arxiv.org/abs/1903.00288
  26. [28]Stojkovic, J., Zhang, C., Goiri, Í., Torrellas, J. and Choukse, E. (2025). Dynamollm: Designing llm inference clusters for performance and energy efficiency. In: 2025 IEEE International Symposium on High Performance Computer Architecture (HPCA), IEEE, 1348–1362.DOI
  27. [29]Ward, K., Dillo, G., Eckley, I. and Fearnhead, P. (2023). Poisson-FOCuS: An efficient online method for detecting count bursts with application to gamma ray burst detection. Journal of the American Statistical Association, 1–13.
  28. [30]West, M. and Harrison, J. (2006). Bayesian forecasting and dynamic models. Springer Science & Business Media.
  29. [31]Williams, C. K. and Rasmussen, C. E. (2006). Gaussian processes for machine learning, volume 2. MIT press Cambridge, MA. 17DOI
  30. [32]Yang, Z., Eckley, I. A. and Fearnhead, P. (2026). mixfocus: A communication-efficient online changepoint detection method in distributed system for mixed-type data. Journal of Time Series Analysis 47(3), 701–714. 2DOI

Paper details

vlnc:W_gcvy83s7
v1 · latestHistory (1)

published · Fresh — added to the Hub within the last 30 days

added ·

Usage

views · 9

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

CC BY 4.0

Original source

  • Mathematics

Not recorded for this paper · View statement →

Looking for related papers…
Contents