TimesNet: Temporal 2D-Variation Modeling for Time Series

Machine Learning
Introduced by
Haixu Wu et al.
Year
2023
Type
2D convolutional time-series model
Family
Time-series forecasting

What does it do?

TimesNet is a general-purpose time-series model introduced by Wu et al. at ICLR 2023.

It reinterprets a one-dimensional series as a set of two-dimensional temporal maps, one for each dominant period detected with the Fast Fourier Transform (FFT). This reshaping places intraperiod patterns (within one cycle) along one axis and interperiod variation (across cycles) along the other, so that 2D convolutional layers can model temporal variation.

The intuition behind the method

Consider a daily record with a strong weekly rhythm. Read as one flat sequence, the weekly structure is spread across distant time steps. TimesNet instead detects the period from the spectrum and stacks the series into a grid in which each row is one week: columns line up the same day of the week, and rows line up consecutive weeks. A 2D convolution can then learn day-of-week patterns along one direction and week-to-week change along the other. When the spectrum shows several strong periods, the model builds one such grid per period and combines the results, so each rhythm is represented explicitly.

History

TimesNet was proposed by Haixu Wu, Tengge Hu, Yong Liu, Hang Zhou, Jianmin Wang and Mingsheng Long, and published at ICLR 2023. Its central design choice, applying 2D convolution to series reshaped by detected period, borrows the convolutional approach from computer vision.

When to use it

Choose TimesNet when the series has clear periodic or quasi-periodic structure that a set of dominant periods can describe, and when the task is one of those the design targets: long-horizon forecasting, imputation, anomaly detection or classification. It is a reasonable candidate when several overlapping cycles are expected, such as hourly observations with both daily and weekly rhythms. Avoid it when the signal is largely aperiodic or stochastic, because period-based reshaping then has little structure to exploit. It is also a weaker choice for very short series, where FFT frequency resolution is coarse and the detected periods may reflect noise. The Inception-based backbone is heavier than linear baselines, so under tight compute budgets a lighter model should be compared first. PatchTST, listed among related methods, is a natural comparison when patch-based attention is the alternative under consideration.

Limitations and considerations

  • Period detection assumes that the largest spectral peaks are the most informative. Irregular or non-stationary series can show strong spectral peaks that do not reflect stable structure, so the detected periods may mislead the reshape.
  • Padding the series to a whole number of periods adds artificial values at the end, and their effect is largest for predictions near that boundary.
  • Computational cost grows with the number of detected periods k, since each period has its own 2D branch, and with sequence length through the size of the 2D maps.
  • The Inception-based 2D backbone has many more parameters than lightweight linear or MLP baselines, which matters when training data are limited.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Recasts one-dimensional temporal modelling as 2D convolution, so the model can reuse convolutional operations developed for image data instead of attention over the time axis.
  • Derives its periods from the spectrum of each dataset, so the 2D reshapes follow the rhythms that are present rather than a fixed calendar assumption.
  • A single architecture covers forecasting, imputation, classification and anomaly detection.
  • The TimesBlock is modular, so the 2D backbone can in principle be replaced by other 2D convolutional modules.

Applications

  • Load forecasting for electricity and traffic series, which often show daily and weekly cycles.
  • Anomaly detection in industrial sensor streams from machinery that operates in repeated cycles.
  • Classification or imputation of quasi-periodic physiological signals such as ECG.
  • Forecasting of weather variables that exhibit seasonal structure.

How it works

How it works

1

The input is transformed with an FFT, and the amplitude spectrum is averaged across channels, so one set of frequencies serves all channels. The top-k frequencies with the largest averaged amplitudes are kept, and each frequency f_i gives a period p_i = ⌈T / f_i⌉ that sets the reshape for that branch. The number of frequencies k is a hyperparameter chosen by the user. It is usually tuned on validation data rather than inferred by the period-detection step itself.

