TIRE#

TIRE – Time-Invariant Representation for change point detection.

Description#

TIRE learns a compact representation by training ensembles of parallel autoencoders in both the time domain (TD) and frequency domain (FD). The shared latent dimensions across autoencoders capture the time-invariant signal statistics while the private dimensions capture time-varying noise. A dissimilarity curve is computed from the shared representations and peaks in this curve indicate change points: the n_segments - 1 most prominent ones when n_segments is given, otherwise every peak whose prominence, relative to the highest one, reaches prominence_threshold.

Each channel is rescaled to \([-1, 1]\) on the whole series before the windows are cut (a constant channel is set to 0; a constant series has no change point). The frequency domain input of a window is the modulus of the discrete Fourier transform of each channel, rescaled channel by channel and concatenated. The shared features are smoothed by a triangular moving average in every domain before the dissimilarity is computed.

By tuning the loss weights and latent dimensions for each domain you can control whether the detector focuses on amplitude changes (TD) or spectral changes (FD) or both.

With stride > 1, the comparison lag and both triangular filter half-widths are ceil(window_size / stride) window rows. The compared windows are adjacent when the stride divides the window size; otherwise their gap is less than one stride. Scores are placed halfway between the end of the first window and the start of the second, including fractional centers, then interpolated onto time point indices. These time scales no longer grow by a factor of stride. Strided training still differs from training every window; no equivalence of the learned features is implied.

Type: change point detection
Supervision: unsupervised or semi-supervised
Scope: univariate and multivariate
Complexity: \(O(d\,n\,\ell)\) per training epoch, where \(\ell\) is window_size
Requires: PyTorch

Parameters#

Name

Type

Default

Description

window_size

int

20

Sliding window size (>= 4).

stride

int

1

Stride between consecutive windows (at most window_size).

domain

str

"both"

Domain(s) for representation learning ("TD", "FD", "both").

intermediate_dim_td

int

0

Hidden dim of TD autoencoder (0 = skip intermediate layer).

latent_dim_td

int

1

Latent dim of TD autoencoder.

nr_shared_td

int

1

Number of shared latent dims (TD).

nr_ae_td

int

3

Number of parallel TD autoencoders.

loss_weight_td

float

1.0

Loss weight for TD component.

intermediate_dim_fd

int

10

Hidden dim of FD autoencoder.

latent_dim_fd

int

1

Latent dim of FD autoencoder.

nr_shared_fd

int

1

Number of shared latent dims (FD).

nr_ae_fd

int

3

Number of parallel FD autoencoders.

loss_weight_fd

float

1.0

Loss weight for FD component.

nfft

int

30

DFT size of the window of each channel (longer windows are cut).

norm_mode

str

"timeseries"

Mean removed before the DFT, per channel: of each window ("window") or of the series ("timeseries").

peak_distance_fraction

float

0.0

Minimum distance between two change points, as a fraction of the series length (0: no constraint).

prominence_threshold

float

0.5

Minimum prominence of a peak, relative to the highest one, when n_segments is None.

max_epochs

int

20

Maximum training epochs.

patience

int

5

Early-stopping patience.

learning_rate

float

1e-3

Optimiser learning rate.

n_segments

int / None

None

Number of segments (overrides peak detection).

axis

int

0

Time axis.

random_state

int / None

None

Random seed.

Usage#

from tsseg.algorithms import TireDetector

detector = TireDetector(window_size=30, domain="both", n_segments=5)
change_points = detector.fit_predict(X)

Implementation: PyTorch reimplementation of the authors’ TensorFlow/Keras code (deryckt/TIRE): the parallel autoencoders and their training follow TIRE.py, and the helpers of tsseg.algorithms.tire.utils are copied from its utils.py. No licence found in the original repository. The original code returns a change score per time step; picking change points from it (n_segments, prominence_threshold) is specific to tsseg. On multivariate series tsseg follows the paper where the original code does not: it transforms the window of each channel (eq. 3) instead of the concatenated windows cut to nfft points, and it rescales each channel (§III-B) instead of leaving this to the caller. Origin: reimplemented from the original code.

Reference: De Ryck, De Vos & Bertrand (2021), Change Point Detection in Time Series Data Using Autoencoders with a Time-Invariant Representation, IEEE Transactions on Signal Processing, doi:10.1109/TSP.2021.3087031 (arXiv:2008.09524).

API reference#

class TireDetector(*, window_size=20, stride=1, domain='both', intermediate_dim_td=0, latent_dim_td=1, nr_shared_td=1, nr_ae_td=3, loss_weight_td=1.0, intermediate_dim_fd=10, latent_dim_fd=1, nr_shared_fd=1, nr_ae_fd=3, loss_weight_fd=1.0, nfft=30, norm_mode='timeseries', peak_distance_fraction=0.0, max_epochs=20, patience=5, learning_rate=0.001, n_segments=None, prominence_threshold=0.5, random_state=None, axis=0)[source]#

Bases: BaseSegmenter

TIRE (Time-Invariant Representation) change point detector.

Each channel is first rescaled to [-1, 1] on the whole series given to predict (a constant channel is set to 0). Autoencoders learn the representation of sliding windows in the time domain and, from the modulus of the discrete Fourier transform of the window of each channel, in the frequency domain; their shared features are smoothed by a triangular moving average. The change score of every time step is the prominence of the dissimilarity between consecutive learned representations, relative to the highest one. With n_segments the n_segments - 1 most prominent peaks are returned; otherwise every peak whose relative prominence reaches prominence_threshold. Two returned peaks are at least peak_distance_fraction of the series length apart (0: no constraint).

