TIME SERIES FORECASTING
Year: 2022

Abstract:
Deep learning has been actively studied for time series forecasting, and the mainstream paradigm is based on the end-to-end training of neural network architectures, ranging from classical LSTM/RNNs to more recent TCNs and Transformers. Motivated by the recent success of representation learning in computer vision and natural language processing, we argue that a more promising paradigm for time series forecasting, is to first learn disentangled feature representations, followed by a simple regression fine-tuning step – we justify such a paradigm from a causal perspective. Following this principle, we propose a new time series representation learning framework for long sequence time series forecasting named CoST, which applies contrastive learning methods to learn disentangled seasonal-trend representations. CoST comprises both time domain and frequency domain contrastive losses to learn discriminative trend and seasonal representations, respectively. Extensive experiments on real-world datasets show that CoST consistently outperforms the state-of-the-art methods by a considerable margin, achieving a 21.3% improvement in MSE on multivariate benchmarks. It is also robust to various choices of backbone encoders, as well as downstream regressors. Code is available at https://github.com/salesforce/CoST.

text: 1 INTRODUCTION
Time series forecasting has been widely applied to various domains, such as electricity pricing (Cuaresma et al., 2004), demand forecasting (Carbonneau et al., 2008), capacity planning and management (Kim, 2003), and anomaly detection (Laptev et al., 2017). Recently, there has been a surge of efforts applying deep learning for forecasting (Wen et al., 2017; Bai et al., 2018; Zhou et al., 2021), and owing to the increase in data availability and computational resources, these approaches have offered promising performance over conventional methods in forecasting literature. Compared to conventional approaches, these methods are able to jointly learn feature representations and the prediction function (or forecasting function) by stacking a series of non-linear layers to perform feature extraction, followed by a regression layer focused on forecasting.
However, jointly learning these layers end-to-end from observed data may lead to the model over-fitting and capturing spurious correlations of the unpredictable noise contained in the observed data. The situation is exacerbated when the learned representations are
entangled – when a single dimension of the feature representation encodes information from multiple local independent modules of the data-generating process – and a local independent module experiences a distribution shift. Figure 1 is an example of such a case, where the observed time series is generated by a seasonal module and nonlinear trend module. If we know that the seasonal module has experienced a distribution shift, we could still makes a reasonable prediction based on
the invariant trend module. However, if we learn an entangled feature representation from the observed data, it would be challenging for the learned model to handle this distribution shift, even if it only happens in a local component of the data-generating process. In summary, the learned representations and prediction associations from the end-to-end training approach are unable to transfer nor generalize well when the data is generated from a non-stationary environment, a very common scenario in the time series analysis. Therefore, in this work, we take a step back and aim to learn disentangled seasonal-trend representations which are more useful for time series forecasting.
To achieve this goal, we leverage the idea of structural time series models (Scott & Varian, 2015; Qiu et al., 2018), which formulates time series as a sum of trend, seasonal and error variables, and exploit such prior knowledge to learn time series representations. First, we present the necessity of learning disentangled seasonal-trend representations through a causal lens, and demonstrate that such representations are robust to interventions on the error variable. Then, inspired by Mitrovic et al. (2020), we propose to simulate interventions on the error variable via data augmentations and learn the disentangled seasonal-trend representations via contrastive learning.
Based on the above motivations, we propose a novel contrastive learning framework to learn disentangled seasonal-trend representations for the Long Sequence Time-series Forecasting (LSTF) task (Zhou et al., 2021). Specifically, CoST leverages inductive biases in the model architecture to learn disentangled seasonal-trend representations. CoST efficiently learns trend representations, mitigating the problem of lookback window selection by introducing a mixture of auto-regressive experts. It also learns more powerful seasonal representations by leveraging a learnable Fourier layer which enables intra-frequency interactions. Both trend and seasonal representations are learned via contrastive loss functions. The trend representations are learned in the time domain, whereas the seasonal representations are learned via a novel frequency domain contrastive loss which encourages discriminative seasonal representations and side steps the issue of determining the period of seasonal patterns present in the data. The contributions of our work are as follows:
1. We show via a causal perspective, the benefits of learning disentangled seasonal-trend representations for time series forecasting via contrastive learning.
2. We propose CoST, a time series representation learning approach which leverages inductive biases in the model architecture to learn disentangled seasonal and trend representations, as well as incorporating a novel frequency domain contrastive loss to encourage discriminative seasonal representations.
3. CoST outperforms existing state-of-the-art approaches by a considerable margin on realworld benchmarks – 21.3% improvement in MSE for the multivariate setting. We also analyze the benefits of each proposed module, and establish that CoST is robust to various choices of backbone encoders and downstream regressors via extensive ablation studies.

