Back to models
Forecaster

ConvTimeNetForecaster

ConvTimeNet for time series forecasting.

Quickstart

python
from sktime.forecasting.convtimenet import ConvTimeNetForecaster

estimator = ConvTimeNetForecaster(context_window, patch_ks, patch_sd, pred_len=None, dw_ks=(9, 3), d_model=64, d_ff=256, norm='batch', dropout=0.0, act='gelu', head_dropout=0, padding_patch=None, revin=True, affine=True, subtract_last=False, deformable=True, enable_res_param=True, re_param=True, re_param_kernel=3, num_epochs=16, batch_size=8, criterion_kwargs=None, criterion=None, optimizer=None, optimizer_kwargs=None, lr=0.001, device='cpu', random_state=None)

Parameters(28)

context_windowint
Length of the input sequence (context window).
patch_ksint
Kernel size for patch creation. Determines the size of each patch extracted from the input sequence for patch embedding.
patch_sdint
Stride length for patch creation. Determines the step size for moving the patch window across the input sequence.
pred_lenint, optional
Length of prediction (forecast horizon). Required for pretraining if fh is not passed to pretrain(). If None, will be determined from fh during fit() or pretrain().
dw_kstuple, optional (default=(9, 3))
Kernel sizes for depthwise convolution layers.
d_modelint, optional (default=64)
Dimension of the model (number of features in the hidden state).
d_ffint, optional (default=256)
Dimension of the feedforward network.
normstr, optional (default=”batch”)
Type of normalization to use (“batch” or “layer”).
dropoutfloat, optional (default=0.0)
Dropout rate to apply to layers.
actstr, optional (default=”gelu”)
Activation function to use (“relu”, “gelu”, etc.).
head_dropoutfloat, optional (default=0)
Dropout rate for the head layer.
padding_patchint or None, optional (default=None)
Padding size for patch embedding. If None, no padding is applied.
revinbool, optional (default=True)
Whether to use RevIN normalization.
affinebool, optional (default=True)
Whether RevIN uses affine transformation.
subtract_lastbool, optional (default=False)
Whether to subtract the last value in RevIN.
deformablebool, optional (default=True)
Whether to use deformable patch embedding.
enable_res_parambool, optional (default=True)
Whether to enable residual parameterization.
re_parambool, optional (default=True)
Whether to use re-parameterization.
re_param_kernelint, optional (default=3)
Kernel size for re-parameterization.
num_epochsint, optional (default=16)
The number of epochs to train the model.
batch_sizeint, optional (default=8)
The size of each mini-batch during training.
criterioncallable, optional (default=None)
The loss function to use. If None, MSELoss will be used.
criterion_kwargsdict, optional (default=None)
Additional keyword arguments to pass to the loss function.
optimizerstr or torch.optim.Optimizer, optional (default=None)
The optimizer to use. If None, Adam will be used.
optimizer_kwargsdict, optional (default=None)
Additional keyword arguments to pass to the optimizer.
lrfloat, optional (default=0.001)
The learning rate to use for the optimizer.
devicestr, optional (default=”cpu”)
Device to use for computation (“cpu” or “cuda”).
random_stateint, RandomState instance or None, optional (default=None)
Random state for reproducibility. If int, it’s the seed for the random number generator. If None, the random number generator uses a random seed.

Examples

>>> from sktime.forecasting.convtimenet import ConvTimeNetForecaster
>>> import numpy as np
>>> import pandas as pd
>>> # Create a sample univariate time series
>>> y = pd. Series (np. arange (1024)) # Example univariate time series data
>>> # Create and fit the forecaster
>>> forecaster = ConvTimeNetForecaster (
... context_window = 48,
... patch_ks = 8,
... patch_sd = 1,
... dw_ks = (13, 7),
... d_model = 128,
... d_ff = 128,
... norm = "batch",
... dropout = 0.01,
... act = "gelu",
... head_dropout = 0.01,
... padding_patch = None,
... revin = True,
... affine = True,
... subtract_last = False,
... deformable = True,
... enable_res_param = True,
... re_param = True,
... re_param_kernel = 3,
... num_epochs = 10,
... batch_size = 64,
... lr = 0.002,
... device = "cpu",
... random_state = 42
... )
>>> forecaster. fit (y, fh = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]) ConvTimeNetForecaster(
... )
>>> # Make predictions
>>> y_pred = forecaster. predict (fh = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ])
>>> print (y_pred)

References

  1. [1 ] Cheng, M., Yang, J., Pan, T., Liu, Q., & Li, Z. (2024). ConvTimeNet: A deep hierarchical fully convolutional model for multivariate time series analysis. arXiv preprint arXiv:2403.01493. https://arxiv.org/abs/2403.01493 [2 ] https://github.com/Mingyue-Cheng/ConvTimeNet