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).epochsis 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
thresholdand give a change point at their start. The authors’ code instead marks thewindow_sizepoints 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.
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 |
|---|---|---|---|
|
int |
|
Time steps per uGLAD window. |
|
int |
|
Step between successive windows. |
|
int |
|
Windows processed together by the multitask solver. |
|
float |
|
Min window score to trigger a change point. |
|
int / None |
|
Min distance between emitted CPs (default: |
|
int |
|
uGLAD training epochs per batch (2000 in the authors’ code). |
|
float |
|
Optimiser learning rate. |
|
int |
|
Unrolled GLAD iterations. |
|
float |
|
Eigenvalue regularisation for batch covariance. |
|
bool |
|
Print progress information. |
|
int |
|
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:
BaseSegmenterGraph-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
uGLADmultitask 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 whenNone.epochs (
int) – Number of uGLAD training epochs per batch, as inmain.pyof 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 (Lin 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 ofX.0assumes(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
thresholdgives a change point at its start, at leastmin_spacingapart, so the windows around one transition can give one each. The authors’ code instead marks thewindow_sizepoints 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 whenXhas the same values, and otherwise segmentsXwith a new fit (new uGLAD models, trained onX), with a warning, leaving the fitted attributes unchanged.- 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.