heading: 2 SEASONAL-TREND REPRESENTATIONS FOR TIME SERIES
text: Problem Formulation Let (x1, . . .xT ) ∈ RT×m be a time series, where m is the dimension of observed signals. Given lookback window h, our goal is to forecast the next k steps, X̂ = g(X), where X ∈ Rh×m, X̂ ∈ Rk×m, and g(·) denotes the prediction mapping function, and X̂ predicts the next k time steps of X .
In this work, instead of jointly learning the representation and prediction association through g(·), we focus on learning feature representations from observed data, with the goal of improving predictive performance. Formally, we aim to learn a nonlinear feature embedding function V = f(X), where X ∈ Rh×m and V ∈ Rh×d, to project m-dimensional raw signals into a d-dimensional latent space for each timestamp. Subsequently, the learned representation of the final timestamp vh is used as inputs for the downstream regressor of the forecasting task.
Disentangled Seasonal-Trend Representation Learning and Its Causal Interpretation As discussed in Bengio et al. (2013), complex data arise from the rich interaction of multiple sources – a good representation should be able to disentangle the various explanatory sources, making it robust to complex and richly structured variations. Not doing so may otherwise lead to capturing spurious features that do not transfer well under non i.i.d. data distribution settings.
To achieve this goal, it is necessary to introduce structural priors for time series. Here, we borrow ideas from Bayesian Structural Time Series models (Scott & Varian, 2015; Qiu et al., 2018). As illustrated in the causal graph in Figure 2, we assume that the observed time series data X is generated from the error variable E and the error-free latent variable X?. X? in turn, is generated from the trend variable T and seasonal variable S. As E is not predictable, the optimal prediction can be achieved if we are able to uncover X? which only depends on T and S.
Firstly, we highlight that existing work using end-to-end deep forecasting methods to directly model the time-lagged relationship and the multivariate interactions along the observed data X . Unfortunately, each X includes unpredictable noise E, which might lead to capturing spurious correlations. Thus, we aim to learn the error-free latent variable X?.
Secondly, by the independent mechanisms assumption (Peters et al., 2017; Parascandolo et al., 2018), we can see that the seasonal and trend modules do not influence or inform each other. Therefore, even if one mechanism changes due to a distribution shift, the other remains unchanged. The design of disentangling seasonality and trend leads to better transfer, or generalization in nonstationary environments. Furthermore, independent seasonal and trend mechanisms can be learned independently and be flexibly re-used and re-purposed.
We can see that interventions on E does not influence the conditional distribution P (X?|T, S), i.e. P do(E=ei)(X?|T, S) = P do(E=ej)(X?|T, S), for any ei, ej in the domain of E. Thus, S and T are invariant under changes in E. Learning representations for S and T allows us to find a stable association with the optimal prediction (of X?) in terms of various types of errors. Since the targets X? are unknown, we construct a proxy contrastive learning task inspired by Mitrovic et al. (2020). Specifically, we use data augmentations as interventions on the error E and learn invariant representations of T and S via contrastive learning. Since it is impossible to generate all possible variations of errors, we select three typical augmentations: scale, shift and jitter, which can simulate a large and diverse set of errors, beneficial for learning better representations.

heading: 3 SEASONAL-TREND CONTRASTIVE LEARNING FRAMEWORK
text: In this section, we introduce our proposed CoST framework to learn disentangled seasonal-trend representations. We aim to learn representations such that for each time step, we have the disentangled representations for seasonal and trend components, i.e., V = [V (T );V (S)] ∈ Rh×d, where V (T ) ∈ Rh×dT and V (S) ∈ Rh×dS , such that d = dT + dS . Figure 3a illustrates our overall framework. Firstly, we make use of an encoder backbone fb : Rh×m → Rh×d to map the observations to latent space. Next, we construct both the trend and seasonal representations from these intermediate representations. Specifically, the Trend Feature Disentangler (TFD), fT : Rh×d → Rh×dT , extracts the trend representations via a mixture of autoregressive experts and is learned via a time domain contrastive loss Ltime. The Seasonal Feature Disentangler (SFD), fS : Rh×d → Rh×dS , extracts the seasonal representations via a learnable Fourier layer and is learned by a frequency domain contrastive loss which includes an amplitude component, Lamp, and a phase component, Lphase. We give a detailed description of both components in the next section. The model is learned in an end-to-end fashion, with the overall loss function being
L = Ltime + α
2 (Lamp + Lphase),
where α is a hyper-parameter which balances the trade-off between trend and seasonal factors. Finally, we concatenate the outputs of the Trend and Seasonal Feature Disentanglers to obtain our final output representations.

