BOCPD cheat sheet
BOCPD · Keep the key ideas within reach.
Bayesian Change Point Model Fundamentals
Bayes' rule for a run length r_t: P(r_t | x_1:t) ∝ P(x_t | r_t, x_1:t-1) · P(r_t | r_t-1) · P(r_t-1 | x_1:t-1).
Two run-length transitions only: growth r_t = r_t-1 + 1 with prior 1 - H, and reset r_t = 0 with prior H (the hazard rate).
Hazard H = 1/λ where λ is the expected run length between change points under a geometric prior; constant H gives a memoryless change-point prior.
Predictive under the growth case uses the posterior predictive of the current segment: p(x_t | r_t-1, x_1:t-1) from the conjugate model.
Predictive under the reset case uses the prior predictive of a fresh segment, independent of past data.
Run-length posterior is a vector over r = 0..t; its length grows by one each step, so naive updates cost O(t) per step and O(t^2) total.
Point estimate of the current change point = argmax_r P(r_t = r | x_1:t); the MAP run length gives the most recent change location.
Change-point probability at time t equals the posterior mass at r_t = 0, i.e. P(r_t = 0 | x_1:t).
Conjugate Models and Predictive Distributions
Normal known-variance model: posterior precision = prior precision + n/σ²; posterior mean is a precision-weighted average of prior mean and sample mean.
Normal unknown mean and variance uses Normal-Inverse-Gamma prior; marginal predictive for x is a Student-t with 2α degrees of freedom, location μ, scale sqrt(β(κ+1)/(ακ)).
Bernoulli/Beta: posterior Beta(α + successes, β + failures); posterior predictive P(x=1) = (α + s)/(α + β + n).
Categorical/Dirichlet: posterior Dirichlet(α + counts); predictive probability of category k is (α_k + n_k)/(Σα + n).
Poisson/Gamma: posterior Gamma(α + Σx_i, β + n); predictive is negative binomial with success probability β/(β+1).
Exponential/Gamma with rate λ: posterior Gamma(α + n, β + Σx_i); predictive is Lomax (Pareto type II).
Sufficient statistics let each run-length hypothesis be updated incrementally: store (n, sum, sum of squares) or counts rather than full history.
Predictive log-likelihoods should be computed in log space and normalized with log-sum-exp to avoid underflow as run lengths grow.
Inference, Algorithms, and Implementation
Recursive message-passing: joint over (r_t-1, r_t) has at most 2t nonzero entries, so one update is O(t) and full filtering O(t²).
Pruning: drop run-length hypotheses whose normalized posterior falls below a threshold (e.g. 1e-4) and renormalize; keeps cost near O(t·W).
Resampling/particle approximations for BOCPD keep a weighted set of run lengths; rejuvenate particles to limit degeneracy.
Viterbi-style max-product over the run-length lattice yields the joint MAP segmentation rather than per-step marginals.
Offline smoothing (forward-backward over run lengths) gives P(r_t | x_1:T), which differs from the filtered P(r_t | x_1:t).
Hazard H controls sensitivity: larger H yields more detected change points and shorter average segments; smaller H is more conservative.
Model evidence (marginal likelihood) can be accumulated per step and used to compare hazard values or component models.
Numerical stability: work with log posteriors, subtract the max before exponentiating, and renormalize after every update.
Diagnostics, Evaluation, and Applications
Detection delay after a true change at τ is the first t > τ where P(r_t = 0 | x_1:t) exceeds a decision threshold.
False-alarm rate is controlled by the threshold on change-point probability or by the hazard prior; report both delay and false alarms.
Segment-level evaluation uses precision/recall over detected change locations with a tolerance window (e.g. ±k observations).
Run-length posterior entropy or its concentration measures segmentation confidence; flat posteriors indicate ambiguity.
BOCPD is online and causal: it uses only x_1:t, unlike offline segmentation methods (e.g. optimal partitioning, binary segmentation).
Assumption check: constant hazard implies geometric segment lengths; heavy-tailed or trended data may need a time-varying hazard or detrending.
Common applications: sensor fault detection, network traffic anomaly detection, speech/music segmentation, and econometric regime shifts.
Retrospective diagnostics: plot run-length posterior heatmaps and check that detected change points align with known events or residuals.