Home

Awesome

<h1 align="center"><ins>S</ins>patio-<ins>T</ins>emporal <ins>G</ins>raph <ins>C</ins>onvolutional <ins>N</ins>etworks: <br> A Deep Learning Framework for Traffic Forecasting</h1> <p align="center"> <a href="https://www.ijcai.org/proceedings/2018/0505.pdf"><img src="https://img.shields.io/badge/-Paper-grey?logo=read%20the%20docs&logoColor=green" alt="Paper"></a> <a href="https://github.com/VeritasYin/STGCN_IJCAI-18"><img src="https://img.shields.io/badge/-Github-grey?logo=github" alt="Github"></a> <a href="https://github.com/VeritasYin/STGCN_IJCAI-18/blob/master/LICENSE"><img src="https://img.shields.io/badge/License-BSD%202--Clause-red.svg"></a> <a href="https://pytorch-geometric-temporal.readthedocs.io/en/latest/modules/root.html#torch_geometric_temporal.nn.attention.stgcn.STConv"><img src="https://img.shields.io/badge/PyG_Temporal-STConv-blue" alt=PyG_Temporal"></a> <a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FVeritasYin%2FSTGCN_IJCAI-18&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=Hits&edge_flat=false"/></a> </p>

Introduction

We propose a novel deep learning framework, STGCN, to tackle time series prediction problem in traffic domain. Instead of applying regular convolutional and recurrent units, we formulate the problem on graphs and build the model with complete convolutional structures. To the best of our knowledge, it is the first time that to apply purely convolutional structures to extract spatio-temporal features simultaneously from graph-structured time series in a traffic study.

Problem Formulation

Traffic forecast is a typical time-series prediction problem, i.e. predicting the most likely traffic measurements (e.g. speed or traffic flow) in the next $H$ time steps given the previous $M$ observations from traffic network $G$ as,

<p align="center"> <img src="https://latex.codecogs.com/svg.image?\large&space;\hat{v}_{t&plus;1},&space;...,&space;\hat{v}_{t&plus;H}=\mathop{\arg\max}_{v_{t&plus;1},&space;...,&space;v_{t&plus;H}}&space;\log&space;P(v_{t&plus;1},&space;...,v_{t&plus;H}|v_{t-M&plus;1},&space;...,v_t;G)"/> </p> <p align="center"><img width="30%" height="30%" src="figures/Graph_Structured_Traffic_Data.png"></p>

Fig.1 Graph-structured traffic data.
Each $v_t$ indicates a frame of current traffic status at time step $t$, which is recorded in a graph-structured data matrix.

Network Structure

<p align="center"><img src="figures/STGCN.png" width="50%" height="50%"></p>

Fig. 2 Architecture of spatio-temporal graph convolutional networks.
The framework STGCN consists of two spatio-temporal convolutional blocks (ST-Conv blocks) and a fully-connected output layer in the end. Each ST-Conv block contains two temporal gated convolution layers and one spatial graph convolution layer in the middle. The residual connection and bottleneck strategy are applied inside each block. The input $v_{t-M+1}, ..., v_t$ is uniformly processed by ST-Conv blocks to explore spatial and temporal dependencies coherently. Comprehensive features are integrated by an output layer to generate the final prediction $\hat{v}$.

Results

ModelPeMSD7(M) (15/30/45 min)PeMSD7(L) (15/30/45 min)
/MAEMAPE(%)RMSEMAEMAPE(%)RMSE
HA4.0110.617.204.6012.508.05
LSVR2.50/3.63/4.545.81/8.88/11.504.55/6.67/8.282.69/3.85/4.796.27/9.48/12.424.88/7.10/8.72
ARIMA5.55/5.86/6.2712.92/13.94/15.209.00/9.13/9.385.50/5.87/6.3012.30/13.54/14.858.63/8.96/9.39
FNN2.74/4.02/5.046.38/9.72/12.384.75/6.98/8.582.74/3.92/4.787.11/10.89/13.564.87/7.02/8.46
FC-LSTM3.57/3.94/4.168.60/9.55/10.106.20/7.03/7.514.38/4.51/4.6611.10/11.41/11.697.68/7.94/8.20
GCGRU2.37/3.31/4.015.54/8.06/9.994.21/5.96/7.132.48/3.43/4.12∗5.76/8.45/10.51∗4.40/6.25/7.49∗
STGCN(Cheb)2.25/3.03/3.575.26/7.33/8.694.04/5.70/6.772.37/3.27/3.975.56/7.98/9.734.32/6.21/7.45
STGCN(1st)2.26/3.09/3.795.24/7.39/9.124.07/5.77/7.032.40/3.31/4.015.63/8.21/10.124.38/6.43/7.81

