Knowledge-Based Systems, Volume 327, Article 114141 (2025)
Zhouzheng Xu · Yuxing Wu · Hang Zhou · Chaofan Fan · Bingyi Li · Kaiyue Liu · Yaqin Ye · Shunping Zhou · Shengwen Li
TL;DR: STMetaT learns trajectory representations across heterogeneous spatial and temporal contexts. It constructs constrained meta-learning tasks, fuses GPS, road, and POI views, and transfers the resulting representation to destination prediction, travel-time estimation, and similar-trajectory search.
- Spatio-temporal task construction. Support/query subsets are sampled under spatial-grid and temporal-window constraints.
- Multi-view trajectory encoding. GPS coordinates, road semantics, and POI context are fused instead of relying on a single trajectory view.
- Meta-learning for heterogeneity. Inner-loop task adaptation and outer-loop optimization target transfer across distinct spatial and temporal conditions.
- Multi-task evaluation. The pipeline contains prediction and retrieval heads for destination prediction (DP), travel-time estimation (TTE), and similar-trajectory search.
| Stage | Purpose | Code |
|---|---|---|
| 1. Constrained task sampling | organize trajectories by spatial grid and temporal window | meta_maml_train.py, data.py |
| 2. Multi-view encoding | combine geometric, temporal, road, and POI signals | models/encode.py, models/traj_clip.py |
| 3. Sequence modeling | model long-range trajectory dependencies | models/mamba/, models/mamba2/ |
| 4. Adaptation and evaluation | fine-tune task heads and evaluate prediction or retrieval | pipeline.py, models/predictor.py |
A CUDA-enabled environment is recommended for the Mamba kernels. The code imports the following core packages:
pip install torch numpy pandas tables scikit-learn einops tqdm higher packaging
pip install mamba-ssm causal-conv1dExperiments are driven by settings/<name>.json. Each setting identifies:
train_traj_df HDF5 trajectory table (key: trips)
test_traj_df HDF5 trajectory table (key: trips)
poi_df HDF5 POI table (key: pois)
poi_embed NumPy POI embedding matrix
road_embed NumPy road embedding matrix
settings/local_test.json points to the small files under samples/. For full experiments, store the datasets outside Git and update the paths in a dedicated settings file.
Optional output locations are controlled through environment variables:
export SETTINGS_CACHE_DIR=/path/to/settings-cache
export MODEL_CACHE_DIR=/path/to/checkpoints
export PRED_SAVE_DIR=/path/to/predictions
export SEARCH_META_DIR=/path/to/search-metadataRun the configured pretraining, fine-tuning, and evaluation pipeline:
python main.py --settings local_test --cuda 0The active stages come directly from the selected JSON file:
pretrain: self-supervised trajectory representation learning;finetune: downstream adaptation with the configured task head;test:dp,tte, orsearchevaluation and optional prediction export.
| Entry point | Role |
|---|---|
main.py |
configuration-driven pretrain → fine-tune → test pipeline |
meta_maml_train.py |
constrained support/query task construction and MAML-style training |
The sample quick start runs main.py. Formal STMetaT meta-learning experiments use the dedicated meta-learning entry point and a settings file containing meta_lr, inner_lr, num_inner_steps, k_shot, and q_shot.
| Path | Content |
|---|---|
$SETTINGS_CACHE_DIR/<timestamp>.json |
immutable copy of the selected setting |
$MODEL_CACHE_DIR/*.pretrain |
pretrained trajectory encoder |
$MODEL_CACHE_DIR/*_trajclip.finetune |
fine-tuned trajectory encoder |
$MODEL_CACHE_DIR/*_predhead.finetune |
fine-tuned downstream head |
$PRED_SAVE_DIR/<run>/ |
optional predictions and targets |
$SEARCH_META_DIR/<dataset>/ |
generated retrieval candidates and metadata |
If STMetaT is useful in your research, please cite:
@article{xu2025stmetat,
author = {Xu, Zhouzheng and Wu, Yuxing and Zhou, Hang and Fan, Chaofan and Li, Bingyi and Liu, Kaiyue and Ye, Yaqin and Zhou, Shunping and Li, Shengwen},
title = {Spatio-Temporal Meta-Learning for Trajectory Representation Learning},
journal = {Knowledge-Based Systems},
volume = {327},
pages = {114141},
year = {2025},
doi = {10.1016/j.knosys.2025.114141}
}