tsseg.algorithms.changefinder package
ChangeFinder — Online two-stage change-point detection via outlier scoring.
Description
ChangeFinder reduces change-point detection to outlier detection using a pair of sequentially discounting autoregressive (SDAR) models. The algorithm operates in two stages:
Stage 1: An SDAR model is fitted online on the raw signal. Each observation receives an outlier score (logarithmic or quadratic loss), which is smoothed by a causal moving average of width T.
Stage 2: A second SDAR model is fitted on the smoothed scores from Stage 1. A second moving average produces the final change-point score curve. Peaks in this curve are returned as change points.
The SDAR model maintains an AR(k) model with exponential discounting: older observations are progressively down-weighted at rate r, allowing the model to track non-stationary dynamics. AR parameters are updated at each step by re-solving a discounted Toeplitz system.
This online, single-pass design yields \(O(n \cdot k^2)\) time complexity, making ChangeFinder efficient for long time series.
n_cps)Parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int |
|
AR order k for both SDAR stages. |
|
float |
|
Discounting rate r in (0, 1). Smaller values retain longer memory. |
|
int |
|
Moving-average window length T after each SDAR stage. |
|
str |
|
Scoring function: |
|
int / None |
|
Number of change points to return. If |
|
float / None |
|
Minimum score for a peak. If |
|
int |
|
Minimum samples between successive change points. |
|
str |
|
|
|
float |
|
Tolerance for aggregating change points in ensembling mode. |
|
int |
|
Time axis. |
Usage
from tsseg.algorithms import ChangeFinderDetector
detector = ChangeFinderDetector(order=5, discount=0.005, smooth_window=7)
cps = detector.fit_predict(X)
Reference: Takeuchi, J. and Yamanishi, K. (2006), A unifying framework for detecting outliers and change points from time series, IEEE TKDE, vol. 18, no. 4, pp. 482–492.
Submodules
tsseg.algorithms.changefinder.sdar module
SDAR (Sequential Discounting AR) learning algorithm.
- Implements the online discounting AR model from:
Takeuchi & Yamanishi, “A Unifying Framework for Detecting Outliers and Change Points from Time Series”, IEEE TKDE, 2006.
- class tsseg.algorithms.changefinder.sdar.SDAR(order, discount)[source]
Bases:
objectSequential Discounting AutoRegressive model.
Learns an AR(k) model incrementally with exponential discounting so that older observations are gradually forgotten. For each new observation the model produces a predicted mean and variance which can be used to compute an outlier score.
- Parameters:
- log_loss(x_new, x_hat, sigma)[source]
Logarithmic loss (negative log-likelihood under Gaussian).
- Return type:
tsseg.algorithms.changefinder.detector module
ChangeFinder: two-stage outlier-to-change-point detection.
- Implements the ChangeFinder algorithm from:
Takeuchi & Yamanishi, “A Unifying Framework for Detecting Outliers and Change Points from Time Series”, IEEE TKDE, 2006.
- The algorithm operates in two stages:
An SDAR model learns the time series online. Each observation receives an outlier score (log-loss or quadratic loss). A moving average of these scores produces a smoothed score series.
A second SDAR model learns the smoothed score series. A second moving average yields the final change-point score at each time step.
Change points are then selected by peak-picking on the final score curve.
- class tsseg.algorithms.changefinder.detector.ChangeFinderDetector(order=5, discount=0.005, smooth_window=7, score='logarithmic', n_cps=None, threshold=None, min_distance=10, multivariate_strategy='l2', tolerance=0, axis=0)[source]
Bases:
BaseSegmenterChangeFinder change-point detector (Takeuchi & Yamanishi, 2006).
Two-stage online method that reduces change-point detection to outlier detection. An AR model with exponential discounting (SDAR) computes outlier scores; a moving average smooths them; a second SDAR + moving average produces a change-point score curve. Peaks in the curve are returned as change points.
- Parameters:
order (
int) – AR order for both SDAR stages.discount (
float) – Discounting rate r in (0, 1). Controls how quickly the model forgets past observations.smooth_window (
int) – Length T of the moving-average windows applied after each SDAR stage.score (
str) – Scoring function:"logarithmic"(negative log-likelihood) or"quadratic"(squared prediction error).n_cps (
int|None) – Number of change points to return. IfNone, all peaks abovethresholdare returned.threshold (
float|None) – Minimum score for a peak to be accepted as a change point. WhenNone, a data-driven threshold ofmean + 2*stdof the score curve is used.min_distance (
int) – Minimum number of samples between successive change points.multivariate_strategy (
str) – Strategy for multivariate inputs:"l2"reduces to univariate via L2 norm;"ensembling"runs independently per channel and aggregates.tolerance (
int|float) – Tolerance for aggregating change points across channels (ensembling strategy only).axis (
int) – Time axis.
References
- set_fit_request(*, axis: bool | None | str = '$UNCHANGED$') ChangeFinderDetector
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- set_predict_request(*, axis: bool | None | str = '$UNCHANGED$') ChangeFinderDetector
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Module contents
ChangeFinder change-point detection algorithm.