TrajMamba: An Efficient and Semantic-rich Vehicle Trajectory Pre-training Model

Yichen Liu, Yan Lin, Shengnan Guo, Zeyu Zhou, Youfang Lin, Huaiyu Wan

TL;DR

TrajMamba is a novel vehicle trajectory pre-training model that leverages the linear-time efficiency of Mamba2 architectures to capture both fine-grained movement patterns and high-level travel purposes. By utilizing contrastive learning with text models during pre-training and a learnable knowledge-distillation compression scheme, it strips away computational redundancy and language model overhead at inference time. The result is a highly accurate trajectory embedding model that executes up to 50 times faster than recent state-of-the-art baselines.

What Problem Does This Paper Address?

Vehicle GPS trajectories are more than just a sequence of coordinates; they contain rich semantic information about how a vehicle moves (speed, acceleration, turns) and why it is traveling (commuting, shopping, leisure). Unlocking these semantics is crucial for intelligent transportation systems (ITS) tasks like destination prediction and arrival time estimation.

However, existing trajectory learning methods face two major bottlenecks:

  1. Heavy Semantic Overhead: To understand a trip's purpose, models must look at the textual descriptions of nearby Points-of-Interest (POIs) and road functions. Integrating Large Language Models (LLMs) directly into trajectory encoders introduces a massive computational burden.
  2. Data Redundancy: High-frequency GPS sampling creates highly redundant data points (e.g., idling at a red light or driving straight at a constant speed). Traditional geometric compression algorithms (like Douglas-Peucker) are rule-based, slow, and decoupled from semantic learning.

Methods

TrajMamba addresses these challenges through a three-step pipeline: a dual-perspective encoder, travel purpose-aware pre-training, and a learnable trajectory compression scheme via knowledge distillation.

Figure 2: The framework of TrajMamba.

1. Traj-Mamba Encoder

Instead of relying on computationally heavy Transformers ($O(n^2)$ complexity), the authors design a Traj-Mamba Encoder based on the Mamba2 architecture, achieving linear time complexity ($O(n)$). Each block features two specialized State Space Models (SSMs):

  • GPS-SSM: Processes coordinates and temporal deltas, modulated by high-order movement features (speed, acceleration, angle).
  • Road-SSM: Captures the geographical space and road network transitions.

A gating mechanism fuses these two perspectives to create a unified trajectory representation.

Figure 3: Structure of Traj-Mamba blocks.

2. Travel Purpose-aware Pre-training

To capture why a vehicle is moving without dragging down inference speeds, TrajMamba uses a text encoder (e.g., OpenAI's text-embedding-3-large) during pre-training to encode POI and road network descriptions. It then uses contrastive learning (InfoNCE loss) to pull the trajectory embeddings closer to their corresponding textual "views." Crucially, the text encoder is discarded after pre-training, leaving a lightweight trajectory encoder that inherently understands travel context.

3. Knowledge Distillation Pre-training

To handle redundancy, the authors introduce a learnable Mask Generator that uses a sparse stochastic gate to drop non-critical trajectory points. To ensure that compressing the trajectory doesn't destroy its semantic meaning, they employ knowledge distillation: a student network processes the compressed trajectory and is trained to match the full-trajectory embedding generated by the fixed teacher network using a Maximum Entropy Coding (MEC) loss.

Datasets

The model was evaluated on two massive, real-world taxi trajectory datasets released by Didi Chuxing:

  • Chengdu: 140,000 trajectories containing over 18 million points.
  • Xian: 210,000 trajectories containing over 18 million points.

Road network topologies were extracted from OpenStreetMap, and POI data was retrieved via the AMap API. Trajectories were filtered to lengths between 5 and 120 points.

Key Insights and Ideas

  • Decoupling Text from Inference: The most elegant trick in TrajMamba is using contrastive alignment to inject LLM-level semantic understanding into a trajectory model without requiring the LLM during deployment.
  • Learnable, Semantic Compression: Instead of compressing trajectories based purely on geometry, TrajMamba's mask generator learns to keep points that matter semantically. For instance, points near the origin and destination are preserved because they carry strong indicators of travel purpose.
  • Linear Scaling for Spatiotemporal Data: By adapting Mamba2's selective scan mechanism to handle parallel GPS and road network inputs, the model maintains a highly efficient linear complexity relative to trajectory length, making it ideal for real-time deployment.

Key Results

The authors evaluated TrajMamba across three downstream tasks: Destination Prediction (DP), Arrival Time Estimation (ATE), and Similar Trajectory Search (STS).

Accuracy Gains

TrajMamba consistently outperformed nine state-of-the-art baselines (including Transformer-based models like START and multi-modal models like JGRM). For instance, in Destination Prediction on the Chengdu dataset, TrajMamba slashed the GPS coordinate prediction error (RMSE) down to 129.47 meters, compared to JGRM's 215.99 meters.

Table 1: Destination prediction (DP) performance results. ↑: higher better, ↓: lower better. Bold: the best, underline: the second best. The results under w/o ft setting can be found in Appendix E.

Efficiency Boosts

The true strength of TrajMamba lies in its speed. Thanks to its Mamba-based architecture and compressed embeddings, its inference/embedding time is drastically lower than Transformer-based counterparts. On the Chengdu dataset, TrajMamba achieved an embedding time of 1.721 seconds, making it over 54x faster than the closest high-performing baseline, JGRM (94.048 seconds).

Table 4: Efficiency analysis of methods. A lower value indicates better performance. Bold: the best, underline: the second best.

Limitations and Future Work

Despite its strong performance, TrajMamba's primary limitation is its cross-city transferability. Because road networks and POI distributions vary drastically between different cities, a model trained on one city struggles with zero-shot migration to another. The authors note that future work will focus on developing universal, transferable road and POI tokenizations to allow models to generalize seamlessly across different urban geographies.

Summary updated

Abstract

Vehicle GPS trajectories record how vehicles move over time, storing valuable travel semantics, including movement patterns and travel purposes. Learning travel semantics effectively and efficiently is crucial for real-world applications of trajectory data, which is hindered by two major challenges. First, travel purposes are tied to the functions of the roads and points-of-interest (POIs) involved in a trip. Such information is encoded in textual addresses and descriptions and introduces heavy computational burden to modeling. Second, real-world trajectories often contain redundant points, which harm both computational efficiency and trajectory embedding quality. To address these challenges, we propose TrajMamba, a novel approach for efficient and semantically rich vehicle trajectory learning. TrajMamba introduces a Traj-Mamba Encoder that captures movement patterns by jointly modeling both GPS and road perspectives of trajectories, enabling robust representations of continuous travel behaviors. It also incorporates a Travel Purpose-aware Pre-training procedure to integrate travel purposes into the learned embeddings without introducing extra overhead to embedding calculation. To reduce redundancy in trajectories, TrajMamba features a Knowledge Distillation Pre-training scheme to identify key trajectory points through a learnable mask generator and obtain effective compressed trajectory embeddings. Extensive experiments on two real-world datasets and three downstream tasks show that TrajMamba outperforms state-of-the-art baselines in both efficiency and accuracy.
BibTeX
@inproceedings{liu2025trajmamba,
  author = {Yichen Liu and Yan Lin and Shengnan Guo and Zeyu Zhou and Youfang Lin and Huaiyu Wan},
  title = {{TrajMamba: An Efficient and Semantic-rich Vehicle Trajectory Pre-training Model}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=pRYGjhirkY},
}
Figure