heading: 3.1 TREND FEATURE REPRESENTATIONS
text: Extracting the underlying trend is crucial for modeling time series. Auto-regressive filtering is one widely used method, as it is able to capture time-lagged causal relationships from past observations. One challenging problem is to select the appropriate lookback window – a smaller window leads to under-fitting, while a larger model leads to over-fitting and over-parameterization issues. A straightforward solution is to optimize this hyper-parameter by grid search on the training or validation loss (Hyndman & Khandakar, 2008), but such an approach is too computationally expensive. Thus, we propose to use a mixture of auto-regressive experts which can adaptively select the appropriate lookback window.
Trend Feature Disentangler (TFD) As illustrated in Figure 3b, the TFD is a mixture of L+1 autoregressive experts, where L = blog2(h/2)c. Each expert is implemented as a 1d causal convolution with d input channels and dT output channels, where the kernel size of the i-th expert is 2i. Each expert outputs a matrix Ṽ (T,i) = CausalConv(Ṽ , 2i). Finally, an average-pooling operation is performed over the outputs to obtain the final trend representations,
V (T ) = AvePool(Ṽ (T,0), Ṽ (T,1), . . . , Ṽ (T,L)) = 1
(L+ 1) L∑ i=0 Ṽ (T,i).
Time Domain Contrastive Loss We employ a contrastive loss in the time domain to learn discriminative trend representations. Specifically, we apply the MoCo (He et al., 2020) variant of contrastive learning which makes use of a momentum encoder to obtain representations of the positive pair, and a dynamic dictionary with a queue to obtain negative pairs. We elaborate further on the details of contrastive learning in Appendix A. Then, given N samples and K negative samples, the time domain contrastive loss is
Ltime = N∑ i=1 − log exp(qi · ki/τ) exp(qi · ki/τ) + ∑K j=1 exp(qi · kj/τ) ,
where given a sample V (T ), we first select a random time step t for the contrastive loss and apply a projection head, which is a one-layer MLP to obtain q, and k is respectively the augmented version of the corresponding sample from the momentum encoder/dynamic dictionary.

heading: 3.2 SEASONAL FEATURE REPRESENTATIONS
text: Spectral analysis in the frequency domain has been widely used in seasonality detection (Shumway et al., 2000). Thus, we turn to the frequency domain to handle the learning of seasonal representations. To do so, we aim to address two issues: i) how can we support intra-frequency interactions (between feature dimensions) which allows the representations to encode periodic information more easily, and, ii) what kind of learning signal is required to learn representations which are able to discriminate between different seasonality patterns? Standard backbone architectures are unable to easily capture intra-frequency level interactions, thus, we introduce the SFD which makes use of a learnable Fourier layer. Then, in order to learn these seasonal features without prior knowledge of the periodicity, a frequency domain contrastive loss is introduced for each frequency.
Seasonal Feature Disentangler (SFD) As illustrated in Figure 3c, the SFD is primarily composed of a discrete Fourier transform (DFT) to map the intermediate features to frequency domain, followed by a learnable Fourier layer. We include further details and definitions of the DFT in Appendix B. The DFT is applied along the temporal dimension and maps the time domain representations into the frequency domain, F(Ṽ ) ∈ CF×d, where F = bh/2c + 1 is the number of frequencies. Next, the learnable Fourier layer, which enables frequency domain interactions, is implemented via a perelement linear layer. It applies an affine transform on each frequency, with a unique set of complexvalued parameters for each frequency, since we do not expect this layer to be translation invariant. Finally, we transform the representation back to time domain using an inverse DFT operation.
The final output matrix of this layer is the seasonal representation, V (S) ∈ Rh×dS . Formally, we can denote the i, k-th element of the output as
V (S) i,k = F −1 ( d∑ j=1 Ai,j,kF(Ṽ )i,j +Bi,k ) ,
where A ∈ CF×d×dS ,B ∈ CF×dS are the parameters of the per-element linear layer. Frequency Domain Contrastive Loss As illustrated in Figure 3c, the inputs to the frequency domain loss functions are the pre-iFFT representations, denoted by F ∈ CF×dS . These are complexvalued representations in the frequency domain. To learn representations which are able to discriminate between different seasonal patterns, we introduce a frequency domain loss function. As our data augmentations can be interpreted as interventions on the error variable, the seasonal information does not change and thus, a contrastive loss in frequency domain corresponds to discriminating between different periodic patterns given a frequency. To overcome the issue of constructing a loss function with complex-valued representations, each frequency can be uniquely represented by its amplitude and phase representations, |Fi,:| and φ(Fi,:). Then, the loss functions are denoted,
Lamp = 1
FN F∑ i=0 N∑ j=1 − log exp(|F (j)i,: | · |(F (j) i,: ) ′|) exp(|F (j)i,: | · |(F (j) i,: ) ′|) + ∑N k 6=j exp(|F (j) i,: | · |F (k) i,: |) ,
Lphase = 1
FN F∑ i=0 N∑ j=1 − log exp(φ(F (j) i,: ) · φ((F (j) i,: ) ′)) exp(φ(F (j) i,: ) · φ((F (j) i,: ) ′)) + ∑N k 6=j exp(φ(F (j) i,: ) · φ(F (k) i,: )) ,
where F (j)i,: is the j-th sample in a mini-batch, and (F (j) i,: ) ′ is the augmented version of that sample.

