tsseg.algorithms.tscp2 package
TS-CP² — change point detection with contrastive predictive coding.
Description
TS-CP² learns temporal representations using a Temporal Convolutional Network (TCN) trained with a contrastive predictive coding (CPC) objective. Pairs of consecutive windows are encoded; if their embeddings are similar the boundary between them is unlikely to be a change point, while dissimilar embeddings signal a regime change.
The contrastive loss (configurable: NCE, debiased CL, focal CL, hard-negative CL) encourages the encoder to capture the distributional structure of each segment. A similarity curve is built from all adjacent-window pairs and thresholded (or top-K peaks selected) to produce change points.
tcnParameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int |
|
Sliding window size for building window pairs. |
|
int / None |
|
Number of change points ( |
|
float / None |
|
Custom similarity threshold for detecting CPs. |
|
int |
|
Step between successive window pairs. |
|
int |
|
Dimension of the learned representation. |
|
int |
|
Number of TCN filters. |
|
int |
|
TCN kernel size. |
|
tuple |
|
Dilation factors for TCN layers. |
|
int |
|
Number of TCN stacks. |
|
float |
|
Dropout rate. |
|
int |
|
Training batch size. |
|
int |
|
Training epochs. |
|
float |
|
Optimiser learning rate. |
|
str |
|
Contrastive loss ( |
|
float |
|
Temperature for contrastive logits. |
|
str |
|
Similarity function. |
|
int |
|
Time axis. |
Usage
from tsseg.algorithms import TSCP2Detector
detector = TSCP2Detector(window_size=128, n_cps=5, epochs=50)
labels = detector.fit_predict(X)
Implementation: TensorFlow reimplementation adapted from original code by Deldari et al.
Reference: Deldari, Smith, Xue & Salim (2021), Time Series Change Point Detection with Self-Supervised Contrastive Predictive Coding, WWW.