Papers
Topics
Authors
Recent
Assistant
AI Research Assistant
Well-researched responses based on relevant abstracts and paper content.
Custom Instructions Pro
Preferences or requirements that you'd like Emergent Mind to consider when generating responses.
Gemini 2.5 Flash
Gemini 2.5 Flash 43 tok/s
Gemini 2.5 Pro 48 tok/s Pro
GPT-5 Medium 21 tok/s Pro
GPT-5 High 20 tok/s Pro
GPT-4o 95 tok/s Pro
Kimi K2 180 tok/s Pro
GPT OSS 120B 443 tok/s Pro
Claude Sonnet 4.5 32 tok/s Pro
2000 character limit reached

Trajectory Anomaly Detection with Language Models (2409.15366v1)

Published 18 Sep 2024 in cs.LG and cs.AI

Abstract: This paper presents a novel approach for trajectory anomaly detection using an autoregressive causal-attention model, termed LM-TAD. This method leverages the similarities between language statements and trajectories, both of which consist of ordered elements requiring coherence through external rules and contextual variations. By treating trajectories as sequences of tokens, our model learns the probability distributions over trajectories, enabling the identification of anomalous locations with high precision. We incorporate user-specific tokens to account for individual behavior patterns, enhancing anomaly detection tailored to user context. Our experiments demonstrate the effectiveness of LM-TAD on both synthetic and real-world datasets. In particular, the model outperforms existing methods on the Pattern of Life (PoL) dataset by detecting user-contextual anomalies and achieves competitive results on the Porto taxi dataset, highlighting its adaptability and robustness. Additionally, we introduce the use of perplexity and surprisal rate metrics for detecting outliers and pinpointing specific anomalous locations within trajectories. The LM-TAD framework supports various trajectory representations, including GPS coordinates, staypoints, and activity types, proving its versatility in handling diverse trajectory data. Moreover, our approach is well-suited for online trajectory anomaly detection, significantly reducing computational latency by caching key-value states of the attention mechanism, thereby avoiding repeated computations.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (44)
  1. Massive Trajectory Data Based on Patterns of Life. In Proceedings of the 31st ACM International Conference on Advances in Geographic Information Systems. 1–4. https://doi.org/10.1145/3589132.3625592
  2. Jinwon An and Sungzoon Cho. 2015. Variational Autoencoder based Anomaly Detection using Reconstruction Probability. https://api.semanticscholar.org/CorpusID:36663713
  3. Alexei Baevski and Abdelrahman Mohamed. 2020. Effectiveness of Self-Supervised Pre-Training for ASR. In ICASSP 2020 - 2020 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP). 7694–7698. https://doi.org/10.1109/ICASSP40776.2020.9054224
  4. wav2vec 2.0: A Framework for Self-Supervised Learning of Speech Representations. ArXiv abs/2006.11477 (2020). https://proceedings.neurips.cc/paper/2020/file/92d1e1eb1cd6f9fba3227870bb6d7f07-Paper.pdf
  5. Language Models Are Few-Shot Learners (NIPS’20). Curran Associates Inc., Red Hook, NY, USA, Article 159, 25 pages.
  6. iBOAT: Isolation-Based Online Anomalous Trajectory Detection. IEEE Transactions on Intelligent Transportation Systems 14, 2 (2013), 806–818. https://doi.org/10.1109/TITS.2013.2238531
  7. Real-Time Detection of Anomalous Taxi Trajectories from GPS Traces. In Mobile and Ubiquitous Systems: Computing, Networking, and Services, Alessandro Puiatti and Tao Gu (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 63–74.
  8. Outlier Detection with Autoencoder Ensembles. 90–98. https://doi.org/10.1137/1.9781611974973.11 arXiv:https://epubs.siam.org/doi/pdf/10.1137/1.9781611974973.11
  9. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers). Association for Computational Linguistics, Minneapolis, Minnesota, 4171–4186. https://doi.org/10.18653/v1/N19-1423
  10. Online Trajectory Prediction for Metropolitan Scale Mobility Digital Twin. In Proceedings of the 30th International Conference on Advances in Geographic Information Systems (Seattle, Washington) (SIGSPATIAL ’22). Association for Computing Machinery, New York, NY, USA, Article 103, 12 pages. https://doi.org/10.1145/3557915.3561040
  11. Hugo Ledoux Filip Biljecki and Peter van Oosterom. 2013. Transportation mode-based segmentation and classification of movement trajectories. International Journal of Geographical Information Science 27, 2 (2013), 385–407. https://doi.org/10.1080/13658816.2012.692791 arXiv:https://doi.org/10.1080/13658816.2012.692791
  12. Coupled IGMM-GANs for deep multimodal anomaly detection in human mobility data. ArXiv abs/1809.02728 (2018). https://arxiv.org/abs/1809.02728
  13. How do you go where?: improving next location prediction by learning travel mode information using transformers. Proceedings of the 30th International Conference on Advances in Geographic Information Systems (2022). https://arxiv.org/abs/2210.04095
  14. Trajectory Outlier Detection: A Partition-and-Detect Framework. In 2008 IEEE 24th International Conference on Data Engineering. 140–149. https://doi.org/10.1109/ICDE.2008.4497422
  15. Deep Representation Learning for Trajectory Similarity Computation. In 2018 IEEE 34th International Conference on Data Engineering (ICDE). 617–628. https://doi.org/10.1109/ICDE.2018.00062
  16. MiniCache: KV Cache Compression in Depth Dimension for Large Language Models. https://arxiv.org/pdf/2405.14366
  17. Online Anomalous Trajectory Detection with Deep Generative Sequence Modeling. In 2020 IEEE 36th International Conference on Data Engineering (ICDE). 949–960. https://doi.org/10.1109/ICDE48307.2020.00087
  18. Outlier trajectory detection: a trajectory analytics based approach. In Database Systems for Advanced Applications (Lecture Notes in Computer Science), Selçuk Candan, Lei Chen, Torben Bach Pedersen, Lijun Chang, and Wen Hua (Eds.). Springer, Springer Nature, United States, 231–246. https://doi.org/10.1007/978-3-319-55753-3_15 22nd International Conference on Database Systems for Advanced Applications (DASFAA) ; Conference date: 27-03-2017 Through 30-03-2017.
  19. LSTM-based Encoder-Decoder for Multi-sensor Anomaly Detection. ArXiv abs/1607.00148 (2016). https://arxiv.org/pdf/1607.00148.pdf
  20. Let’s Speak Trajectories. In Proceedings of the 30th International Conference on Advances in Geographic Information Systems (Seattle, Washington) (SIGSPATIAL ’22). Association for Computing Machinery, New York, NY, USA, Article 37, 4 pages. https://doi.org/10.1145/3557915.3560972
  21. No News is Good News: A Critique of the One Billion Word Benchmark. ArXiv abs/2110.12609 (2021). https://api.semanticscholar.org/CorpusID:239769114
  22. Deep Contextualized Word Representations. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers). Association for Computational Linguistics, New Orleans, Louisiana, 2227–2237. https://doi.org/10.18653/v1/N18-1202
  23. Dieter Pfoser and Christian S. Jensen. 1999. Capturing the Uncertainty of Moving-Object Representations. In Proceedings of the 6th International Symposium on Advances in Spatial Databases (SSD’99). Springer-Verlag, 111–132. https://doi.org/10.1007/3-540-48482-5_9
  24. Efficiently Scaling Transformer Inference. ArXiv abs/2211.05102 (2022). https://arxiv.org/pdf/2211.05102
  25. Learning Transferable Visual Models From Natural Language Supervision. In International Conference on Machine Learning. https://proceedings.mlr.press/v139/radford21a/radford21a.pdf
  26. Language Models are Unsupervised Multitask Learners. https://api.semanticscholar.org/CorpusID:160025533
  27. Sequential Variational Autoencoders for Collaborative Filtering. Proceedings of the Twelfth ACM International Conference on Web Search and Data Mining (2018). https://arxiv.org/pdf/1811.09975.pdf
  28. Coupled IGMM-GANs with Applications to Anomaly Detection in Human Mobility Data. ACM Trans. Spatial Algorithms Syst. 6, 4, Article 24 (jun 2020), 14 pages. https://doi.org/10.1145/3385809
  29. Anomalous Trajectory Detection Using Recurrent Neural Network. In Advanced Data Mining and Applications, Guojun Gan, Bohan Li, Xue Li, and Shuliang Wang (Eds.). Springer International Publishing, Cham, 263–277.
  30. LLaMA: Open and Efficient Foundation Language Models. ArXiv abs/2302.13971 (2023). https://arxiv.org/pdf/2302.13971.pdf
  31. Inc Uber. 2023. H3 Hexagonal hierarchical geospatial indexing system. https://h3geo.org/. Accessed: 11/22/23.
  32. Attention is All you Need. In Advances in Neural Information Processing Systems, I. Guyon, U. Von Luxburg, S. Bengio, H. Wallach, R. Fergus, S. Vishwanathan, and R. Garnett (Eds.), Vol. 30. Curran Associates, Inc. https://arxiv.org/pdf/1706.03762.pdf
  33. Leveraging language foundation models for human mobility forecasting. Proceedings of the 30th International Conference on Advances in Geographic Information Systems (2022). https://arxiv.org/pdf/2209.05479.pdf
  34. Driving with Knowledge from the Physical World (KDD ’11). Association for Computing Machinery, New York, NY, USA, 316–324. https://doi.org/10.1145/2020408.2020462
  35. T-Drive: Driving Directions Based on Taxi Trajectories (GIS ’10). Association for Computing Machinery, New York, NY, USA, 99–108. https://doi.org/10.1145/1869790.1869807
  36. IBAT: Detecting Anomalous Taxi Trajectories from GPS Traces. In Proceedings of the 13th International Conference on Ubiquitous Computing (Beijing, China) (UbiComp ’11). Association for Computing Machinery, New York, NY, USA, 99–108. https://doi.org/10.1145/2030112.2030127
  37. A trajectory outlier detection method based on variational auto-encoder. Mathematical biosciences and engineering : MBE 20 8 (2023), 15075–15093. https://api.semanticscholar.org/CorpusID:259926930
  38. Online Anomalous Subtrajectory Detection on Road Networks with Deep Reinforcement Learning. In 2023 IEEE 39th International Conference on Data Engineering (ICDE). 246–258. https://doi.org/10.1109/ICDE55515.2023.00026
  39. Contextual Spatial Outlier Detection with Metric Learning (KDD ’17). Association for Computing Machinery, New York, NY, USA, 2161–2170. https://doi.org/10.1145/3097983.3098143
  40. Chong Zhou and Randy C. Paffenroth. 2017. Anomaly Detection with Robust Deep Autoencoders. In Proceedings of the 23rd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (Halifax, NS, Canada) (KDD ’17). Association for Computing Machinery, New York, NY, USA, 665–674. https://doi.org/10.1145/3097983.3098052
  41. Learning to Prompt for Vision-Language Models. International Journal of Computer Vision 130 (2021), 2337 – 2348. https://arxiv.org/pdf/2109.01134.pdf
  42. Time-Dependent Popular Routes Based Trajectory Outlier Detection. Springer-Verlag, Berlin, Heidelberg, 16–30. https://doi.org/10.1007/978-3-319-26190-4_2
  43. Deep Autoencoding Gaussian Mixture Model for Unsupervised Anomaly Detection. In International Conference on Learning Representations. https://sites.cs.ucsb.edu/~bzong/doc/iclr18-dagmm.pdf
  44. Urban life: a model of people and places. Computational and Mathematical Organization Theory 29 (11 2023), 20–51. https://doi.org/10.1007/s10588-021-09348-7