heading: 4 EXPERIMENTS
text: In this section, we report the results of a detailed empirical analysis of CoST and compare it against a diverse set of time series representation learning approaches, as well as compare against end-to-end supervised forecasting methods. Appendix F contains further results on runtime analysis.

heading: 4.1 EXPERIMENTAL SETUP
text: Datasets We conduct extensive experiments on five real-world public benchmark datasets. ETT (Electricity Transformer Temperature)1 (Zhou et al., 2021) consists of two hourly-level datasets (ETTh) and one 15-minute-level dataset (ETTm), measuring six power load features and “oil temperature”, the chosen target value for univariate forecasting. Electricity2 measures the electricity consumption of 321 clients, and following popular benchmarks, we convert the dataset into hourlylevel measurements and set “MT 320” as the target value for univariate forecasting. Weather3 is an hourly-level dataset containing 11 climate features from nearly 1,600 locations in the U.S., and we take “wet bulb” as the target value for univariate forecasting. Finally, we also include the M5 dataset (Makridakis et al., 2020) in Appendix J.
Evaluation Setup Following prior work, we perform experiments on two settings – multivariate and univariate forecasting. The multivariate setting involves multivariate inputs and outputs, considering all dimensions of the dataset. The univariate setting involves univariate inputs and outputs, which are the target values described above. We use MSE and MAE as evaluation metrics, and perform a 60/20/20 train/validation/test split. Inputs are zero-mean normalized and evaluated over various prediction lengths. Following (Yue et al., 2021), self-supervised learning approaches are first trained on the train split, and a ridge regression model is trained on top of the learned representations to directly forecast the entire prediction length. The validation set is used to choose the appropriate ridge regression regularization term α, over a search space of {0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000}. Evaluation results are reported on the test set. Implementation Details For CoST and all other representation learning methods, the backbone encoder used is a Temporal Convolution Network (following similar practice in TS2Vec (Yue et al., 2021)) unless the approach includes or is an architectural modification (further details in Appendix E). All methods used have a representation dimensionality of 320. We use a standard hyper-parameter setting on all datasets – a batch size of 256 and learning rate of 1E−3, momentum of 0.9 and weight decay of 1E−4 with SGD optimizer and cosine annealing. The MoCo implementation for time domain contrastive loss uses a queue size of 256, momentum of 0.999, and temperature of 0.07. We train for 200 iterations for datasets with less than 100,000 samples, and 600 iterations otherwise. Details on data augmentations used in CoST can be found in Appendix C.

heading: 4.2 RESULTS
text: Among the baselines, we report the performance of representation learning techniques including TS2Vec, TNC, and a time series adaptation of MoCo in our main results. A more extensive benchmark of feature-based forecasting approaches can be found in Appendix H due to space limitations. Further details about the baselines can be found in Appendix E. We include supervised forecasting approaches - two Transformer based models, Informer (Zhou et al., 2021) and LogTrans(Li et al., 2020), and the backbone TCN trained directly on an end-to-end forecasting loss. A comparison of end-to-end forecasting approaches can be found in Appendix I.
Table 1 summarizes the results of CoST and top performing baselines for the multivariate setting, and Table 7 (in Appendix G due to space limitations) for the univariate setting. For end-to-end forecasting approaches, the TCN generally outperforms the Transformer based approaches, Informer and LogTrans. At the same time, the representation learning methods outperform end-to-end forecasting approaches, but there are indeed cases, such as in certain datasets for the univariate setting, where the end-to-end TCN performs surprisingly well. While Transformers have been shown to
1https://github.com/zhouhaoyi/ETDataset 2https://archive.ics.uci.edu/ml/datasets/ElectricityLoadDiagrams20112014 3https://www.ncei.noaa.gov/data/local-climatological-data/
be powerful models in other domains like NLP, this suggests that TCN models are still a powerful baseline which should still be considered for time series.
Overall, our approach achieves state-of-the-art performance, beating the best performing end-toend forecasting approach by 39.3% and 18.22% (MSE) in the multivariate and univariate settings respectively. CoST also beats next best performing feature-based approach by 21.3% and 4.71% (MSE) in the multivariate and univariate settings respectively. This indicates that CoST learns more relevant features by learning a composition of trend and seasonal features which are crucial for forecasting tasks.

