tsseg.algorithms.vqtss package
VQ-TSS — Vector Quantized Time Series Segmentation.
Description
VQ-TSS is a predictive segmentation model that learns discrete state codes via a VQ-VAE bottleneck:
Encoder — dilated residual convolutions map sliding windows to a continuous latent space.
Vector Quantisation — an EMA-updated codebook discretises the latent vectors into a finite set of state codes.
Predictor — an InfoNCE objective trains the predictor to match the next-step continuous latent, encouraging the codebook to capture semantically meaningful states.
A temporal-smoothness regulariser discourages rapid label switching.
Parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int |
|
Sliding-window length for training. |
|
int |
|
Stride for sliding-window extraction. |
|
int |
|
Latent / codebook dimension. |
|
int |
|
Number of VQ codebook entries (max discrete states). |
|
float |
|
VQ commitment-loss coefficient. |
|
float |
|
EMA decay for codebook updates. |
|
float |
|
Temporal-smoothness regularisation weight. |
|
float |
|
Temperature for InfoNCE logits. |
|
int |
|
Timesteps within +/- margin masked from negatives. |
|
float |
|
Adam learning rate. |
|
int |
|
Mini-batch size. |
|
int |
|
Training epochs. |
|
float |
|
Gradient clipping (0 = disable). |
|
str / None |
|
PyTorch device (auto-detected if |
|
int / None |
|
Random seed. |
|
int |
|
Time axis. |
Usage
from tsseg.algorithms import VQTSSDetector
detector = VQTSSDetector(window_size=128, num_embeddings=32, epochs=20)
states = detector.fit_predict(X)
Implementation: Origin: new code.
Reference: —
Submodules
tsseg.algorithms.vqtss.detector module
- class tsseg.algorithms.vqtss.detector.VQTSSDetector(*, window_size=128, stride=1, hidden_dim=64, num_embeddings=64, commitment_cost=0.25, decay=0.99, smoothness_weight=0.1, contrastive_temperature=0.07, neg_temporal_margin=5, learning_rate=0.001, batch_size=64, epochs=10, max_grad_norm=1.0, device=None, random_state=None, axis=0)[source]
Bases:
BaseSegmenterVector Quantized Time Series Segmentation (VQ-TSS).
A predictive segmentation model that learns discrete state codes by optimising a contrastive future-prediction task through a VQ-VAE bottleneck. The encoder uses dilated residual convolutions, quantises the latent via EMA-updated codebook vectors, and trains a predictor to match the next-step continuous latent (InfoNCE objective).
- Parameters:
axis (
int) – Time axis.axis=0means(n_timepoints, n_channels).window_size (
int) – Sliding-window length used during training.stride (
int) – Stride for the sliding-window extraction.hidden_dim (
int) – Latent / codebook dimension.num_embeddings (
int) – Number of VQ codebook entries (maximum number of discrete states).commitment_cost (
float) – VQ commitment-loss coefficient.decay (
float) – EMA decay for codebook updates.smoothness_weight (
float) – Weight of the temporal-smoothness regularisation on quantised latents.contrastive_temperature (
float) – Temperature for the InfoNCE logits.neg_temporal_margin (
int) – Timesteps within±neg_temporal_marginof the positive are masked out as negatives (they are trivially similar in continuous signals).learning_rate (
float) – Adam learning rate.batch_size (
int) – Mini-batch size.epochs (
int) – Number of training epochs.max_grad_norm (
float) – Gradient clipping (max L2 norm). Set0to disable.device (
str|None) – PyTorch device. Auto-detected ifNone.random_state (
int|None) – Random seed for reproducibility.
- get_active_states()[source]
Return the unique codebook indices used on the training data.
- Return type:
- set_fit_request(*, axis: bool | None | str = '$UNCHANGED$') VQTSSDetector
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: bool | None | str = '$UNCHANGED$') VQTSSDetector
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.