Summary

  • The paper introduces LM-TAD, which models movement trajectories as language sequences to detect anomalies via perplexity and surprisal rates.
  • The methodology leverages a transformer architecture with user-specific tokens, enabling precise, context-aware anomaly localization.
  • Experimental results indicate LM-TAD outperforms autoencoder baselines on agent-specific metrics and supports real-time detection with efficient caching.

Trajectory Anomaly Detection with LLMs: LM-TAD

Introduction and Motivation

The paper "Trajectory Anomaly Detection with LLMs" (2409.15366) introduces LM-TAD, an autoregressive causal-attention model for unsupervised trajectory anomaly detection. The central premise is the analogy between natural language statements and movement trajectories: both are ordered sequences of discrete elements governed by external rules and contextual dependencies. This conceptualization enables the application of LLMing techniques to trajectory data, facilitating the identification of anomalous patterns at both the trajectory and location levels. Figure 1

Figure 1: Conceptual visualization of trajectories as natural language statements, highlighting the analogy between ordered elements and contextual rules in both domains.

Model Architecture and Methodology

LM-TAD leverages a transformer-based architecture, employing token and positional embeddings, multi-head causal self-attention, and a final linear-softmax output layer. The model is trained to maximize the likelihood of observed trajectories, predicting the next location conditioned on historical context. User-specific tokens are incorporated to capture individual behavioral patterns, enabling context-aware anomaly detection. Figure 2

