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.
window_sizeParameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int |
|
Sliding window size (>= 4). |
|
int |
|
Stride between consecutive windows (at most |
|
str |
|
Domain(s) for representation learning ( |
|
int |
|
Hidden dim of TD autoencoder (0 = skip intermediate layer). |
|
int |
|
Latent dim of TD autoencoder. |
|
int |
|
Number of shared latent dims (TD). |
|
int |
|
Number of parallel TD autoencoders. |
|
float |
|
Loss weight for TD component. |
|
int |
|
Hidden dim of FD autoencoder. |
|
int |
|
Latent dim of FD autoencoder. |
|
int |
|
Number of shared latent dims (FD). |
|
int |
|
Number of parallel FD autoencoders. |
|
float |
|
Loss weight for FD component. |
|
int |
|
DFT size of the window of each channel (longer windows are cut). |
|
str |
|
Mean removed before the DFT, per channel: of each window ( |
|
float |
|
Minimum distance between two change points, as a fraction of the series length (0: no constraint). |
|
float |
|
Minimum prominence of a peak, relative to the highest one, when
|
|
int |
|
Maximum training epochs. |
|
int |
|
Early-stopping patience. |
|
float |
|
Optimiser learning rate. |
|
int / None |
|
Number of segments (overrides peak detection). |
|
int |
|
Time axis. |
|
int / 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:
BaseSegmenterTIRE (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. Withn_segmentsthen_segments - 1most prominent peaks are returned; otherwise every peak whose relative prominence reachesprominence_threshold. Two returned peaks are at leastpeak_distance_fractionof 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 mostwindow_size. The comparison lag and both filter half-widths areceil(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*_tdparameters are unused with"FD", the*_fdones,nfftandnorm_modewith"TD".intermediate_dim_td (
int) – Width of the hidden layer of each time domain autoencoder;0means 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 mostlatent_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) – Asintermediate_dim_td, for the frequency domain autoencoders.latent_dim_fd (
int) – Aslatent_dim_td, for the frequency domain.nr_shared_fd (
int) – Asnr_shared_td, for the frequency domain.nr_ae_fd (
int) – Asnr_ae_td, for the frequency domain.loss_weight_fd (
float) – Asloss_weight_td, for the frequency domain.nfft (
int) – Number of points of the discrete Fourier transform of the window of each channel, whosenfft // 2 + 1first bins are kept (nfft // 2withnorm_mode="window", which drops bin 0) and rescaled to [-1, 1] channel by channel. A window longer thannfftis cut to its firstnfftpoints.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 afterpatienceepochs 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: then_segments - 1most prominent peaks are returned (none whenn_segments=1).Noneselects the peaks byprominence_threshold.prominence_threshold (
float) – Minimum prominence of a returned peak, relative to the highest one, whenn_segmentsisNone.axis (
int) – The time axis ofX:0if 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 eachfit;Nonesets 0.
Notes
fitonly stores the series: the autoencoders are trained onXbypredict.change_scores_holds the change score of each time point afterpredict. A constant series (every channel constant) gives zero scores and no change point, even withn_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
nfftpoints, and leaves the rescaling to the caller.- 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.
- 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