PaTSS#
PaTSS – Pattern-based Time Series Segmentation.
Warning
Deprecated. PatssDetector will be removed in a future release. It
needs npbad, which is not on PyPI, and it over-segments: on a 54-series
sample of TSB-SEG it predicted 17 times more change points than the ground
truth (median), and scored below a random segmentation on univariate series.
The authors maintain PaTSEmb
(pip install patsemb), which needs a Java runtime.
Description#
PaTSS (Carpentier et al., 2024) describes each time step by the sequential
patterns that occur around it, then clusters these descriptions into states.
For each channel and each window length (the powers of two from word_size
to \(\min(2^{10}, n/2)\) by default):
Pattern mining – the sliding windows are discretised with SAX (
word_sizesymbols,alphabet_sizebins), and thetop_k_patternsmost frequent sequential patterns ofmin_pattern_sizetomax_pattern_sizesymbols are mined (a Java miner run bynpbad).Embedding – each window is described by the relative support of the patterns it contains, and each time step by the average over the windows that cover it. Patterns whose occurrences overlap those of a kept pattern (Jaccard index above
jaccard_similarity_threshold) are dropped, and thenb_largest_variancemost variable patterns of each channel are kept.Segmentation – on the embeddings of all channels and window lengths, k-means is run for each number of states in
n_clusters, and the clustering with the best silhouette score is kept. By default, a logistic regression fitted on its labels then gives the probability of each state at each time step, which lets two states overlap during a gradual transition. The detector returns the most probable state at each time step.
All settings are passed through the config dictionary (see below).
npbad cuts the \(n\) windows with a mask over the whole series. Add
the Java pattern miner, whose cost depends on the patterns found, then
k-means and a silhouette score (quadratic in its sample of at most
\(2000 + 0.1\,(n - 2000)\) points) for each of the 8 candidate numbers of
states. The per-window overhead dominates in practice: about 15 s for 4,000
univariate points, close to linear in \(n\) up to 8,000 pointsParameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
dict / None |
|
Settings for PaTSS, in three sections (table below). |
|
int |
|
Time axis (input assumed |
config holds up to three dictionaries, "pattern_mining",
"pattern_filter" and "segmentation", and an integer "n_jobs".
A missing key takes its default value, also inside a section given in part;
the dictionary passed is not modified. Keys are not checked: a misspelt key
is ignored.
Section |
Key |
Default |
Description |
|---|---|---|---|
|
|
|
Smallest window length, a power of two; |
|
|
Largest window length \(2^{10}\) (and at most \(n/2\)). |
|
|
|
Step between consecutive windows. |
|
|
|
Number of SAX symbols per window. |
|
|
|
Number of SAX bins. |
|
|
|
SAX bins over the whole min-max normalised series ( |
|
|
|
Number of most frequent patterns mined per channel and window length. |
|
|
|
Length range of the patterns, in symbols. |
|
|
|
Constraint on the relative duration of a pattern occurrence. |
|
|
|
Filter the mined patterns by minimum description length. |
|
|
|
|
Range of relative support of the patterns kept. |
|
|
A pattern whose occurrences overlap those of a kept pattern beyond this Jaccard index is dropped. |
|
|
|
Number of patterns kept per channel, the most variable ones. |
|
|
|
Project the embedding onto |
|
|
|
|
|
|
|
Inverse regularisation strength |
|
|
|
Candidate numbers of states; the best silhouette score wins. |
|
(top level) |
|
|
Number of processes for the pattern mining and the clustering. |
Usage#
from tsseg.algorithms import PatssDetector
detector = PatssDetector() # default config
states = detector.fit_predict(X)
# Custom config: missing keys keep their default value
detector = PatssDetector(config={
"pattern_mining": {"word_size": 8, "top_k_patterns": 50},
"segmentation": {"n_clusters": [2, 3, 4]},
})
states = detector.fit_predict(X)
Implementation: Adapted from the original PaTSS code (KU Leuven, MIT licence).
Reference: Carpentier, L., Feremans, L., Meert, W. & Verbeke, M. (2024). Pattern-based Time Series Semantic Segmentation with Gradual State Transitions. Proceedings of the 2024 SIAM International Conference on Data Mining (SDM), 316–324. doi:10.1137/1.9781611978032.36
API reference#
This module provides a wrapper for the PaTSS algorithm to integrate it with the tsseg library’s API, following the aeon BaseSegmenter structure.
- class PatssDetector(config=None, axis=0)[source]#
Bases:
BaseSegmenterA wrapper for the PaTSS (Pattern-based Time Series Segmentation) algorithm, compatible with the aeon framework.
Warning
Deprecated, will be removed in a future release.
PatssDetectorneedsnpbad, which is not on PyPI, and it over-segments: on a 54-series sample of TSB-SEG it predicted 17 times more change points than the ground truth (median). The authors maintain PaTSEmb (ML-KULeuven/PaTSEmb), which needs Java.This implementation uses the original logic from PaTSS_perso.py and adapts it to the BaseSegmenter API.
- Parameters:
config (
dict) – Settings of PaTSS: up to three dictionaries,"pattern_mining","pattern_filter"and"segmentation", and an integer"n_jobs"(keys and defaults: PaTSS page of the documentation). A missing key takes its default value, also inside a section given in part;configitself is not modified. IfNone, every default is used.axis (
int) – The axis of the time series data. Assumes (n_timepoints, n_channels).
- 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.