Embedding spatial context in urban traffic forecasting with contrastive pre-training

Matthew Low, Arian Prabowo, Hao Xue, Flora SalimarXiv 2025 · OpenReview

Abstract: Urban traffic forecasting is a commonly encountered problem, with wide-ranging applications in fields such as urban planning, civil engineering and transport. In this paper, we study the enhancement of traffic forecasting with pre-training, focusing on spatio-temporal graph methods. While various machine learning methods to solve traffic forecasting problems have been explored and extensively studied, there is a gap of a more contextual approach: studying how relevant non-traffic data can improve prediction performance on traffic forecasting problems. We call this data spatial context. We introduce a novel method of combining road and traffic information through the notion of a traffic quotient graph, a quotient graph formed from road geometry and traffic sensors. We also define a way to encode this relationship in the form of a geometric encoder, pre-trained using contrastive learning methods and enhanced with OpenStreetMap data. We introduce and discuss ways to integrate this geometric encoder with existing graph neural network (GNN)-based traffic forecasting models, using a contrastive pre-training paradigm. We demonstrate the potential for this hybrid model to improve generalisation and performance with zero additional traffic data.

Introduction

Traffic forecasting is a cornerstone of modern urban planning, but most state-of-the-art models are "data-hungry" in a specific way: they rely almost exclusively on historical sensor data such as speeds and flows. These models typically utilize Spatio-Temporal Graph Neural Networks (STGNNs), treating traffic sensors as nodes in a graph. However, the "edges" between these nodes are often mathematical abstractions based on distance, ignoring the "spatial context"—the physical reality of the road network.

For example, a sensor near a shopping mall behaves differently than one on a rural highway, even if the local road geometry appears similar. Furthermore, existing models struggle to generalize to new areas where historical data is sparse. This research aims to bridge this gap by integrating freely available map data, such as speed limits, lane counts, and points of interest from OpenStreetMap (OSM), into the forecasting pipeline.

Methodology

Conceptual framework of the proposed spatio-temporal graph forecasting pre-training.

The proposed framework introduces a three-step approach to integrate spatial context into forecasting models:

1. The Traffic Quotient Graph

Road maps from OpenStreetMap are highly detailed, whereas sensor networks are relatively sparse. To reconcile these scales, the authors employ the mathematical concept of a quotient graph. By clustering detailed "road nodes" around a single "traffic sensor node," they create a simplified graph that maintains the true connectivity of the physical road network.

2. Geometric Encoder and Contrastive Pre-training

A Graph Neural Network (GNN) is designed to extract features from this spatial data, including direct features (lane counts, max speeds) and derived features (nearby amenities like cafes or offices). To train this encoder without labeled traffic data, a contrastive learning approach is used.

The contrastive pre-training process using cluster sampling and subgraph generation.

As shown in the figure above, the model generates "positive pairs" by sampling different road nodes within the same sensor cluster. The model learns that these different views represent the same underlying spatial context, allowing it to recognize similar road patterns across a city. This acts as a form of natural data augmentation, where the cluster of road nodes around a sensor provides noisy but semantically similar views of the same location.

3. Model Integration

These pre-trained spatial embeddings are integrated into a standard forecasting model, specifically Graph WaveNet, using a "spatially gated addition" mechanism. This allows the model to dynamically weigh the importance of spatial context against historical traffic patterns.

Experimental Results

The approach was evaluated on three benchmark traffic datasets: METR-LA (Los Angeles), PEMS-BAY (Bay Area), and PEMS-D7(m) (California District 7). The hybrid model consistently outperformed the baseline Graph WaveNet across all datasets:

  • METR-LA: Achieved a Mean Absolute Error (MAE) of 12.74 (baseline: 12.86).
  • PEMS-BAY: Achieved an MAE of 5.89 (baseline: 6.09).
  • PEMS-D7(m): Achieved an MAE of 8.67 (baseline: 9.03).

Qualitatively, the models incorporating spatial context converged faster, showing a steeper decline in training loss during early epochs. This suggests that the physical characteristics of a road act as a powerful "prior," allowing the model to understand the "capacity" for traffic patterns before processing historical data.

Conclusion

This paper demonstrates that pre-training a geometric encoder on non-traffic data can significantly enhance the performance and efficiency of traffic forecasting models. While the study primarily utilized amenities as a derived feature, future work could expand this to include land-use zones, building heights, or weather patterns. The ultimate goal remains "zero-shot" forecasting—predicting traffic on entirely new road networks where historical sensor data is unavailable.

Summary updated

BibTeX
@misc{low2025embedding,
  author = {Matthew Low and Arian Prabowo and Hao Xue and Flora Salim},
  title = {{Embedding spatial context in urban traffic forecasting with contrastive pre-training}},
  year = {2025},
  eprint = {2503.14980},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.14980},
}
Figure