FLUSS#

FLUSS – Fast Low-cost Unipotent Semantic Segmentation.

Description#

FLUSS is a domain-agnostic method for semantic segmentation of time series. It leverages the matrix profile (computed by stumpy) and derives the arc curve: for each time index the number of nearest-neighbour arcs crossing that index is counted. Valleys in the arc curve indicate semantic boundaries because few matching subsequences span across a true regime change.

A sequential peak search on the inverted arc curve yields the requested number of change points, or fewer when the curve left outside the exclusion zones of the first ones is flat. FLUSS has only one parameter – the window size – which corresponds to the dominant period length.

By default, as in the FLUSS paper, the matrix profile compares z-normalized subsequences, that is their shapes: a change in the mean or the scale of the series alone does not show. On three segments of white noise with different means, the nearest neighbour of a window lies in its own segment for a third of the windows only, as by chance, and no change point stands out.

normalize=False compares the raw subsequences (Euclidean distance), so a shift in level shows: on the same series (change points at 300 and 700, default window_size=10), three segments give [293, 692]. The arcs then stay in their segment and the corrected arc curve is low over whole segments, not only at the change points: without n_segments, the default threshold=0.5 returns twelve change points there, threshold=0.1 the two true ones.

On a multivariate series, multivariate_strategy chooses how the channels are combined: "ensembling" (default) runs FLUSS on each channel and votes on their change points, "l2" runs it on the L2 norm of the channels, and "cac_mean" averages the corrected arc curves of the channels, then extracts the change points from that mean curve as from a univariate one. The mean is the multivariate FLUSS of Gharghabi et al. (2019, section 3.4). Each curve is already in [0, 1], so no rescaling is applied; profile holds the mean curve. A change seen by a few channels only is diluted by the others, and threshold keeps its univariate default, not tuned for the mean curve.

Type: change point detection
Supervision: semi-supervised or unsupervised
Scope: univariate (multivariate via ensembling, the L2 norm or the mean corrected arc curve)
Complexity: \(O(d\,n^{2})\): one matrix profile per channel (stumpy.stump)
Requires: stumpy (pip install tsseg[fluss])

Parameters#

Name

Type

Default

Description

window_size

int

10

Sliding window size (use the dominant period length).

n_segments

int / None

2

Number of segments (= change points + 1), at most. None: unknown, change points are the minima of the corrected arc curve below threshold.

exclusion_factor

int

5

Multiplying factor for the exclusion zone around detected points.

multivariate_strategy

str

"ensembling"

Strategy for multivariate inputs: "ensembling" (vote on the change points of the channels), "l2" (L2 norm of the channels) or "cac_mean" (mean of the corrected arc curves of the channels).

tolerance

float

0.01

Ensembling: tolerance for aggregating change points (a float below 1 is a fraction of the series length).

threshold

float

0.5

With n_segments=None: corrected-arc-curve value below which a minimum is a change point (in [0, 1]).

consensus

float

0.0

Ensembling with n_segments=None: detections of the channels within tolerance are merged; a merged change point is returned if at least this fraction of the channels (one at least) detected it.

normalize

bool

True

True: matrix profile of z-normalized subsequences (FLUSS paper). False: raw subsequences, Euclidean distance (shifts in level show).

axis

int

0

Time axis.

Usage#

from tsseg.algorithms import FLUSSDetector

detector = FLUSSDetector(window_size=50, n_segments=4)
change_points = detector.fit_predict(X)

Implementation: Wrapper around stumpy. BSD 3-Clause.

Reference: Gharghabi, Yeh, Ding, Ding, Hibbing, LaMunion, Kaplan, Crouter & Keogh (2017, 2019), Domain Agnostic Online Semantic Segmentation, ICDM / DMKD.

API reference#

FLUSS (Fast Low-cost Unipotent Semantic Segmentation) Segmenter.

class FLUSSDetector(*, window_size=10, n_segments=2, exclusion_factor=5, multivariate_strategy='ensembling', tolerance=0.01, threshold=0.5, consensus=0.0, normalize=True, axis=0)[source]#

Bases: BaseSegmenter

FLUSS (Fast Low-cost Unipotent Semantic Segmentation) Segmenter.

FLUSS [1] is a domain-agnostic semantic segmentation method (FLOSS, from the same paper, is its online variant) that operates on the assumption that a low number of arcs crossing a given index point indicates a high probability of a semantic change. Segments are called regimes in the original paper and stumpy package, but here we use the term segments to be consistent with state detection terminology.

Parameters:
  • window_size (int, default = 10) – Size of window for sliding, based on the period length of the data.

  • n_segments (int or None, default = 2) – The number of segments to search (change points + 1). None: the number is not known, and every minimum of the corrected arc curve below threshold is a change point. With a number, fewer change points come out when the corrected arc curve left after the exclusion zones of the first ones is flat (1 everywhere: no point is crossed by fewer arcs than expected).

  • exclusion_factor (int, default=5) – The multiplying factor for the segment exclusion zone.

  • axis (int) – The time axis of X: 0 if time points are rows.

  • multivariate_strategy (str, default="ensembling") – Strategy for handling multivariate data. "ensembling": FLUSS on each channel, then a vote on the change points of the channels. "l2": FLUSS on the L2 norm of the channels. "cac_mean": the mean of the corrected arc curves of the channels (the multivariate FLUSS of [2]), then one regime extraction on that curve; tolerance and consensus are not used. Univariate series ignore it.

  • tolerance (int or float, default=0.01) – Ensembling strategy only: a change point of a channel is supported by every channel with a change point within tolerance samples; change points are taken by decreasing support, then by closeness of the supporting channels, and one within tolerance of a change point already taken is dropped (at most n_segments - 1 of them). A float below 1 is a fraction of the series length.

  • threshold (float, default=0.5) – Used when n_segments is None: the regime extraction of FLUSS takes the lowest point of the corrected arc curve (CAC, in [0, 1]) and masks its exclusion zone, as long as that point is below threshold (the online variant FLOSS flags a regime change the same way, when the CAC drops below a threshold).

  • consensus (float, default=0.0) – Ensembling with n_segments=None: a change point is returned only if at least consensus of the channels (one at least) support it.

  • normalize (bool, default=True) – True: the matrix profile compares z-normalized subsequences, as in the FLUSS paper, so only the shape of a window counts and a change in mean or scale alone does not show. False: it compares the raw subsequences (Euclidean distance), and a shift in level does show; the corrected arc curve is then low over whole segments, so n_segments=None needs a lower threshold. Passed to stumpy.stump.

Notes

With multivariate_strategy="cac_mean", each channel gets its matrix profile (same window_size and normalize) and its corrected arc curve, of length n - window_size + 1; the curve of the series is their arithmetic mean, without rescaling (each is already in [0, 1], at 1 in the masked margins). Change points are read off it as from a univariate curve: at most n_segments - 1 minima below 1, or the minima below threshold with n_segments=None. profile holds the mean curve and scores its values at the change points. A change seen by a few channels only is diluted by the others; threshold keeps its univariate default, not tuned for the mean curve.

References

Examples

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

>>> from tsseg import load_mocap
>>> from tsseg.algorithms import FLUSSDetector
>>> X, y = load_mocap(trial=0)
>>> fluss = FLUSSDetector(window_size=50, n_segments=7)
>>> fluss.fit_predict(X)
array([ 471, 1689, 1949, 3090, 3255, 3793])
predict_scores(X)[source]#

Return scores in FLUSS’s profile for each annotation.

Parameters:

np.ndarray – 1D time series to be segmented.

Returns:

Scores for sequence X

Return type:

np.ndarray

set_fit_request(*, axis='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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.

Parameters:

axis (Union[bool, None, str]) – Metadata routing for axis parameter in fit.

Returns:

self – The updated object.

Return type:

FLUSSDetector

set_predict_request(*, axis='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the predict method.

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 (see sklearn.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 to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • 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.

Parameters:

axis (Union[bool, None, str]) – Metadata routing for axis parameter in predict.

Returns:

self – The updated object.

Return type:

FLUSSDetector