heading: 4.3 PARAMETER SENSITIVITY
text: α controls the weightage of the seasonal components in the overall loss function, L = Ltime + α 2 (Lamp + Lphase). We perform a sensitivity analysis on this hyper-parameter (Table 2) and show that an optimal value can be chosen and is robust across various settings. We choose α = 5E−04 for all other experiments since it performs well on both multivariate and univariate settings. We note that the small values of α stems from the frequency domain contrastive loss being generally three orders of magnitude larger than the time domain contrastive loss, rather than being an indicator that the seasonal component has lower importance than the trend component. Further, we highlight that overall, while choosing a smaller value of α leads to better performance on most datasets, there are certain cases for which a larger α might be preferred, as seen in the lower portion of Table 2.

heading: 4.4 ABLATION STUDY
text: Components of CoST We first perform an ablation study to understand the performance benefits brought by each component in CoST. Table 3 presents the average results over the ETT datasets on all forecast horizon settings (similarly for Tables 4 and 5). We show that both trend and seasonal components improve performance over the baselines (SimCLR and MoCo), and further, the composition of trend and seasonal components leads to the optimal performance. We further verify that training our proposed model architecture end-to-end with a supervised forecasting loss leads to worse performance.
Backbones Next, we verify that our proposed trend and seasonal components as well as contrastive loss (both time and frequency domain) are robust to various backbone encoders. TCN is the default backbone encoder used in all other experiments and we present results on LSTM and Transformer backbone encoders of equivalent parameter size. While performance using the TCN backbone outperforms LSTM and Transformer, we show that our approach outperforms the competing approach on all three settings.
Regressors Finally, we show that CoST is also robust to various regressors used for forecasting. Apart from a ridge regression model, we also perform experiments on a linear regression model and a kernel ridge regression model with RBF kernel. As shown in Table 5, we also demonstrate that CoST outperforms the competing baseline on all three settings.
4.5 CASE STUDY
We visualize the learned representations on a simple synthetic time series with both seasonal and trend components, and show that CoST is able to learn representations which are able to discriminate between various seasonal and trend patterns. The synthetic dataset is generated by defining two trend and three seasonal patterns, and taking the cross product to form six time series (details in Appendix D). After training the encoders on the synthetic dataset, we can visualize them via the T-SNE algorithm (Van der Maaten & Hinton, 2008). Figure 4 shows that our approach is able to learn both the trend and seasonal patterns from the dataset and the learned representations has high clusterability, whereas TS2Vec is unable to distinguish between various seasonal patterns.

heading: 5 RELATED WORK
text: Deep forecasting has typically been tackled as an end-to-end supervised learning task, where early work considered using RNN based models (Lai et al., 2018) as a natural approach to modeling time series data. Recent work have also considered adapting Transformer based models for time series forecasting (Li et al., 2020; Zhou et al., 2021), specifically focusing on tackling the quadratic space complexity of Transformer models. Oreshkin et al. (2020) proposed a univariate deep forecasting model and showed that deep models outperform classical time series forecasting techniques.
While recent work in time series representation learning focused on various aspects of representation learning such how to sample contrastive pairs (Franceschi et al., 2020; Tonekaboni et al., 2021), taking a Transformer based approach (Zerveas et al., 2021), exploring complex contrastive learning tasks (Eldele et al., 2021), as well as constructing temporally hierarchical representations (Yue et al., 2021), none have touched upon learning representations composed of trend and seasonal features. Whereas existing work have focused exclusively on time series classification tasks, Yue et al. (2021) first showed that time series representations learned via contrastive learning establishes a new stateof-the-art performance on deep forecasting benchmarks.
Classical time series decomposition techniques (Hyndman & Athanasopoulos, 2018) have been used to decompose time series into seasonal and trend components to attain interpretability. There has been recent work on developing more robust and efficient decomposition approaches (Wen et al., 2018; 2020; Yang et al., 2021). These methods focus decomposing the raw time series into trend and seasonal components which are still interpreted as time series in the original input space rather than learning representations. Godfrey & Gashler (2017) presents an initial attempt to use neural networks to model periodic and non-periodic components in time series data, leveraging periodic activation functions to model the periodic components. Different from our work, such a method is only able to model a single time series per model, rather than produce the decomposed seasonaltrend representations given a lookback window.

