FLOSS#

FLOSS (Fast Low-cost Online Semantic Segmentation) – online change point detection with the arc curve of the matrix profile.

Description#

FLOSS is the streaming counterpart of FLUSS. It keeps the last sliding_window_size points of a stream and, point by point, the right nearest neighbour of every subsequence of length window_size in that window (the one-directional matrix profile). Each neighbour link is an arc pointing forward in time, and few arcs cross a regime change. The one-directional corrected arc curve (CAC1D) divides the number of arcs that cross each point by the number expected without any regime structure (a beta curve fitted once per window length), clipped to 1; its first and last exclusion_factor * window_size values are set to 1. A change point is reported where the curve drops below threshold.

See Online detectors for the update API and the events it returns.

Type: change point detection, online
Supervision: unsupervised
Scope: univariate and multivariate (mean of the curves of the channels)
Complexity: \(O(d \log d)\) per point and channel, where d is the sliding window size; memory \(O(d)\) per channel

Parameters#

Name

Type

Default

Description

window_size

int

10

Subsequence length L, about one period of the data; also the unit of the exclusion zones.

sliding_window_size

int

10_000

Number of most recent points kept. It must exceed (2 * exclusion_factor + 1) * window_size - 1.

threshold

float

0.45

A change point is reported where the curve is below it (in [0, 1]).

exclusion_factor

int

5

Exclusion zones, in multiples of window_size.

normalize

bool

True

Z-normalized subsequences (False: raw Euclidean distances).

axis

int

0

Time axis of the input.

The exclusion factor 5 between change points is the paper’s; the z-normalized distance is the matrix profile’s default. The paper sets L to about one period (65 points for accelerometer data at 100 Hz) and learns threshold per domain: the mean minus three standard deviations of the curve minimum on training data without regime change (0.089 on arterial blood pressure). The defaults sliding_window_size and threshold are those of the streaming evaluation of FLOSS by Ermshaus et al. (2024), whose FLOSS wrapper uses 0.45 (chosen by mean rank on their training series); window_size=10 is the default of FLUSSDetector.

Usage#

FLOSS needs stumpy (pip install "tsseg[fluss]").

import numpy as np
from tsseg.algorithms import FLOSSDetector

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

det = FLOSSDetector(window_size=20, sliding_window_size=1000)
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"], event["score"])

# batch use: replay of the stream, array([1469, 1570])
FLOSSDetector(window_size=20, sliding_window_size=1000).fit_predict(X)

The stream reports 1469 (detected at 1588) and 1570 (at 1689): the valley of the curve around the change at 1500 is wider than the exclusion zone of 100 points, so a second change point appears just past it (exclusion_factor=10 reports 1466 only). A stream fed with update emits nothing before its window is full. predict treats its input as a finite stream: on a series shorter than sliding_window_size, the extraction runs once on the curve of the whole series. A threshold suited to the sliding window may not suit that curve: with the default window, this series is shorter than 10,000 points and 0.45 reports ten change points, every 100 points from 1168 to 2092, since the curve stays low over the whole square wave, whose nearest neighbours lie one period ahead.

Implementation notes#

  • Wrapper around stumpy.floss (BSD-3-Clause), one stream per channel; the curve of the first window is computed from its right matrix profile with stumpy’s corrected arc curve. Tests check the events against stumpy.floss driven directly. stumpy reseeds the global numpy random state when it fits the idealized arc curve; the detector restores it and caches the curve per window length.

  • Alarm rule (the paper does not specify one): when the window fills, then after each point, the regime extraction of FLUSS runs on the curve of the window below threshold (lowest point, mask from exclusion_factor * window_size points before it to one point less after it, as stumpy and FLUSSDetector, repeat), on the points more than exclusion_factor * window_size points after the last reported change point. This is the rule of the FLOSS wrapper of Ermshaus et al. (2024), except that the wrapper also accepts a later minimum before the last change point when it is far enough from every earlier one, and it reads the curve of the first window with indices shifted by one point; events here are final and their positions increase.

  • A change point is reported as soon as the curve dips below threshold, before the valley is complete, so it may precede the lowest point of the valley. Event scores are the curve value at the change point (lower is stronger). As in FLUSSDetector, the position is the start of the subsequence where the curve is lowest, which tends to precede the change by up to about window_size points.

  • A position is first examined at the edge of the right exclusion zone, where stumpy’s beta curve overestimates the number of arcs expected without regime structure (by about a quarter at 5 * window_size points from the end of a 10,000-point window, measured on white noise): the curve reads low there, which favours early alarms.

  • Inherited from stumpy: the ends of the curve are set to 1 on exclusion_factor * window_size points (the paper: L), and trivial matches are excluded within ceil(window_size / 4) points (the paper: L / 2). Not implemented: the temporal constraint of Gharghabi et al. (2019, Section 3.5); the sliding window already bounds the arcs.

  • Multivariate series use the mean of the curves of the channels, as the multivariate framework of Gharghabi et al. (2019, Section 3.4) and FLUSSDetector(multivariate_strategy="cac_mean"). A change seen by a few channels is diluted by the others; the paper (Section 4.7) averages a few chosen channels rather than all of them: pass only those.

  • Reproduction (tests/reproduction/test_floss_tssb.py): on the 75 TSSB series, with the protocol of Ermshaus et al. (2024), the mean Covering is 0.480; their published FLOSS results score 0.4845. 46 of the 67 series of at most 10,000 points give their change points exactly, and the other 21 do once the one-point index shift of their first window is applied; three of the 8 longer series differ by the append-only rule.

References#

Gharghabi, S., Ding, Y., Yeh, C.-C. M., Kamgar, K., Ulanova, L., and Keogh, E. (2017). Matrix Profile VIII: Domain Agnostic Online Semantic Segmentation at Superhuman Performance Levels. IEEE International Conference on Data Mining (ICDM), 117–126.

Gharghabi, S., Yeh, C.-C. M., Ding, Y., Ding, W., Hibbing, P., LaMunion, S., Kaplan, A., Crouter, S. E., and Keogh, E. (2019). Domain agnostic online semantic segmentation for multi-dimensional time series. Data Mining and Knowledge Discovery, 33(1), 96–130.

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