Multivariate
polars_ts.dl.multivariate
Native multivariate deep forecasting models.
MultivariatePatchTST: Channel-mixing PatchTST that processes all variates jointly through a shared transformer encoder.
iTransformerForecaster: Inverted transformer that treats each variate as a token (Liu et al., 2024), enabling cross-variate attention.
References
Nie et al. (2023). PatchTST. ICLR. Liu et al. (2024). iTransformer. ICLR.
_MVPatchTSTNet
Bases: Module
Channel-mixing PatchTST: all variates processed jointly.
forward(x)
Forward pass.
Parameters
x : Tensor of shape (batch, input_size, n_vars)
Returns
Tensor of shape (batch, h, n_vars)
_iTransformerNet
Bases: Module
Inverted transformer: each variate is a token.
forward(x)
Forward pass.
Parameters
x : Tensor of shape (batch, input_size, n_vars)
Returns
Tensor of shape (batch, h, n_vars)
MultivariatePatchTST
Channel-mixing PatchTST for multivariate forecasting.
Parameters
h Forecast horizon. input_size Lookback window length. patch_len Length of each input patch. target_cols List of target column names to forecast jointly. d_model Transformer hidden dimension. n_heads Number of attention heads. n_layers Number of transformer encoder layers. dropout Dropout rate. lr Learning rate. max_epochs Maximum training epochs. id_col, time_col Column names.
fit(df)
Train on multivariate panel data.
predict(df)
Generate multivariate forecasts.
iTransformerForecaster
Inverted transformer forecaster for multivariate time series.
Treats each variate as a token, enabling cross-variate attention.
Parameters
h Forecast horizon. input_size Lookback window length. target_cols List of target column names to forecast jointly. d_model Transformer hidden dimension. n_heads Number of attention heads. n_layers Number of transformer encoder layers. dropout Dropout rate. lr Learning rate. max_epochs Maximum training epochs. id_col, time_col Column names.
fit(df)
Train on multivariate panel data.
predict(df)
Generate multivariate forecasts.
_extract_multivariate(df, target_cols, id_col, time_col)
Extract per-series multivariate arrays.
Returns
ids
List of series identifiers.
arrays
List of arrays, each of shape (seq_len, n_vars).
_build_mv_windows(arrays, input_size, h)
Build multivariate sliding windows.
Returns
X
Shape (n_windows, input_size, n_vars).
Y
Shape (n_windows, h, n_vars).
_build_mv_forecast_df(ids, forecasts, target_cols, df, h, id_col, time_col)
Build output DataFrame with future dates and multivariate forecasts.
Parameters
forecasts
Shape (n_series, h, n_vars).