heading: 6 CONCLUSION
text: Our work shows separating the representation learning and downstream forecasting task to be a more promising paradigm than the standard end-to-end supervised training approach for time-series forecasting. We show this empirically, and also explain it through a causal perspective. By following this principle, we proposed CoST, a contrastive learning framework that learns disentangled seasonal-trend representations for time series forecasting tasks. Extensive empirical analysis shows that CoST outperforms the previous state-of-the-art approaches by a considerable margin and is robust to various choices of backbone encoders and regressors. Future work will extend our framework for other time-series intelligence tasks.

heading: A CONTRASTIVE LEARNING
text: Contrastive learning via the instance discrimination task is a powerful approach for self-supervised learning. Here, we describe the essentials of this method, which underpins our proposed approach. Firstly, a family of data augmentations, A, is defined. Given a single sample of data xi ∈ X, two data augmentation operators are sampled, a ∼ A, a′ ∼ A. qi = f(a(xi)) is referred to as the query representation with encoder f , and ki = f(a′(xi)) is the positive key representation. Finally, the InfoNCE loss function is
LInfoNCE = N∑ i=1 − log exp(qi · ki/τ) exp(qi · ki/τ) + ∑K j=1 exp(qi · kj/τ) ,
where τ is the temperature hyper-parameter, kj are negative key representations, and K is the total number of negative samples. Standard approaches use an efficient mechanism to obtain negative samples - by simply treating all other samples in the mini-batch as negative samples, i.e. K = N−1. MoCo (He et al., 2020) introduces the idea of a using a queue of sizeK (a hyper-parameter) to obtain negative samples. At each iteration of training, simply pop N samples from the queue, and push the N representations form the current mini-batch.

heading: B DISCRETE FOURIER TRANSFORM
text: The DFT provides a frequency domain view of a given sequence, x = (x0, x1, . . . , xN−1), mapping a time series with regular intervals into the Fourier coefficients, a sequence of complex numbers of equal length. Due to the conjugate symmetry of the DFT of real-valued signals, we can simply consider the first bN/2c+ 1 Fourier coefficients, c = F(x) ∈ CbN/2c+1.
ck = F(x)k = N−1∑ n=0 xn · exp(−i2πkn/N).
Each complex component, ck, can be represented by the amplitude, |ck|, and the phase, φ(ck),
|ck| = √ R{ck}2 + I{ck}2 φ(ck) = tan−1 ( I{ck} R{ck} ) where R{ck} and I{ck} are the real and imaginary components of ck respectively. Finally, the inverse DFT maps the frequency domain representation back to the time domain,
xn = F−1(c)n = 1
N N−1∑ k=0 ck · exp(i2πkn/N).

heading: C DATA AUGMENTATIONS
text: In our experiments, we utilize a composition of three data augmentations, applied in the following order - scaling, shifting, and jittering, activating with a probability of 0.5.
Scaling The time-series is scaled by a single random scalar value, obtained by sampling ∼ N (0, 0.5), and each time step is x̃t = xt.
Shifting The time-series is shifted by a single random scalar value, obtained by sampling ∼ N (0, 0.5) and each time step is x̃t = xt + .
Jittering I.I.D. Gaussian noise is added to each time step, from a distribution t ∼ N (0, 0.5), where each time step is now x̃t = xt + t.

heading: D SYNTHETIC DATA GENERATION
text: We first construct two trend patterns. The first trend patterns follows a nonlinear, saturating pattern, yt =
1 1+exp β0(t−β1) + t for β0 = 0.2, β1 = 60, t ∼ N (0, 0.3). The second pattern is a mixture of
ARMA process, ARMA(2, 2) + ARMA(3, 3) + ARMA(4, 4), where the AR and MA parameters are as follows, ({.9, -.1}, {.2, -.5}), ({.1, .2, .3}, {.1, .65, -.45}), ({.3, .5, -.5, -.3}, {.1, .1, -.2, - .3}). Next, we construct three seasonal patterns, consisting of sine waves with the following period, phase, and amplitudes, {20, 0, 3}, {50, .2, 3}, {100, .5, 3}. The final time series are constructed as follows, generate a trend pattern g(t) and seasonal pattern s(t), the final time series is y(t) = g(t) + s(t), t = 0, . . . , 999. We do this for all pairs of trend and seasonal patterns, constructing a total of 6 time series.

