TimeXer#
- class pytorch_forecasting.models.timexer._timexer.TimeXer(context_length: int, prediction_length: int, task_name: str = 'long_term_forecast', features: str = 'MS', enc_in: int = None, hidden_size: int = 256, n_heads: int = 4, e_layers: int = 2, d_ff: int = 1024, dropout: float = 0.2, activation: str = 'relu', patch_length: int = 16, factor: int = 5, embed_type: str = 'fixed', freq: str = 'h', output_size: int | list[int] = 1, loss: MultiHorizonMetric = None, learning_rate: float = 0.001, static_categoricals: list[str] | None = None, static_reals: list[str] | None = None, time_varying_categoricals_encoder: list[str] | None = None, time_varying_categoricals_decoder: list[str] | None = None, time_varying_reals_encoder: list[str] | None = None, time_varying_reals_decoder: list[str] | None = None, x_reals: list[str] | None = None, x_categoricals: list[str] | None = None, embedding_sizes: dict[str, tuple[int, int]] | None = None, embedding_labels: list[str] | None = None, embedding_paddings: list[str] | None = None, categorical_groups: dict[str, list[str]] | None = None, logging_metrics: ModuleList = None, **kwargs)[source]#
Bases:
BaseModelWithCovariatesTimeXer model for time series forecasting with exogenous variables.
An implementation of the TimeXer model.
TimeXer empowers the canonical transformer with the ability to reconcile endogenous and exogenous information without any architectural modifications and achieves consistent state-of-the-art performance across twelve real-world forecasting benchmarks.
TimeXer employs patch-level and variate-level representations respectively for endogenous and exogenous variables, with an endogenous global token as a bridge in-between. With this design, TimeXer can jointly capture intra-endogenous temporal dependencies and exogenous-to-endogenous correlations.
TimeXer model for time series forecasting with exogenous variables.
- Parameters:
(int) (prediction_length)
(int)
(str (activation) – ‘long_term_forecast’ or ‘short_term_forecast’, which corresponds to forecasting scenarios implied by the task names.
optional) (Whether to apply normalization to input data.) – ‘long_term_forecast’ or ‘short_term_forecast’, which corresponds to forecasting scenarios implied by the task names.
(str – multivariate forecating with single target, ‘M’ for multivariate forecasting with multiple targets and ‘S’ for univariate forecasting).
optional) – multivariate forecating with single target, ‘M’ for multivariate forecasting with multiple targets and ‘S’ for univariate forecasting).
(int (patch_length)
optional)
(int – representations.
optional) – representations.
(int – layers.
optional) – layers.
(int – mechanism.
optional) – mechanism.
(int
optional)
(float (dropout) – regularization.
optional) – regularization.
(str – (‘relu’ or ‘gelu’).
optional) – (‘relu’ or ‘gelu’).
(int – endogenous variable tokenization.
optional) – endogenous variable tokenization.
(bool (use_norm) – Do not change, as it a setting controlled by the pytorch-forecasting API
optional) – Do not change, as it a setting controlled by the pytorch-forecasting API
factor (Scaling factor for attention scores.)
embed_type (Type of time feature embedding ('timeF' for time-based features))
freq (Frequency of the time series data('h' for hourly,'d' for daily, etc.).)
(list[str]) (embedding_paddings)
(list[str])
(list[str]) – variables for encoder
(list[str]) – variables for decoder
(list[str]) – encoder
(list[str]) – decoder
(list[str]) – forward function
(list[str]) – to forward function
(dict[str (categorical_groups) – variables to tuple of integers where the first integer denotes the number of categorical classes and the second the embedding size
tuple[int (dictionary mapping categorical) – variables to tuple of integers where the first integer denotes the number of categorical classes and the second the embedding size
int]]) (dictionary mapping categorical) – variables to tuple of integers where the first integer denotes the number of categorical classes and the second the embedding size
(dict[str – to list of categorical labels
list[str]]) (dictionary of categorical) – to list of categorical labels
(list[str]) – label 0 is always mapped to an embedding vector filled with zeros
(dict[str – variables that are grouped together and can also take multiple values simultaneously (e.g. holiday during octoberfest). They should be implemented as bag of embeddings.
list[str]]) – variables that are grouped together and can also take multiple values simultaneously (e.g. holiday during octoberfest). They should be implemented as bag of embeddings.
(nn.ModuleList[LightningMetric]) (logging_metrics) – logged during training. Defaults to nn.ModuleList([SMAPE(), MAE(), RMSE(), MAPE()]).
**kwargs (additional arguments to
BaseModel.)
Methods
forward(x)Forward pass of the model.
from_dataset(dataset[, ...])Create model from dataset and set parameters related to covariates.
- forward(x: dict[str, Tensor]) dict[str, Tensor][source]#
Forward pass of the model.
- Parameters:
x – Dictionary containing model inputs
- Returns:
Dictionary with model outputs
- classmethod from_dataset(dataset: TimeSeriesDataSet, allowed_encoder_known_variable_names: list[str] = None, **kwargs)[source]#
Create model from dataset and set parameters related to covariates.
- Parameters:
dataset – timeseries dataset
allowed_encoder_known_variable_names – list of known variables that are allowed in encoder, defaults to all
**kwargs – additional arguments such as hyperparameters for model (see
__init__())
- Returns:
TimeXer
- property decoder_covariate_size: int#
Decoder covariates size.
- Returns:
size of time-dependent covariates used by the decoder
- Return type:
int
- property encoder_covariate_size: int#
Encoder covariate size.
- Returns:
size of time-dependent covariates used by the encoder
- Return type:
int
- property static_size: int#
Static covariate size.
- Returns:
size of static covariates
- Return type:
int