SubsequenceExtractionTransformer
Extract contiguous subsequences of specified length based on rolling aggregates.
A transformer for the extraction of contiguous subsequences of specified length based on maximal/minimal rolling window aggregates.
Given a sequence \(\\{x_1, x_2, \cdots, x_n \\}\) and subseq_len integer \(k\) such that \(0 < k \leq n\), the transformer’s task is to find index \(i\) satisfying \(1 \leq i \leq i + k - 1 \leq n\) such that for given aggregate_fn \(A: \mathbb{R}^k \longrightarrow \mathbb{R}\):
\(A(x_{i}, \cdots, x_{i+k-1})\) is maximal when
selector = 'max', and\(A(x_{i}, \cdots, x_{i+k-1})\) is minimal when
selector = 'min'.
The maximum sum subarray problem is a special case and can be obtained by setting aggregate_fn = np.sum and selector = 'max'.
Quickstart
from sktime.transformations.subsequence_extraction import SubsequenceExtractionTransformer
estimator = SubsequenceExtractionTransformer(aggregate_fn, subseq_len, kwargs=None, selector='max')Parameters(4)
- aggregate_fncallable of signature np.ndarray -> float
Callable function in
numpyused to aggregate values in contiguous subsequence to a scalar.- subseq_lenint
- Length of the subsequence in.iloc units. Must be less than the lengths of all input series.
- kwargsdict, default: None
- Dictionary of additional keyword arguments to pass to aggregate_fn.
- selector{‘max’, ‘min’}, default: ‘max’
- Function used to decide which subsequence to return from the set of scalars or primitives.
Examples
>>> import numpy as np
>>> from sktime.transformations.subsequence_extraction import (
... SubsequenceExtractionTransformer
... )
>>> from sktime.utils._testing.hierarchical import _make_hierarchical
>>> X = _make_hierarchical (same_cutoff = False)
>>> subseq_extract = SubsequenceExtractionTransformer (
... aggregate_fn = np. sum,
... subseq_len = 3,
... )
>>> subseq_extract. fit (X) SubsequenceExtractionTransformer(
... )
>>> X_transformed = subseq_extract. transform (X)References
Jon Bentley. 1984. Programming pearls: algorithm design techniques. Commun. ACM 27, 9 (Sept. 1984), 865-873. https://doi.org/10.1145/358234.381162