Figure 2: Architecture of LM-TAD, illustrating the embedding layers, transformer blocks, and output prediction mechanism.

The model supports various trajectory representations, including discretized GPS coordinates, staypoints, and activity types. This flexibility is achieved by abstracting locations as tokens, allowing the model to operate on heterogeneous trajectory modalities. Figure 3

Figure 3

Figure 3

Figure 3

Figure 3: Example of discretized GPS coordinates as input tokens for LM-TAD.

Anomaly Scoring: Perplexity and Surprisal Rate

Anomaly detection is performed using perplexity, a standard metric in LLMing, which quantifies the uncertainty in predicting the next location. High perplexity indicates low-probability (anomalous) trajectories. For localization of anomalies within trajectories, the surprisal rate is introduced, measuring the unexpectedness of individual locations given their context. Figure 4

Figure 4: Surprisal rate through trajectories on the Pattern of Life dataset, demonstrating the identification of anomalous locations via elevated surprisal scores.

Thresholds for anomaly detection are computed as the mean plus standard deviation of perplexity scores, either globally or per-user, enabling both global and user-specific outlier identification.

Experimental Evaluation

Datasets

Experiments are conducted on two datasets:

  • Pattern-of-Life (PoL): Simulated agent trajectories with labeled anomalies, supporting user-contextual anomaly detection.
  • Porto Taxi: Real-world taxi GPS traces, with synthetic anomalies (random shift and detour) injected for evaluation.

