ClaSS#

ClaSS (Classification Score Stream) – online change point detection with a self-supervised classifier.

Description#

ClaSS is the streaming counterpart of ClaSP. It keeps the last sliding_window_size points of a univariate stream and maintains, point by point, the k nearest neighbours of every subsequence of width window_size in that window. Every jump points, it scores each split of the window after the last reported change point with a k-NN classifier (the ClaSP profile, cross-validated with a macro F1 score). The best split is reported as a change point when a rank-sum test on the predicted labels is significant (p-value below 1e-50 by default). The subsequence width is learned with SuSS on the first n_warmup points.

ClaSS is the first online detector of tsseg: see Online detectors for the update API and the events it returns.

Type: change point detection, online
Supervision: unsupervised
Scope: univariate
Complexity: \(O(k\,d)\) per point, where d is the sliding window size; memory \(O(k\,d)\)

Parameters#

Name

Type

Default

Description

sliding_window_size

int

10_000

Number of most recent points kept (d in the paper).

n_warmup

int / None

None

Points on which window_size is learned (None = sliding_window_size; capped at it).

window_size

str / int

"suss"

Subsequence width, or "suss", "fft", "acf" to learn it.

k_neighbours

int

3

Number of nearest neighbours.

distance

str

"znormed_euclidean_distance"

Subsequence distance (z-normalised Euclidean = Pearson correlation).

jump

int

5

A split is searched every jump points.

validation

str

"significance_test"

"significance_test" or "score_threshold".

threshold

str / float

"default"

p-value (default 1e-50) or score threshold (default 0.75).

excl_radius

int

5

Exclusion radius of the profile, in multiples of window_size (larger than k_neighbours); segments stay at least 5 * window_size long.

axis

int

0

Time axis of the input.

sliding_window_size, SuSS, the z-normalised distance, k_neighbours, the macro F1 score and the 1e-50 significance level are the paper’s (Section 4.2); jump and excl_radius come from claspy and the authors’ code.

Usage#

import numpy as np
from tsseg.algorithms import ClaSSDetector

rng = np.random.default_rng(0)
t = np.arange(3000)
X = np.where(t < 1500, np.sin(t / 5), np.sign(np.sin(t / 12)))
X = X + 0.1 * rng.standard_normal(t.size)

det = ClaSSDetector(sliding_window_size=2000)
for start in range(0, X.size, 100):          # a stream, 100 points at a time
    for event in det.update(X[start : start + 100]):
        print(event["position"], event["detection_time"])

ClaSSDetector().fit_predict(X)                # batch use: replay of the stream

A stream fed with update emits nothing before its warm-up is complete (10,000 points by default); change points found in the warm-up points are emitted when it completes. predict treats its input as a finite stream: on a series shorter than the warm-up, window_size is learned on the whole series, which is then segmented, as in the authors’ evaluation.

Implementation notes#

  • Vendored from claspy 0.2.8 (claspy/streaming, BSD-3-Clause), on top of the ClaSP code that tsseg already vendors, with the split rule of the authors’ code: the change point is the profile argmax plus window_size, it is rejected within 5 * window_size of the window edge, and the next segment starts at the reported change point. claspy applies the offset to the reported position only, so it placed a change that had just entered the window early (29 to 111 points in the tests) and started the next segment window_size points before it.

  • Inherited from claspy: the significance test uses all the cross-validated labels of the window (the paper resamples 1,000 of them with replacement, Section 3.3) and splits them at the profile argmax; claspy’s score="accuracy" has no effect, so it is not exposed.

  • Scores of the events are NaN: claspy does not log them.

  • On the 75 TSSB series, the mean Covering is 0.848 (claspy: 0.838); the authors’ code scores 0.807 (their published per-series results). The reproduction test is tests/reproduction/test_class_tssb.py.

Reference#

Ermshaus, A., Schäfer, P., and Leser, U. (2024). Raising the ClaSS of Streaming Time Series Segmentation. Proceedings of the VLDB Endowment, 17(8), 1953–1966. https://doi.org/10.14778/3659437.3659450