qumphy.models.timesnet module
File: qumphy/models/timesnet.py Project: 22HLT01 QUMPHY Contact: oskar.pfeffer@ptb.de Gitlab: https://gitlab.com/qumphy Description: Adapted from https://github.com/thuml/Time-Series-Library.
- qumphy.models.timesnet.FFT_for_Period(x, k=2)[source]
Find dominant periods in a time-series batch using the FFT.
- Parameters:
x (torch.Tensor) – Input tensor of shape (batch_size, sequence_length, channels).
k (int) – Number of dominant frequencies to select.
- Returns:
Tuple containing the selected periods and their corresponding frequency weights.
- Return type:
tuple
- class qumphy.models.timesnet.TimesBlock(*args: Any, **kwargs: Any)[source]
Bases:
ModuleTimesNet block for multi-period temporal feature extraction.
- class qumphy.models.timesnet.TimesNet(*args: Any, **kwargs: Any)[source]
Bases:
ModuleTimesNet model for time series forecasting and classification.
Implements the TimesNet architecture as described in: https://openreview.net/pdf?id=ju_Uqw384Oq
- Parameters:
seq_len (int) – Length of the input sequence.
label_len (int) – Length of the label/start token sequence (for forecasting).
pred_len (int, optional) – Length of the prediction/output sequence.
e_layers (int, optional) – Number of encoder layers. Default is 2.
d_model (int, optional) – Model hidden dimension. Default is 16.
d_ff (int, optional) – Dimension of the feed-forward network. Default is 32.
num_kernels (int, optional) – Number of kernels for the Inception-like blocks. Default is 6.
top_k (int, optional) – Top-k selection parameter for TimesBlock. Default is 5.
enc_in (int, optional) – Number of input channels/features. Default is 1.
c_out (int, optional) – Number of output channels/features or classes. Default is 1.
embed (str, optional) – Type of time feature embedding. Options are ‘timeF’, ‘fixed’, or ‘learned’. Default is ‘fixed’.
freq (str, optional) – Frequency string for time feature encoding (e.g., ‘h’ for hourly). Default is ‘s’.
dropout (float, optional) – Dropout rate. Default is 0.1.
num_class (int, optional) – Number of classes (for classification tasks).
task_name (str, optional) – Task type, either ‘classification’ or ‘forecasting’. Default is ‘classification’.
References
- anomaly_detection(x_enc)[source]
Run anomaly detection with the TimesNet model.
- Parameters:
x_enc (torch.Tensor) – Encoder input tensor of shape (batch_size, seq_len, enc_in).
- Returns:
Reconstructed output tensor.
- Return type:
torch.Tensor
- classification(x_enc, x_mark_enc)[source]
Run classification with the TimesNet model.
- Parameters:
x_enc (torch.Tensor) – Input tensor of shape (batch_size, enc_in, seq_len).
x_mark_enc (torch.Tensor) – Encoder time feature tensor. This parameter is kept for compatibility.
- Returns:
Classification logits of shape (batch_size, num_class).
- Return type:
torch.Tensor
- forecast(x_enc, x_mark_enc, x_dec, x_mark_dec)[source]
Run forecasting with the TimesNet model.
- Parameters:
x_enc (torch.Tensor) – Encoder input tensor of shape (batch_size, seq_len, enc_in).
x_mark_enc (torch.Tensor) – Encoder time feature tensor.
x_dec (torch.Tensor) – Decoder input tensor. This parameter is kept for compatibility.
x_mark_dec (torch.Tensor) – Decoder time feature tensor. This parameter is kept for compatibility.
- Returns:
Forecast output tensor of shape (batch_size, seq_len + pred_len, c_out).
- Return type:
torch.Tensor
- imputation(x_enc, x_mark_enc, x_dec, x_mark_dec, mask)[source]
Run imputation with the TimesNet model.
- Parameters:
x_enc (torch.Tensor) – Encoder input tensor of shape (batch_size, seq_len, enc_in).
x_mark_enc (torch.Tensor) – Encoder time feature tensor.
x_dec (torch.Tensor) – Decoder input tensor. This parameter is kept for compatibility.
x_mark_dec (torch.Tensor) – Decoder time feature tensor. This parameter is kept for compatibility.
mask (torch.Tensor) – Mask tensor indicating observed and missing values.
- Returns:
Imputed output tensor.
- Return type:
torch.Tensor