tGLAD#

tGLAD – temporal Graph-difference change point detection.

Description#

tGLAD segments multivariate time series by tracking the evolution of conditional independence (CI) graphs over time. A sliding window converts the series into overlapping intervals; the uGLAD sparse graph recovery model (multitask mode) recovers a precision matrix (CI graph) for each interval simultaneously. Following the authors’ code, the score of a window is the absolute second difference, across windows, of the sum of its partial correlations (for a univariate series, tsseg uses the precision of the single channel). In place of the allocation algorithm of the paper, tsseg returns the start of each window whose score reaches threshold, keeping change points at least min_spacing apart.

Each batch of windows trains a new uGLAD model, and uGLAD scales each channel of each window to \([0, 1]\) (min-max) first. What to expect:

  • Training length. GLAD shrinks the off-diagonal entries of the precision matrix by a soft threshold that it learns. After too few epochs, this threshold can set every partial correlation of a window to zero; when it does so in every window, all scores are 0 and no change point is found. With 100 epochs, this happened on a two-channel series with two clear mean shifts, and on 96 to 100 % of the windows of the first three MoCap trials (four channels, default window_size). epochs is therefore 2000 by default, as in the authors’ code; training takes about 20 times longer than with 100.

  • Several change points per transition. The windows around a transition can each reach threshold and give a change point at their start. The authors’ code instead marks the window_size points on each side of each such window as a transition, so that the marked intervals merge.

  • Univariate series. Without partial correlations, the summary of a window is the precision of its single channel, a fallback that is not in the authors’ code. Because of the min-max scaling, it does not follow the variance of the signal, only the shape of the distribution of the window’s values; after 2000 epochs it varies from one window to the next, within a stationary segment too, by far more than the default threshold, so that most windows give a change point.

Type: change point detection
Supervision: fully unsupervised
Scope: multivariate; univariate accepted (fallback summary, see above)
Complexity: \(O(d^{3}\,n)\) per training epoch
Requires: PyTorch, networkx

Note

The tGLAD paper (Imani & Shrivastava, AALTD 2023, Sec. 3.3) reports \(O(n)\) when \(d^{3} \ll n\). This counts \(d\) and the number of epochs as constants and assumes the batches run in parallel; the sequential cost it derives, \(O(d^{3}\,n)\) per epoch, is the one above.

Parameters#

Name

Type

Default

Description

window_size

int

512

Time steps per uGLAD window.

stride

int

128

Step between successive windows.

batch_size

int

8

Windows processed together by the multitask solver.

threshold

float

0.5

Min window score to trigger a change point.

min_spacing

int / None

None

Min distance between emitted CPs (default: stride).

epochs

int

2000

uGLAD training epochs per batch (2000 in the authors’ code).

learning_rate

float

0.001

Optimiser learning rate.

glad_iterations

int

5

Unrolled GLAD iterations.

eval_offset

float

0.1

Eigenvalue regularisation for batch covariance.

verbose

bool

False

Print progress information.

axis

int

0

Time axis.

Usage#

from tsseg.algorithms import TGLADDetector

detector = TGLADDetector(window_size=256, stride=64, threshold=0.4)
change_points = detector.fit_predict(X)

Implementation: Re-coding, with NumPy, of the scoring in main.py of the authors’ repository (Harshs27/tGLAD), around the uGLAD multitask solver of that repository, vendored in tsseg/algorithms/tglad/vendor/uGLAD/ (imports made relative). uGLAD is under the uGLAD Non-Commercial License, which allows non-commercial use only; a copy is in tsseg/algorithms/tglad/vendor/LICENSE. Origin: wrapper around vendored third-party code.

Reference: Imani & Shrivastava (2023), Are uGLAD? Time will tell!

API reference#

TGLAD change point detector.

class TGLADDetector(*, window_size=512, stride=128, batch_size=8, threshold=0.5, min_spacing=None, epochs=2000, learning_rate=0.001, glad_iterations=5, eval_offset=0.1, verbose=False, axis=0)[source]#

Bases: BaseSegmenter

Graph-difference based change point detector using uGLAD.

The detector follows the batching procedure described in the original tGLAD repository. The time-series is converted to overlapping windows, each window yields a precision matrix via the uGLAD multitask solver.

The change point score is calculated based on the second derivative of the sum of partial correlations derived from the precision matrices, faithfully mirroring the original implementation. Change points are emitted whenever the score reaches threshold.

Parameters:
  • window_size (int) – Number of time steps per uGLAD window.

  • stride (int) – Step between successive windows.

  • batch_size (int) – Number of windows processed together by the multitask solver.

  • threshold (float) – Minimum window score (absolute second difference, across windows, of the sum of partial correlations) that triggers a change point.

  • min_spacing (int | None) – Minimum distance (in samples) required between two emitted change points. Defaults to the stride when None.

  • epochs (int) – Number of uGLAD training epochs per batch, as in main.py of the authors’ repository. Fewer epochs run faster but can leave every partial correlation at zero, and then no change point is found (see Notes).

  • learning_rate (float) – Optimiser learning rate.

  • glad_iterations (int) – Number of unrolled GLAD iterations (L in the paper).

  • eval_offset (float) – Eigenvalue regularisation applied to batch covariance matrices.

  • verbose (bool) – If true, uGLAD prints its progress on stdout for each batch: input checks, the loss every tenth of the epochs and the runtime. If false, nothing is printed.

  • axis (int) – Time axis of X. 0 assumes (n_timepoints, n_features).

Notes

Each batch of windows trains a new uGLAD model, and uGLAD scales each channel of each window to [0, 1] (min-max) before it estimates the precision matrix.

  • Training length: GLAD shrinks the off-diagonal entries of the precision matrix by a soft threshold that it learns. After too few epochs, this threshold can set every partial correlation of a window to zero; when it does so in every window, all summaries are 0 and no change point is found. With 100 epochs this happened on a two-channel series with two clear mean shifts, and on 96 to 100 % of the windows of the first three MoCap trials (four channels, default window_size). 2000 epochs take about 20 times longer.

  • Several change points per transition: every window whose score reaches threshold gives a change point at its start, at least min_spacing apart, so the windows around one transition can give one each. The authors’ code instead marks the window_size points on each side of each such window as a transition, so that the marked intervals merge.

  • Univariate series: there is no partial correlation, and the summary of a window falls back to the precision of its single channel (this fallback is not in the authors’ code). The min-max scaling removes the scale of the window, so this precision does not follow the variance of the signal, only the shape of the distribution of the window’s values. After 100 epochs it is far from converged and jumps from one batch to the next; after 2000 it varies from one window to the next, within a stationary segment too, by far more than the default threshold, so that most windows give a change point.

TGLAD segments the series given to fit: predict(X) returns those change points when X has the same values, and otherwise segments X with a new fit (new uGLAD models, trained on X), with a warning, leaving the fitted attributes unchanged.

property change_points_: ndarray#

Return change points detected during fit().

property change_scores_: ndarray#

Score of each window (0 for the first and the last).

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:

TGLADDetector

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:

TGLADDetector