SST#
Change-point detection by singular spectrum transformation.
Description#
The singular spectrum transformation (SST) compares the local dynamics of the
series before and after each time point. The lagged vectors
\(s(j) = (x_{j - N + 1}, \dots, x_j)\) of length \(N\)
(window_size) form the past Hankel matrix
\(H_1(t) = [s(t - N), \dots, s(t - 1)]\) and the future one
\(H_2(t) = H_1(t + \gamma)\), \(\gamma\) points later (lag). The
\(r\) leading left singular vectors \(u_1(t), \dots, u_r(t)\) of
\(H_1(t)\) (rank) span the dominant subspace of the past, a linear
model of its dynamics; \(\mu(t)\), the leading one of \(H_2(t)\), is
the main direction of the future. The score
is the squared distance between \(\mu(t)\) and the past subspace (Idé & Tsuda, 2007). It rises when the shape of the signal changes (frequency or form of an oscillation) and, after the preprocessing below, at level shifts; changes of the variance or of the autocorrelation of noise are found late or not at all. Every channel is first brought to unit variance and mean 3, as in the papers: the SVD is not invariant to translation, and the positive offset makes the leading singular value non-degenerate. A multivariate series puts the Hankel matrices of its channels side by side (one shared subspace, as multivariate SSA does with Page matrices).
By default the singular vectors come from the randomised SVD of Weber & Lenz
(2025), which multiplies the Hankel matrices by FFT instead of forming them:
\(O(q (k + p) N \log N)\) per time point instead of \(O(N^3)\) for a
full SVD (method="exact"), for a score error that the paper bounds and
measures (0.036 on average on its synthetic series, without the preprocessing
above, which makes the error much smaller).
The papers give the score only. Change points are the n_cps highest peaks
of the score at least min_distance points apart; there is no
unsupervised mode, and n_cps is required. A peak at \(t\) is reported
as a change at \(t\), the first point after the past matrix; the score
peaks within a few tens of points of a level shift, up to about \(N\) points after
a frequency change, and several \(N\) after a change of the variance of
white noise. The score is 0 where the two
matrices do not fit (the first \(2N - 1\) points and the last
\(\gamma - 1\)) and is kept in the scores_ attribute after
predict.
The defaults of window_size, rank and min_distance are tsseg’s
calibration: in guided mode on the eight change-point datasets of TSB-SEG,
the grid window_size in {25, 50, 100, 200}, rank in {1, 3, 5},
min_distance in {N, 2N} is best at (200, 3, 2N), with a mean
bidirectional covering of 0.629 against 0.557 for (50, 5, N).
n_cps)"fft_rsvd"), \(O(T d N^3)\)
("exact"); about 15 s for 20,000 points with the defaultsParameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int |
|
Window \(N\): length of the lagged vectors and number of columns of each Hankel matrix. A score needs \(2N - 1 + \gamma\) points, and no change point is reported in the first \(2N - 1\). The papers fix no value (Idé & Tsuda use 50); 200 is tsseg’s calibration. Lower it for short series or segments. |
|
int / None |
|
Lag \(\gamma\) between the past and future matrices; |
|
int |
|
Dimension \(r < N\) of the past subspace (Idé & Tsuda recommend 3 or 4; Weber & Lenz use 5; 3 is also tsseg’s calibration). |
|
int |
|
Oversampling \(p\) of the randomised SVD (Weber & Lenz). |
|
int |
|
Subspace iterations \(q\) of the randomised SVD (Weber & Lenz). |
|
str |
|
|
|
int / None |
|
Number of change points (required). |
|
int / None |
|
Minimum distance between change points; |
|
int / None |
|
Seed of the randomised SVD. |
|
int |
|
Time axis. |
Usage#
from tsseg.algorithms import SSTDetector
detector = SSTDetector(n_cps=3, random_state=0)
cps = detector.fit_predict(X)
score = detector.scores_
Implementation: written for tsseg from the papers, without third-party code. On synthetic signals of the four kinds of Weber & Lenz, scored raw as in the paper, the mean absolute error of the randomised SVD against the full SVD stays below the paper’s figure (reproduction test).
Reference: Idé & Tsuda (2007), Change-point detection using Krylov subspace learning, SDM; Idé & Inoue (2005), Knowledge discovery from heterogeneous dynamic systems using change-point correlations, SDM; Weber & Lenz (2025), Accelerating singular spectrum transformation for scalable change point detection, IEEE Access 13.
API reference#
Singular spectrum transformation (SST) change-point detector.
- class SSTDetector(*, window_size=200, lag=None, rank=3, oversampling=10, n_iter=3, method='fft_rsvd', n_cps=None, min_distance=None, random_state=None, axis=0)[source]#
Bases:
BaseSegmenterChange-point detection by singular spectrum transformation (SST).
At every time \(t\), the past Hankel matrix \(H_1(t) = [s(t - N), \dots, s(t - 1)]\), whose columns are the lagged vectors \(s(j) = (x_{j - N + 1}, \dots, x_j)\), is compared with the future one \(H_2(t) = H_1(t + \gamma)\). Their dominant left singular subspaces describe the local linear dynamics of the series; the score
\[z(t) = 1 - \sum_{i=1}^{r} \left(u_i(t)^\top \mu(t)\right)^2 \in [0, 1]\]is the squared distance between the leading future direction \(\mu(t)\) and the span of the \(r\) leading past ones \(u_1(t), \dots, u_r(t)\) [2]. It rises when the shape of the signal changes (frequency or form of an oscillation) and, after the preprocessing (see Notes), at level shifts; changes of the variance or of the autocorrelation of noise are found late or not at all. Change points are the
n_cpshighest peaks of the score at leastmin_distancepoints apart.By default the singular vectors come from the randomised SVD with FFT-based Hankel products of [3] (“FFT rSVD SST”), which costs \(O(q (k + p) N \log N)\) per time point instead of \(O(N^3)\).
- Parameters:
window_size (
int) – Window \(N\): length of the lagged vectors and number of columns of each Hankel matrix (Idé & Tsuda’s \(n = w\), Sec. 2 of [2]). A score needs2 * window_size - 1 + lagpoints, which is also the minimum series length, and no change point is reported in the first2 * window_size - 1points. The papers fix no value ([2] uses 50, [3] 100 to 5,000); 200 is tsseg’s calibration (see Notes). Lower it for short series or segments.lag (
int|None) – Lag \(\gamma\) between the past and future matrices;Nonemeanswindow_size // 2, the default of [2] (Sec. 2).rank (
int) – Dimension \(r < N\) of the past subspace: [2] recommends 3 or 4 (Sec. 2) and uses 3 in its experiments (Sec. 5); [3] uses \(k = 5\) (Sec. IV-E). 3 is also tsseg’s calibration.oversampling (
int) – Oversampling \(p\) of the randomised SVD (\(p = 10\), \(k + p = 15\) in [3], Sec. IV-E). Unused bymethod="exact".n_iter (
int) – Subspace iterations \(q\) of the randomised SVD (about \(\log N\) in [3], Sec. IV-E). Unused bymethod="exact".method (
str) –"fft_rsvd": randomised SVD with FFT Hankel products, the variant that [3] recommends (Sec. V-A);"exact": full SVD of every Hankel matrix, the reference of [3] (cubic inwindow_size).n_cps (
int|None) – Number of change points to return: then_cpshighest peaks of the score, or fewer if it has fewer peaks. Required: the papers give no rule to choose the change points without it, andNoneraises aValueErrorinpredict.min_distance (
int|None) – Minimum number of points between two change points: of two peaks closer than that, the higher one is kept.Nonemeans2 * window_size(tsseg’s calibration).random_state (
int|None) – Seed of the Gaussian test matrix of the randomised SVD.Nonedraws a new one at everypredict(the score then varies by the approximation error, see Notes).axis (
int) – Time axis.
- scores_#
Score of the last series passed to
predict;0where the two Hankel matrices do not fit in the series (the first2 * window_size - 1points and the lastlag - 1).- Type:
np.ndarray of shape (n_timepoints,)
Notes
Reimplemented from the papers, without third-party code.
Geometry, score and its time index follow Idé & Tsuda [2] (Sec. 2, Eq. 2.3): \(z(t)\) is placed at the first point after the past matrix, which is the change point reported for a peak at \(t\). Weber & Lenz [3] (Alg. 1) compute the same score with \(\delta = \gamma\) but place it at the last point of the future matrix, about \(\gamma\) points later. Idé & Inoue [1] (Sec. 3.1) also normalise the score series to unit area; not done here (same peaks). No paper says where a change lies relative to the peak. Measured (tsseg): a level shift peaks within a few to a few tens of points of the change, a frequency change up to about \(N\) points after it, a change of the variance of white noise several \(N\) after it.
Every channel is first brought to unit variance and mean 3 ([2], Sec. 5.1 and footnote 2: positive values make the leading singular value non-degenerate; [1], Sec. 4.2: the SVD is not invariant to translation). Without the offset the score of white noise is erratic (tsseg’s measurement).
Multivariate series (tsseg’s choice, as the SST papers are univariate): the Hankel matrices of the channels are concatenated column-wise, \(H = [H^{(1)}, \dots, H^{(d)}] \in \mathbb{R}^{N \times dN}\), so that all channels share one subspace, as multivariate SSA stacks the Page matrices of the channels (Alanqary, Alomar & Shah [4], Sec. 2, Eq. 4; Hankel variant in its footnote 1; multilevel Hankel matrices are also suggested in [3], Sec. V-A).
Randomised SVD: one Gaussian test matrix with
rank + oversamplingcolumns is drawn perpredictand used for every time point; the leading future direction is taken from the same decomposition (rankrank) as the past subspace of the matrix \(\gamma\) points earlier, which is at least as accurate as the rank-1 decomposition of [3]. QR orthonormalisation is used at every subspace iteration ([3] uses LU in the intermediate ones, for speed only: same subspace in exact arithmetic). [3] reports a mean absolute score error of 0.036 against the exact SST on its synthetic series (Table 4), without the preprocessing above; with it, the error is much smaller (the constant offset widens the gap between the leading singular values).Selection: the papers give the score only. In guided mode, the
n_cpshighest peaks are kept (tsseg’s choice); there is no unsupervised mode. At the ends of the series, where the matrices do not fit, the score is 0 ([2] uses periodic boundaries instead), and the first or last valid point can be a peak.Defaults (tsseg’s calibration, 2026-11-04): guided mode on the eight change-point datasets of TSB-SEG (mean over datasets of the mean bidirectional covering), grid
window_sizein {25, 50, 100, 200},rankin {1, 3, 5},min_distancein {N, 2N}: (200, 3, 2N) is best, 0.629 against 0.557 for (50, 5, N); the largest window of the grid wins, so longer windows were not tried.
The cost is \(O(T \cdot q (k + p) d N \log N)\) for a series of \(T\) points and \(d\) channels with
"fft_rsvd", and \(O(T d N^3)\) with"exact": about 15 s for 20,000 points with the defaults.References
Examples
>>> import numpy as np >>> from tsseg.algorithms import SSTDetector >>> t = np.arange(1000) >>> X = np.where(t < 500, np.sin(2 * np.pi * t / 40), np.sin(2 * np.pi * t / 10)) >>> SSTDetector(n_cps=1, random_state=0).fit_predict(X) array([...])
- set_fit_request(*, axis='$UNCHANGED$')#
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='$UNCHANGED$')#
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.