heading: E DETAILS ON BASELINES
text: Results for TS2Vec, TNC, MoCo, Triplet, CPC, TST, TCC are based on our reproduction, while results for Informer, LogTrans, and LSTNet (Lai et al., 2018) are directly taken from Yue et al. (2021) for the ETT and Electricity datasets, and Zhou et al. (2021) for the Weather dataset. For all reproduced approaches, we train for 200 iterations for datasets with less than 100,000 samples, otherwise, and 600 iterations otherwise.
The encoders used in all approaches except Triplet and TST is the causal TCN encoder as proposed in TS2Vec (Yue et al., 2021). A fully connected layer is first used to project each time step from the dimensionality of the multivariate time series to the hidden channel (size 64). Then, there are 10 layers of convolution blocks. Each convolution block is a sequence of GELU, DilatedConv, GELU, DilatedConv, with skip connections across each block. The DilatedConvs have dilation of 2i in each layer i of convolution block, all have kernel size of 3 and input/output channel size of 64. A final convolution block is used to map the hidden channels to the output channel (size 320).
For Triplet, the encoder is their proposed causal TCN encoder, while for TST, their proposed Transformer encoder is used. Further details can be found in their respective papers.
TS2Vec (Yue et al., 2021) TS2Vec was recently proposed as a universal framework for learning time series representations by performing contrastive learning in a hierarchical manner over augmented context views. They propose to learn timestamp level representations. We ran the code from their open source repository4 as is, hyper-parameters used are all defaults as suggested in their paper.
TNC (Tonekaboni et al., 2021) TNC proposes a self-supervised framework for learning generalizable representations for non-stationary time series. They make use of the augmented Dickey-Fuller test for stationarity to ensure positive samples come from the a neighborhood of similar signals. We use their open source code5, setting w = 0.005 in the loss function, mc sample size = 20, batch size of 8, and learning rate of 1E−3 with Adam optimizer.
MoCo (He et al., 2020) MoCo is a popular self-supervised learning baseline in computer vision, and we implement a time series version of MoCo using their open source code6. We use a batch size of 128, queue of 256, momentum for the momentum encoder is 0.999, temperature of the loss function is 0.07, learning rate of 1E−3 with SGD optimizer, with cosine annealing. Data augmentations used are described in Appendix C.
Triplet (Franceschi et al., 2020) Triplet proposes a time series self-supervised learning approach by taking positive samples to be substrings of the anchor, and negative samples to be randomly sampled from the dataset. We reproduce their approach by adapting their open source code7, making use of their proposed causal TCN model architecture. We use a batch size of 10, and learning rate 1E−3 with AdamW optimizer.
CPC (van den Oord et al., 2019) CPC learns representations by predicting the future in latent space using auto-regressive models. They use a probabilistic contrastive loss which induces latent
4https://github.com/yuezhihan/ts2vec 5https://github.com/sanatonek/TNC representation learning 6https://github.com/facebookresearch/moco 7https://github.com/White-Link/UnsupervisedScalableRepresentationLearningTimeSeries
space to capture information maximally useful to predict future samples. We reproduce this approach by referencing an unofficial implementation8. We use a GRU for the AR module, use two prediction steps after eight AR steps. We use a batch size of 8 and learning rate of 1E−3 with AdamW optimizer.
TST (Zerveas et al., 2021) TST is a Transformer based approach using a reconstruction loss. We use the open source implementation9 as is.
TCC (Eldele et al., 2021) TCC introduces a temopral contrastive module and a tough cross-view prediction task. We use their open source implementation10. We use a learning rate of 3E−4 with Adam optimizerλ1 = 1, λ2 = 0.7 as in their implementation, and jitter scale ratio or 1.1, maximum segment length of 8, and jitter ratio of 0.8, following their HAR setting.

