DLinear#

class pytorch_forecasting.models.dlinear._dlinear_v2.DLinear(loss: Module, moving_avg: int = 25, individual: bool = False, logging_metrics: list[Module] | None = None, optimizer: Optimizer | str | None = 'adam', optimizer_params: dict | None = None, lr_scheduler: str | None = None, lr_scheduler_params: dict | None = None, metadata: dict | None = None, **kwargs: Any)[source]#

Bases: TslibBaseModel

DLinear: Decomposition Linear Model for Long-Term Time Series Forecasting.

DLinear decomposes time series into trend and seasonal components and applies separate linear layers to each component. The final prediction is the sum of both components.

Parameters:
  • loss (nn.Module) – Loss function for training step.

  • moving_avg (int , default=25) – Kernel size for moving average decomposition.

  • individual (bool, default=False) – Whether to use individual linear layers for each variate (True) or shared layers across all variates (False).

  • logging_metrics (Optional[list[nn.Module]], default=None) – List of metrics to log during training, validation, and testing.

  • optimizer (Optional[Union[Optimizer, str]], default='adam') – Optimizer to use for training.

  • optimizer_params (Optional[dict], default=None) – Parameters for the optimizer.

  • lr_scheduler (Optional[str], default=None) – Learning rate scheduler to use.

  • lr_scheduler_params (Optional[dict], default=None) – Parameters for the learning rate scheduler.

  • metadata (Optional[dict], default=None) – Metadata for the model from TslibDataModule.

References

[1] https://arxiv.org/pdf/2205.13504 [2] https://github.com/thuml/Time-Series-Library/blob/main/models/DLinear.py

Notes

[1] This implementation supports only continuous features. Categorical variables

will be accommodated in future versions.

Methods

forward(x)

Forward pass of the DLinear model.

forward(x: dict[str, Tensor]) dict[str, Tensor][source]#

Forward pass of the DLinear model.

Parameters:

x (dict[str, torch.Tensor]) – Dictionary containing input tensors.

Returns:

Dictionary containing output tensors. These can include - predictions: Prediction_output of shape (batch_size, prediction_length, target_dim) - attention_weights: Optionally, output attention weights

Return type:

dict[str, torch.Tensor]