Parameters:
  • window_size (int) – Length of the sliding windows (at least 4, below the series length); also the target time scale for comparison and for the half-width of the triangular representation and dissimilarity filters.

  • stride (int) – Step between consecutive windows, at most window_size. The comparison lag and both filter half-widths are ceil(window_size / stride) window rows. Compared windows are adjacent when stride divides window_size; otherwise their gap is smaller than one stride. Scores are placed midway between the end of the first window and the start of the second, retaining fractional centers for interpolation onto time point indices.

  • domain (Literal['TD', 'FD', 'both']) – Representations learned in the time domain ("TD"), the frequency domain ("FD") or both, concatenated with weights that equalise the 95th percentiles of their dissimilarities. Only the autoencoders of the chosen domain are trained: the *_td parameters are unused with "FD", the *_fd ones, nfft and norm_mode with "TD".

  • intermediate_dim_td (int) – Width of the hidden layer of each time domain autoencoder; 0 means no hidden layer.

  • latent_dim_td (int) – Dimension of the latent code of each time domain autoencoder.

  • nr_shared_td (int) – Number of latent dimensions that are shared, that is, kept close for consecutive windows; at most latent_dim_td. Only they form the representation.

  • nr_ae_td (int) – Number of consecutive windows encoded in parallel, with the same weights, by the time domain autoencoder.

  • loss_weight_td (float) – Weight of the term that keeps the shared codes of consecutive windows close, added to the reconstruction error.

  • intermediate_dim_fd (int) – As intermediate_dim_td, for the frequency domain autoencoders.

  • latent_dim_fd (int) – As latent_dim_td, for the frequency domain.

  • nr_shared_fd (int) – As nr_shared_td, for the frequency domain.

  • nr_ae_fd (int) – As nr_ae_td, for the frequency domain.

  • loss_weight_fd (float) – As loss_weight_td, for the frequency domain.

  • nfft (int) – Number of points of the discrete Fourier transform of the window of each channel, whose nfft // 2 + 1 first bins are kept (nfft // 2 with norm_mode="window", which drops bin 0) and rescaled to [-1, 1] channel by channel. A window longer than nfft is cut to its first nfft points.

  • norm_mode (Literal['window', 'timeseries']) – Mean removed before the Fourier transform, channel by channel: that of each window, or that of the whole series.

  • peak_distance_fraction (float) – Minimum distance between two returned peaks, as a fraction of the series length (0: no constraint).

  • max_epochs (int) – Maximum number of training epochs of each autoencoder.

  • patience (int) – Training stops after patience epochs in which the loss does not decrease by more than 1e-6; the weights of the best epoch are kept.

  • learning_rate (float) – Learning rate of the Adam optimiser.

  • n_segments (int | None) – Number of segments: the n_segments - 1 most prominent peaks are returned (none when n_segments=1). None selects the peaks by prominence_threshold.

  • prominence_threshold (float) – Minimum prominence of a returned peak, relative to the highest one, when n_segments is None.

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

  • random_state (int | None) – Seed of torch’s global random generator (weights, batch shuffling), set when the detector is built and at each fit; None sets 0.

Notes

fit only stores the series: the autoencoders are trained on X by predict. change_scores_ holds the change score of each time point after predict. A constant series (every channel constant) gives zero scores and no change point, even with n_segments.

The rescaling (§III-B of the paper), the Fourier transform of each channel (eq. 3) and the smoothing of the representations in every domain (eq. 11) follow the paper. The original code transforms the concatenated windows of the channels, cut to nfft points, and leaves the rescaling to the caller.

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:

TireDetector

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:

TireDetector

calc_fft(windows, nfft=30, norm_mode='timeseries')[source]#

Calculates the DFT for each window and transforms its length

Parameters:
  • windows – time series windows

  • nfft – number of points used for the calculation of the DFT

  • norm_mode – ensure that the timeseries / each window has zero mean

Returns:

frequency domain windows, each window having size nfft//2 (+1 for timeseries normalization), rescaled to [-1, 1] (all zero when the spectrum is constant)

combine_ts(list_of_windows)[source]#

Combines a list of windows from multiple views to one list of windows

Parameters:

list_of_windows – list of windows from multiple views

Returns:

one array with the concatenated windows

distance(data, window_size)[source]#

Calculates distance (dissimilarity measure) between features

Parameters:
  • data – array of of learned features of size (nr. of windows) x (number of shared features)

  • window_size – window size used for CPD

Returns:

Array of dissimilarities of size ((nr. of windows)-stride)

matched_filter(signal, window_size)[source]#

Matched filter for dissimilarity measure smoothing (and zero-delay weighted moving average filter for shared feature smoothing)

Parameters:
  • signal – input signal

  • window_size – window size used for CPD

Returns:

filtered signal

new_peak_prominences(distances)[source]#

Adapted calculation of prominence of peaks, based on the original scipy code

Parameters:

distances – dissimarity scores

Returns:

prominence scores

ts_to_windows(ts, onset, window_size, stride, normalization='timeseries')[source]#

Transforms time series into list of windows