# Multivariate Time Series Deep Spatiotemporal Forecasting with Graph Neural Network
## 3 Methods
### Experiment Model  
The model structure of MDST-GNN is shown in Figure 3. It consists of four parts: a graph learning module, K temporal convolution modules, K graph convolution modules, and a down-sampling convolution module. The graph learning module is used to construct the spatial dependency graph of the data. The temporal convolution module captures the temporal information of the data. The spatiotemporal information is obtained by fusing the dependency graph and temporal information in the graph convolution module. The down-sampling convolution module extracts deep spatiotemporal information. Add residual connections to the model to avoid vanishing gradients during training. A skip connection is added after each temporal convolution module. To obtain the final output, the hidden features are projected onto the desired output dimension by convolution. Algorithm 1 shows the algorithm steps of the model.  
* Input: The raw data X of the multivariate time series.
* Output: The prediction result of data X after h (Horizon) steps. The value of h can take 3, 6, 12, and 24.
* Line 1-2: Preprocess the input raw data X. Normalize each sequence of a multivariate time series X. Divide X into training set (60%), validation set (20%), and test set (20%). The Xtrain and Ytrain are obtained by splitting the sequence X with a fixed-length sliding window. Xtrain represents the input data for training, and Ytrain represents the labels of the training data.
* Line 4: Construct the graph structure A of the multivariate time series. A represents the dependencies between different sequences in a multivariate time series by an adjacency matrix.
* Line 6: A 1 \(\times\) 1 convolutional network is used to obtain high-dimensional data in the channel dimension of Xtrain.
* Line 8: Add skip connection method to preserve part of the original information of each layer.
* Line 9: Perform a temporal convolution operation on the input data to obtain the temporal information of the data.
* Line 10: In the graph convolution, spatially weighted spatiotemporal information is obtained by multiplying the temporal information with an adjacency matrix A.
* Line 11: The output data are normalized using Layer Norm. Repeat Line 8 to Step 11 for L times. L represents the number of layers of the module.  
* Line 13: Perform down-sampling convolution operation on the obtained spatiotemporal information to extract deep spatiotemporal information.
* Line 14-15: Concatenate deep spatiotemporal information and skip connections information. The final output result is obtained through \(1\times 1\) convolutional dimensionality reduction information.
* Line 16-18: Reverse normalize the output of the model. The mean value (MAE) of the difference between the output and the true value is used as the loss function. The model parameters are updated according to the gradient, and the steps from Step 3 to Step 10 are repeated until the model finally converges to the minimum error.
* Line 21: Finally, input the test set into the trained model to obtain the prediction result.  
The above process can be divided into 4 parts. Line 1 to 2 is the data preprocessing part. Lines 4 to 15 are the MDST-GNN model training and fitting process. Line 16 to 18 is the loss function calculation part. Line 21 gives the final prediction result. The source code of the algorithm is available at [[https://github.com/yiminghzc/MDST-GNN](https://github.com/yiminghzc/MDST-GNN)]([https://github.com/yiminghzc/MDST-GNN](https://github.com/yiminghzc/MDST-GNN)) (accessed on 28 May 2022).