Skip to main content

1. MLP

Multi-Layer Perceptron

MLP

Bases: Module Multi-Layer Perceptron for time series forecasting. A feedforward neural network with configurable depth and width. The network
consists of an input layer, multiple hidden layers with activation functions
and dropout, and an output layer. All hidden layers have the same dimensionality.
Parameters: Returns:

2. Temporal Convolutions

For long time in deep learning, sequence modelling was synonymous with recurrent networks, yet several papers have shown that simple convolutional architectures can outperform canonical recurrent networks like LSTMs by demonstrating longer effective memory. References -van den Oord, A., Dieleman, S., Zen, H., Simonyan, K., Vinyals, O., Graves, A., Kalchbrenner, N., Senior, A. W., & Kavukcuoglu, K. (2016). Wavenet: A generative model for raw audio. Computing Research Repository, abs/1609.03499. URL: http://arxiv.org/abs/1609.03499. arXiv:1609.03499. -Shaojie Bai, Zico Kolter, Vladlen Koltun. (2018). An Empirical Evaluation of Generic Convolutional and Recurrent Networks for Sequence Modeling. Computing Research Repository, abs/1803.01271. URL: https://arxiv.org/abs/1803.01271.

Chomp1d

Bases: Module Temporal trimming layer for 1D sequences. Removes the rightmost horizon timesteps from a 3D tensor. This is commonly
used to trim padding added by convolution operations, ensuring the output
sequence has the desired length.
The operation trims the temporal dimension: [N, C, T] -> [N, C, T-horizon] Parameters: Returns:

CausalConv1d

CausalConv1d

Bases: Module Causal Convolution 1d Receives x input of dim [N,C_in,T], and computes a causal convolution in the time dimension. Skipping the H steps of the forecast horizon, through its dilation. Consider a batch of one element, the dilated convolution operation on the tt time step is defined: Conv1D(x,w)(t)=(x[d]w)(t)=k=1Kwkxtdk\mathrm{Conv1D}(\mathbf{x},\mathbf{w})(t) = (\mathbf{x}_{[*d]} \mathbf{w})(t) = \sum^{K}_{k=1} w_{k} \mathbf{x}_{t-dk} where dd is the dilation factor, KK is the kernel size, tdkt-dk is the index of the considered past observation. The dilation effectively applies a filter with skip connections. If d=1d=1 one recovers a normal convolution. Parameters: Returns:

TemporalConvolutionEncoder

3. Transformers

References

TransEncoder

Bases: Module Transformer Encoder. A stack of transformer encoder layers that processes input sequences through
multiple self-attention and feed-forward layers. Optionally includes convolutional
layers between attention layers for distillation and a final normalization layer.
Parameters: Returns:

TransEncoderLayer

Bases: Module Transformer Encoder Layer. A single layer of the transformer encoder that applies self-attention followed by
a position-wise feed-forward network with residual connections and layer normalization.
Dropout is applied after the self-attention output and twice in the feed-forward network
(after each convolution) before the residual connections for regularization.
Parameters: Returns:

TransDecoder

Bases: Module Transformer decoder module for sequence-to-sequence forecasting. Stacks multiple TransDecoderLayer modules to process decoder inputs with
self-attention and cross-attention mechanisms. Optionally applies layer
normalization and a final projection layer to produce output predictions.
Parameters: Returns:

TransDecoderLayer

Bases: Module Transformer Decoder Layer. A single layer of the transformer decoder that applies masked self-attention,
cross-attention with encoder outputs, and a position-wise feed-forward network
with residual connections and layer normalization. Dropout is applied after each
sub-layer (self-attention, cross-attention, and twice in the feed-forward network)
before the residual connection for regularization.
Parameters: Returns:

AttentionLayer

Bases: Module Multi-head attention layer wrapper. This layer wraps an attention mechanism and handles the linear projections
for queries, keys, and values in multi-head attention. It projects inputs
to multiple heads, applies the inner attention mechanism, and projects back
to the original hidden dimension.
Parameters: Returns:

FullAttention

