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.
stumpy.stump)pip install tsseg[fluss])Parameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int |
|
Sliding window size (use the dominant period length). |
|
int / None |
|
Number of segments (= change points + 1), at most. |
|
int |
|
Multiplying factor for the exclusion zone around detected points. |
|
str |
|
Strategy for multivariate inputs: |
|
float |
|
Ensembling: tolerance for aggregating change points (a float below 1 is a fraction of the series length). |
|
float |
|
With |
|
float |
|
Ensembling with |
|
bool |
|
|
|
int |
|
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:
BaseSegmenterFLUSS (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 belowthresholdis 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 ofX:0if 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;toleranceandconsensusare 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
tolerancesamples; change points are taken by decreasing support, then by closeness of the supporting channels, and one withintoleranceof a change point already taken is dropped (at mostn_segments - 1of them). A float below 1 is a fraction of the series length.threshold (float, default=0.5) – Used when
n_segmentsisNone: 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 belowthreshold(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 leastconsensusof 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, son_segments=Noneneeds a lowerthreshold. Passed tostumpy.stump.
Notes
With
multivariate_strategy="cac_mean", each channel gets its matrix profile (samewindow_sizeandnormalize) and its corrected arc curve, of lengthn - 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 mostn_segments - 1minima below 1, or the minima belowthresholdwithn_segments=None.profileholds the mean curve andscoresits values at the change points. A change seen by a few channels only is diluted by the others;thresholdkeeps 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
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.