heading: F RUNTIME ANALYSIS
text: Table 6 shows the runtime in seconds for each phase for various representation learning methods and end-to-end approaches. All experiments are performed on an NVIDIA A100 GPU. Do note that for Informer, we follow the hyperparameters (including lookback window length) as described by the authors which may vary for different forecasting horizons, thus the runtime may not be strictly increasing as the forecasting horizon increases. We want to highlight that for all representation learning approaches, the ridge regressor portions should be equal since the dimension size used are the same across all methods, any differences are simply due to randomness. Despite a slightly higher training time compared to some of the baseline approaches, CoST achieves much better results (refer to Table 1 in the main paper). Furthermore, the extra computation time of CoST as compared to TS2Vec is due to the sequential computation of each expert in the mixture of AR expert component, it can be further accelerated by parallel methods (He et al., 2021).
8https://github.com/jefflai108/Contrastive-Predictive-Coding-PyTorch 9https://github.com/gzerveas/mvts transformer
10https://github.com/emadeldeen24/TS-TCC

heading: G UNIVARIATE FORECASTING BENCHMARK

heading: H RESULTS ON FEATURE-BASED FORECASTING BASELINES
text: We include hand-crafted features (using the same experiment methodology as representation learning approaches) in our benchmark, by using features from the TSFresh package. We select the same set of features for all datasets and settings, to avoid extensive feature engineering which requires domain expertise. TSFresh generally under performs in the multivariate benchmark due to the high dimensionality of the generated features, since it extracts univariate features and thus feature size increases linearly with input size. On the other hand, it performs relatively well on the univariate setting.

heading: I RESULTS ON END-TO-END FORECASTING BASELINES COMPARED TO COST

heading: J RESULTS ON M5 DATASETS

heading: K CASE STUDY: DISENTANGLEMENT
text: To exhibit CoST’s ability to disentangle trend and seasonal components, we plot the T-SNE representations of the Trend Feature Disentangler (TFD) and Seasonal Feature Disentangler (SFD) separately. From Figure 5a, we see that representations from the TFD indeed have better clusterability and the representations from SFD have a degree of overlap between the two trend patterns. From Figure 5b, we see that the TFD representations have a higher degree of overlap between the three seasonality patterns than the SFD representations. Here, to better highlight the stronger capability of seasonality representations in extracting seasonal patterns, we used complex seasonality patterns (described below).
Complex Seasonality Similar to the synthetic data generation process in Appendix D, we generate three different seasonality patterns before combining them with the two trend patterns. The first seasonality pattern is no seasonality. The second pattern begins with a sine wave of period, phase, and amplitude of {3, 0, 10}, thereafter, a mask is then applied to the entire pattern, consisting of a repeating pattern of three 1s and seven 0s. The third pattern begins with a sine wave of period, phase, and amplitude of {10, 0.5, 15}, thereafter, a mask is then applied to the entire pattern, consisting of a repeating pattern of two 1s and eight 0s.

Review summaries:
The current training paradigm applied in most time series forecasting approaches jointly learns feature representations and the prediction function. This paper argues that this paradigm may lead to several issues, e.g., overfitting problems, obtaining false relations of the unpredictable noise in the data, and entangling representations.  To tackle these challenges, this paper proposes a new framework (CoST) to first learn error-free feature representations, and then fine-tune the representations through a simple regressor. In the feature learning stage, a pretext task is constructed by using data augmentation and contrastive learning. The goal is to learn disentangled seasonal and trend representations. Moreover, time domain and frequency domain contrastive losses are incorporated to learn discriminative trends and seasonal representations, respectively. 

The paper proposes a contrastive learning framework for time series forecasting CoST. This is done by detangling trend and seasonal features than using the learnt feature representations with a simple regression. Trend feature disentangler consists of a mixture of autoregressive experts followed by average pooling. While the seasonal feature is done by changing the features into the frequency domain via FFT and then applying a linear layer with weights to every different frequency. The overall loss is the weighted time-domain contrastive loss from trend feature disentangler and frequency domain contrastive loss which contains both phase and amplitude loss from seasonal feature disentangler. The proposed method was evaluated on 5 datasets in both a multivariate and univariate setting. CoST was compared against different representation learning and end-to-end learning appraoches. 

This paper introduce a framework of learning disentangled trend and seasonal representations of time series and its application to forecasting tasks. It employs contrastive losses to distill discriminative trend and seasonal representations. DFT is used in obtaining frequency domain information. Empirical results show the proposed framework is able to outperform end-to-end trained forecasters and other representation learning methods. In addition, the learned representations can be clustered to distinguish multiple trends or seasonalities.

This paper proposes a novel way to represent time series learnt with contrastive losses in both the time and frequency domain for the forecasting task. The approach is novel and timely and is clearly described. The authors make a connection to causality which they use also for designing data augmentation schemes.