Bases: Module Full attention mechanism with scaled dot-product attention. Implements standard multi-head attention using scaled dot-product attention.
Supports both efficient computation via PyTorch’s scaled_dot_product_attention
and explicit attention computation when attention weights are needed. Optional
causal masking prevents attention to future positions in autoregressive models.
Parameters: Returns:

TriangularCausalMask

Triangular causal mask for autoregressive attention. Creates an upper triangular boolean mask that prevents attention mechanisms
from attending to future positions in the sequence. This ensures causality
in autoregressive models where predictions at time t should only depend on
positions before t.
The mask is created using torch.triu with diagonal=1, resulting in a mask
where positions (i, j) are True when j > i, effectively masking out future
positions during attention computation.
Parameters: Attributes:

DataEmbedding_inverted

Bases: Module Inverted data embedding module for variate-as-token transformer architectures. Transforms time series data by treating each variate (channel) as a token rather
than each time step. The input is permuted from [Batch, Time, Variate] to
[Batch, Variate, Time], then a linear layer projects the time dimension to the
hidden dimension. Optionally concatenates temporal covariates along the variate
dimension.
Parameters: Returns:

DataEmbedding

Bases: Module Data embedding module combining value, positional, and temporal embeddings. Transforms time series data into high-dimensional embeddings by combining:
  • Value embeddings: Convolutional encoding of the time series values
  • Positional embeddings: Sinusoidal encodings for relative position within window
  • Temporal embeddings: Linear projection of absolute calendar features (optional)
Parameters: Returns:

TemporalEmbedding

Bases: Module Temporal embedding module for encoding calendar-based time features. Creates learnable or fixed embeddings for temporal features including month,
day, weekday, hour, and optionally minute. These embeddings are summed to
produce a combined temporal representation.
Parameters: Returns:

FixedEmbedding

Bases: Module Fixed sinusoidal embedding for categorical temporal features. Creates non-trainable embeddings using sine and cosine functions at different
frequencies. Unlike PositionalEmbedding which encodes continuous positions,
FixedEmbedding is designed for discrete categorical inputs (e.g., hour of day,
day of month, month of year). The embeddings are precomputed and frozen,
making them non-learnable parameters.
Parameters: Returns:

TimeFeatureEmbedding

Bases: Module Linear embedding for temporal/calendar features. Transforms time-based features (e.g., hour, day, month) into embeddings using
a single linear projection without bias. This embedding is typically used to
incorporate calendar information into transformer models, providing absolute
temporal context that complements positional encodings.
Parameters: Returns:

PositionalEmbedding

Bases: Module Sinusoidal positional embedding for transformer models. Generates fixed sinusoidal positional encodings using sine and cosine functions
at different frequencies. These encodings provide position information to
transformer models, allowing them to understand the relative or absolute position
of tokens in a sequence. The encodings are precomputed and stored as a buffer,
making them non-trainable.
Parameters: Returns:

SeriesDecomp

Bases: Module Series decomposition block for trend-residual decomposition. Decomposes time series into trend and residual components using moving average filtering. The trend is extracted via a moving average filter, and the residual is computed as the difference between the input and the trend. Parameters: Returns:

MovingAvg

Bases: Module Moving average block to highlight the trend of time series. Applies a moving average filter using 1D average pooling to smooth time series
data and extract trend components. The input is padded on both ends by repeating
the first and last values to maintain the original sequence length.
Parameters: Returns:

RevIN

Bases: Module Reversible Instance Normalization for time series forecasting. Normalizes time series data by removing the mean (or last value) and scaling by
standard deviation. The normalization can be reversed after model predictions to
restore the original scale. Optionally includes learnable affine parameters for
additional transformation flexibility.
Parameters: Returns:

RevINMultivariate

Bases: Module Reversible Instance Normalization for multivariate time series models. Normalizes multivariate time series data using batch statistics computed across
the time dimension. The normalization can be reversed after model predictions to
restore the original scale. Optionally includes learnable affine parameters for
additional transformation flexibility.
Parameters: Returns: