tsseg.algorithms.bocd package
BOCD (Bayesian Online Change-point Detection) — posterior thresholding.
Description
This offline Bayesian change-point detector integrates out the mean and variance of each segment under a conjugate Normal-Gamma prior, constructs a run-length posterior via dynamic programming, and selects change points by thresholding the posterior probability of a boundary. It extends the classical framework of Fearnhead (2006) and Adams & MacKay (2007) to multivariate time series.
A constant hazard function \(H(\tau) = 1/\lambda\) controls the prior expectation of segment length. Two strategies handle multivariate inputs:
"l2"— reduces channels via L2 norm before inference."ensembling"— runs per-channel inference and aggregates change points.
Parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
float |
|
Expected run length (constant hazard = |
|
float |
|
Prior mean of segment observations. |
|
float |
|
Strength of the prior mean (normal precision). |
|
float |
|
Shape of the inverse-gamma prior over variance. |
|
float |
|
Scale of the inverse-gamma prior over variance. |
|
int |
|
Log-probability truncation threshold for the DP matrix. |
|
float |
|
Minimum posterior probability to accept a change point. |
|
int |
|
Minimum distance (samples) between successive change points. |
|
int / None |
|
Optional upper bound on the number of change points. |
|
str |
|
|
|
float |
|
Tolerance for aggregating change points in ensembling mode. |
|
int |
|
Time axis. |
Usage
from tsseg.algorithms import BOCDDetector
detector = BOCDDetector(hazard_lambda=200, cp_prob_threshold=0.1)
labels = detector.fit_predict(X)
Implementation: Adapted from hildensia/bayesian_changepoint_detection. Apache License 2.0.
Reference: Fearnhead (2006), Statistics and Computing; Adams & MacKay (2007), arXiv.