Formula
\text{Given input } \mathbf{X} \in \mathbb{R}^{T \times C}, \text{ compute amplitude spectrum } A = \text{Avg}(|\text{FFT}(\mathbf{X})|) \text{ and select top-}k \text{ dominant frequencies } f_1, \dots, f_k \text{ with periods } p_i = \lceil T / f_i \rceil.
2

For each period p_i, the series is padded at its end up to the next multiple of p_i, that is p_i · ⌈T / p_i⌉, and reshaped into a matrix with ⌈T / p_i⌉ rows and p_i columns. Each row covers one period, so horizontally adjacent entries are temporally adjacent within a cycle, and vertically adjacent entries occupy the same phase in consecutive cycles.

Formula
\text{For each period } p_i, \text{ pad } \mathbf{X} \text{ to length } p_i \cdot \lceil T/p_i \rceil \text{ then reshape to } \mathbf{X}^{2D}_i \in \mathbb{R}^{\lceil T/p_i \rceil \times p_i \times C}, \text{ yielding a 2D temporal map capturing intraperiod and interperiod variation.
3

Each 2D map is processed by a TimesBlock whose backbone is an Inception block, a 2D convolutional module with multi-scale kernels. The same backbone is applied to every period-derived map. The multi-scale kernels are intended to capture both fine intraperiod patterns and coarser interperiod trends in the same pass.

Formula
\text{Apply a 2D convolutional backbone (Inception block) } \mathcal{F}_{2D}(\cdot) \text{ to each } \mathbf{X}^{2D}_i \text{ to extract joint intra- and inter-period features: } \hat{\mathbf{X}}^{2D}_i = \mathcal{F}_{2D}(\mathbf{X}^{2D}_i).
4

The processed 2D maps are truncated back to the original length T and converted to one-dimensional form. They are then summed with weights w_i computed from the averaged spectral amplitudes of the selected frequencies, which gives more weight to the more dominant periodicities. A linear projection head maps the fused representation to the task output, such as forecasts, reconstructions or classification logits.

Formula
\text{Truncate each } \hat{\mathbf{X}}^{2D}_i \text{ back to 1D and fuse via amplitude-weighted summation: } \hat{\mathbf{X}} = \sum_{i=1}^{k} w_i \cdot \text{Reshape1D}(\hat{\mathbf{X}}^{2D}_i), \text{ then project with a linear forecasting head.}

Common pitfalls

  • Setting k too large admits weak spectral peaks as periods and adds noisy branches to the fused output. Keep k small and check the sensitivity of results to it on validation data.
  • Applying the model to data without meaningful periodicity, such as random-walk returns, gives the reshaping little to work with, so gains over simpler baselines are unlikely and overfitting is a risk.
  • The detected periods depend on the input window length T, so changing the lookback window changes the reshape itself. Benchmark numbers are only comparable when lookback length and prediction horizon match.

Frequently asked questions

How does TimesNet differ from Transformer-based forecasters like Autoformer?

Autoformer, a related Transformer-based forecaster, models temporal dependencies in the one-dimensional time domain using series decomposition and auto-correlation. TimesNet does not use attention. It reshapes the series into 2D maps according to FFT-detected periods and applies 2D convolutions to them. The main practical difference is the inductive bias: TimesNet encodes periodicity through the reshape, whereas attention-based models must learn temporal dependencies from the data.

Can TimesNet handle multivariate series where channels have different dominant periods?

Period detection averages the FFT amplitude spectrum across all channels, so a single set of periods is shared by all channels. The model therefore assumes that channels share dominant periodicities. For datasets with strongly heterogeneous channel rhythms, channel-independent variants or channel-specific period detection may be more appropriate.

Is TimesNet suitable for very short time series?

Period detection becomes unreliable for very short series because frequency resolution depends on sequence length. With a short input, the detected periods may reflect noise rather than real cycles, and the reshaped matrix may have very few rows. Simpler MLP or recurrent models are generally a safer first choice in that regime.

Related methods

Sources

  1. Wu, H., Hu, T., Liu, Y., Zhou, H., Wang, J., & Long, M. (2023). TimesNet: Temporal 2D-variation modeling for general time series analysis. ICLR.

    Open publication reference