Skip to content

ConvTimeNetForecaster

ConvTimeNetForecaster

class 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)[source]

ConvTimeNet for time series forecasting.

ConvTimeNet is a hierarchical pure convolutional model designed. Unlike prevalent methods centered around self-attention mechanisms, ConvTimeNet introduces two key innovations:

  1. A deformable patch layer that adaptively perceives local patterns of temporally dependent basic units in a data-driven manner.

  2. Hierarchical pure convolutional blocks that capture dependency relationships

    among the representations of basic units at different scales.

The model employs a large kernel mechanism allowing convolutional blocks to be deeply stacked, achieving a larger receptive field. This architecture effectively models both local patterns and their multi-scale dependencies within a single model, addressing common challenges in time series analysis such as adaptive perception of local patterns and multi-scale dependency capture.

This forecaster has been wrapped around implementations from [1] and [2].

Parameters:
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.

criterion_kwargsdict, optional (default=None)

Additional keyword arguments to pass to the loss function.

criterioncallable, optional (default=None)

The loss function to use. If None, MSELoss will be used.

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.

Attributes:
cutoff

Cut-off = “present time” state of forecaster.

fh

Forecasting horizon that was passed.

is_fitted

Whether fit has been called.

state

State of the estimator.

References

[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

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)

Methods

build_pytorch_pred_dataloader(y, fh)

Build PyTorch DataLoader for prediction.

build_pytorch_train_dataloader(y)

Build PyTorch DataLoader for training with custom batch handling.

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(y[, X, fh])

Fit forecaster to training data.

fit_predict(y[, X, fh, X_pred])

Fit and forecast time series at future horizon.

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get a dict of parameters values for this object.

get_pretrained_params([deep])

Get pretrained parameters of this estimator.

get_tag(tag_name[, tag_value_default, ...])

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params([parameter_set])

Return testing parameter settings for the estimator.

get_y_true(y)

Get y_true values for validation.

is_composite()

Check if the object is composed of other BaseObjects.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

predict([fh, X])

Forecast time series at future horizon.

predict_interval([fh, X, coverage])

Compute/return prediction interval forecasts.

predict_proba([fh, X, marginal])

Compute/return fully probabilistic forecasts.

predict_quantiles([fh, X, alpha])

Compute/return quantile forecasts.

predict_residuals([y, X])

Return residuals of time series forecasts.

predict_var([fh, X, cov])

Compute/return variance forecasts.

pretrain(y[, X, fh])

Pre-train forecaster on panel (global) data.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

score(y[, X, fh])

Scores forecast against ground truth, using MAPE (non-symmetric).

set_config(**config_dict)

Set config flags to given values.

set_params(**params)

Set the parameters of this object.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.

update(y[, X, update_params])

Update cutoff value and, optionally, fitted parameters.

update_predict(y[, cv, X, update_params, ...])

Make predictions and update model iteratively over the test set.

update_predict_single([y, fh, X, update_params])

Update model with new data and make forecasts.