Baselines

LM-TAD is compared against deep autoencoder (SAE), variational autoencoder (VSAE), and Gaussian mixture VSAE (GM-VSAE) baselines. All baselines use reconstruction error as the anomaly score.

Results

On the PoL dataset, LM-TAD consistently outperforms all baselines in F1 and PR-AUC for agent-specific anomaly detection. Autoencoder-based methods fail to distinguish anomalies due to overfitting and lack of user-context modeling. LM-TAD's use of user tokens and conditional likelihood estimation enables robust identification of context-dependent anomalies.

On the Porto dataset, LM-TAD achieves competitive performance with GM-VSAE for global anomaly detection, particularly excelling in random shift scenarios. For detour anomalies affecting small trajectory segments, GM-VSAE shows marginally higher sensitivity, attributed to the averaging effect in perplexity-based scoring. Figure 5

Figure 5

Figure 5: Visualization of random shift anomalies in the Porto dataset, illustrating the perturbation of trajectory segments.

Figure 6

Figure 6

Figure 6

Figure 6

Figure 6: SAE baseline performance, highlighting its limitations in distinguishing anomalous trajectories.

Figure 7

Figure 7

Figure 7

Figure 7

Figure 7: F1 scores for random shift anomalies, demonstrating LM-TAD's competitive accuracy across anomaly types.

Ablation and Online Detection

An ablation paper confirms LM-TAD's adaptability to different location modalities (staypoints, GPS, dwell time), with staypoint labels yielding the highest anomaly detection accuracy in PoL. LM-TAD supports online anomaly detection by caching key-value states in the attention mechanism, enabling low-latency scoring of partial trajectories without recomputation.

Theoretical and Practical Implications

The LM-TAD framework advances trajectory anomaly detection by:

  • Contextual Modeling: Conditioning on user and temporal tokens enables fine-grained, context-aware anomaly detection, addressing the heterogeneity of normal behavior across individuals.
  • Localization: Surprisal rate facilitates precise identification of anomalous locations within trajectories, overcoming the limitations of aggregate anomaly scores.
  • Modality Flexibility: The token-based approach generalizes across spatial, semantic, and temporal trajectory representations.
  • Online Efficiency: KV cache utilization in transformer inference supports real-time anomaly detection, critical for applications in transportation, surveillance, and healthcare.

Future Directions

Potential avenues for further research include:

  • Integration with External Knowledge: Incorporating road network constraints, POI semantics, or multimodal sensor data to enhance anomaly characterization.
  • Adaptive Thresholding: Developing dynamic, context-sensitive thresholding mechanisms for anomaly scores.
  • Scalability: Extending LM-TAD to large-scale, multi-agent environments with federated or distributed training.
  • Explainability: Augmenting the model with interpretable attention mechanisms to elucidate the rationale behind anomaly detection decisions.

Conclusion

LM-TAD represents a significant methodological advancement in trajectory anomaly detection, leveraging LLMing paradigms to capture sequential dependencies and contextual variability in movement data. Its superior performance in user-contextual anomaly detection, competitive results in global outlier identification, and support for diverse trajectory modalities and online inference position it as a robust solution for real-world spatiotemporal anomaly detection tasks. The approach opens new possibilities for user-centric, scalable, and explainable anomaly detection in mobility analytics and related domains.

List To Do Tasks Checklist Streamline Icon: https://streamlinehq.com

Collections

Sign up for free to add this paper to one or more collections.

X Twitter Logo Streamline Icon: https://streamlinehq.com

Tweets

This paper has been mentioned in 2 posts and received 40 likes.

Don't miss out on important new AI/ML research

See which papers are being discussed right now on X, Reddit, and more:

“Emergent Mind helps me see which AI papers have caught fire online.”

Philip

Philip

Creator, AI Explained on YouTube