Table 1: Performance comparison of different approaches on the dataset PeMSD7.

<p align="center"><img src="figures/PeMS_R39.png" width="40%" height="30%"><img src="figures/PeMS_R141.png" width="40%" height="30%"></p>

Fig. 3: Speed prediction in the morning peak and evening rush hours of the dataset PeMSD7.

<p align="center"><img src="figures/PeMS_Train_Time.png" width="40%" height="30%"><img src="figures/PeMS_Train_Time_L.png" width="40%" height="30%"></p>

Fig. 4: Time consumptions of training on the dataset PeMSD7 (M, left) and (L, right)

Requirements

Our code is based on Python3 (>= 3.6). There are a few dependencies to run the code. The major libraries are listed as follows:

The implementation of Spatio-Temporal Graph Convolutional Layer with PyTorch is available in PyG Temporal. You might refer to STConv that supports ChebConv Graph Convolutions.

Dataset

Data Source

PeMSD7 was collected from Caltrans Performance Measurement System (PeMS) in real-time by over 39, 000 sensor stations, deployed across the major metropolitan areas of California state highway system. The dataset is also aggregated into 5-minute interval from 30-second data samples. We randomly select a medium and a large scale among the District 7 of California containing 228 and 1, 026 stations, labeled as PeMSD7(M) and PeMSD7(L), respectively, as data sources. The time range of PeMSD7 dataset is in the weekdays of May and June of 2012. We select the first month of historical speed records as training set, and the rest serves as validation and test set respectively.

Dataset PeMSD7(M/L) is now available under dataset folder (station list included). Please refer issue #6 for how to download metadata from PeMS.

Data Format

You can make your customized dataset by the following format:

Note: please replace the $num_route with the number of routes in your dataset. '*.csv' should not contain any index or header in the file.

Data Preprocessing

The standard time interval is set to 5 minutes. Thus, every node of the road graph contains 288 data points per day (day_slot = 288). The linear interpolation method is used to fill missing values after data cleaning. In addition, data input are normalized by Z-Score method.
In PeMSD7, the adjacency matrix of the road graph is computed based on the distances among stations in the traffic network. The weighted adjacency matrix W can be formed as,

<p align="center"> <img src="https://latex.codecogs.com/svg.image?\large&space;w_{ij}=\left\{&space;\begin{aligned}&space;&\exp(-\frac{{d_{ij}^2}}{{\sigma^2}}),~i&space;\neq&space;j~\text{and}~\exp(-\frac{{d_{ij}^2}}{{\sigma^2}})&space;\geq&space;\epsilon\\&space;&0\qquad\qquad,~\text{otherwise}.&space;\end{aligned}&space;\right."/> </p>

All of our experiments use 60 minutes as the historical time window, a.k.a. 12 observed data points (M = 12) are used to forecast traffic conditions in the next 15, 30, and 45 minutes (H = 3, 6, 9).

Model Details

Training

python main.py --n_route {$num_route} --graph {$weight_matrix_file}

Default settings:

Note: it normally takes around 6s on a NVIDIA TITAN Xp for one epoch with the batch size of 50 and n_route of 228.

Folder structure

├── data_loader
│   ├── data_utils.py
│   └── __init__.py
├── dataset
│   ├── PeMSD7_V_228.csv
│   ├── PeMSD7_W_228.csv
│   ├── PeMSD7_V_1026.csv
│   └── PeMSD7_W_1026.csv
├── main.py
├── models
│   ├── base_model.py
│   ├── __init__.py
│   ├── layers.py
│   ├── tester.py
│   └── trainer.py
├── output
│   ├── models
│   └── tensorboard
├── README.md
└── utils
    ├── __init__.py
    ├── math_graph.py
    └── math_utils.py

Updates

Feb. 22, 2022:

Feb. 11, 2022:

Apr. 18, 2019:

Jan. 14, 2019:

Citation

Please refer to our paper. Bing Yu*, Haoteng Yin*, Zhanxing Zhu. Spatio-temporal Graph Convolutional Networks: A Deep Learning Framework for Traffic Forecasting. In Proceedings of the 27th International Joint Conference on Artificial Intelligence (IJCAI), 2018

@inproceedings{yu2018spatio,
    title={Spatio-temporal Graph Convolutional Networks: A Deep Learning Framework for Traffic Forecasting},
    author={Yu, Bing and Yin, Haoteng and Zhu, Zhanxing},
    booktitle={Proceedings of the 27th International Joint Conference on Artificial Intelligence (IJCAI)},
    year={2018}
}