CroTad: A Contrastive Reinforcement Learning Framework for Online Trajectory Anomaly Detection

Rui Xue, Dan He, Fengmei Jin, Chen Zhang, Xiaofang ZhouarXiv 2025 · OpenReview

Abstract

Detecting trajectory anomalies is a vital task in modern Intelligent Transportation Systems (ITS), enabling the identification of unsafe, inefficient, or irregular travel behaviours. While deep learning has emerged as the dominant approach, several key challenges remain unresolved. First, sub-trajectory anomaly detection, capable of pinpointing the precise segments where anomalies occur, remains underexplored compared to whole-trajectory analysis. Second, many existing methods depend on carefully tuned thresholds, limiting their adaptability in real-world applications. Moreover, the irregular sampling of trajectory data and the presence of noise in training sets further degrade model performance, making it difficult to learn reliable representations of normal routes. To address these challenges, we propose a contrastive reinforcement learning framework for online trajectory anomaly detection, CroTad. Our method is threshold-free and robust to noisy, irregularly sampled data. By incorporating contrastive learning, CroTad learns to extract diverse normal travel patterns for different itineraries and effectively distinguish anomalous behaviours at both sub-trajectory and point levels. The detection module leverages deep reinforcement learning to perform online, real-time anomaly scoring, enabling timely and fine-grained identification of abnormal segments. Extensive experiments on two real-world datasets demonstrate the effectiveness and robustness of our framework across various evaluation scenarios.

Introduction

Detecting anomalies in GPS trajectories—such as unauthorized detours or route deviations—is critical for urban safety and operational efficiency. However, current methodologies face significant hurdles. Most models operate at a coarse granularity, classifying entire trips rather than pinpointing specific abnormal segments. Furthermore, they often rely on manually tuned anomaly score thresholds, which lack adaptability across different urban environments. Finally, real-world GPS data is frequently noisy and irregularly sampled, complicating the learning of "normal" behavior in unlabeled datasets.

Methodology

CroTad addresses these issues through a two-stage pipeline: Trajectory Representation Learning (TRL) and Anomaly Detection (AD).

The CroTad framework architecture, comprising Trajectory Representation Learning (TRL) and Anomaly Detection (AD) modules.

Trajectory Representation Learning (TRL)

To handle spatial data effectively, CroTad maps GPS coordinates to H3 hexagonal cells. It constructs a Hierarchical Graph that integrates road connectivity, travel context (e.g., transit stops), and historical mobility patterns.

The TRL stage employs Contrastive Pre-training to ensure that similar routes are clustered together in the embedding space. A key innovation is Intra-Itinerary Contrast (IIC), a loss function that compares trajectories with the same Origin-Destination (OD) pair. This allows the model to distinguish between legitimate shortcuts and genuine anomalies.

Anomaly Detection (AD)

The detection phase transitions from representation to decision-making:

  1. Pseudo-Labeling: In the absence of ground-truth labels, the framework uses offline clustering (DBSCAN) on learned embeddings to identify sparse clusters as potential anomalies.
  2. Deep Q-Learning (DQN): These pseudo-labels are used to train a reinforcement learning agent. The agent learns an optimal policy to classify segments in real-time.
  3. Biased Reward Function: To account for the rarity of anomalies, a biased reward system is implemented, penalizing false negatives more heavily than false positives.

Experimental Evaluation

The framework was evaluated on two real-world datasets: Porto (taxi trajectories in Portugal) and Translink (bus trajectories in Australia). Due to the scarcity of real-world labels, synthetic benchmarks were created, covering head, rear, and midway detours, as well as route switching.

Key Results

  • High Precision: On the Translink dataset, CroTad achieved an F1-score of approximately 0.97 for head detours, significantly outperforming generative baselines like DeepTEA (~0.71).
  • Denoising Capabilities: In identifying buses deviating for refueling, CroTad showed up to a 110% improvement in F1-score over traditional sequence-to-sequence models.
  • Robustness: The model demonstrated exceptional performance in "Route Switching" scenarios, where a vehicle follows a path that is normal for a different destination but abnormal for its current one.

Conclusion

CroTad introduces a threshold-free, policy-based approach to trajectory anomaly detection. By leveraging contrastive learning for robust representations and reinforcement learning for real-time detection, it achieves fine-grained, point-level accuracy. Future work will explore the integration of dynamic features like real-time traffic and weather conditions to further enhance the model's contextual understanding.

Summary updated

BibTeX
@misc{xue2025crotad,
  author = {Rui Xue and Dan He and Fengmei Jin and Chen Zhang and Xiaofang Zhou},
  title = {{CroTad: A Contrastive Reinforcement Learning Framework for Online Trajectory Anomaly Detection}},
  year = {2025},
  eprint = {2511.16929},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.16929},
}
Figure