Pi-DPM is a physics-informed anomaly detection framework for trajectory data. It leverages the Denoising Diffusion Probabilistic Model (DDPM) to learn fine-scale spatiotemporal mobility patterns and detect trajectories that deviate from physical laws (e.g., GPS spoofing). Unlike standard diffusion models, Pi-DPM integrates kinematic constraints from simplified bicycle models, ensuring generated or reconstructed trajectories remain physically plausible. This physics-informed regularization reduces false positives and improves interpretability for human analysts.
- Detecting GPS spoofing in maritime and urban mobility (e.g., illicit oil transfers, unauthorized fishing).
- Identifying anomalous behaviors in vehicle and vessel trajectories.
- Trajectory generation and augmentation with physics-based guarantees.
- Anomaly Detection (Core focus): Detects physically implausible trajectories by computing reconstruction errors and applying a user-defined threshold.
- Context- and Physics-Informed Modeling: Combines a Context-Informed Encoder (CIE) for spatiotemporal attention with a Physics-Informed Decoder (PID) constrained by the kinematic bicycle model (KBM).
- Trajectory Generation: Produces synthetic, realistic trajectories for augmentation and downstream tasks.
- Robust to Noise and Data Scarcity: Outperforms purely data-driven generative models by incorporating prior physical knowledge.
Pi-DPM is implemented in Python (>=3.8) and PyTorch (>=1.7). Key dependencies:
python>=3.7
torch>=1.7
pandas
numpy
matplotlib
pathlib
shutil
datetime
colored
math
-
Clone the repository: Download the Pi-DPM repository to your local machine, either via git or as a ZIP download. git clone https://github.com/arunshar/Physics-Informed-Diffusion-Probabilistic-Model.git cd Pi-DPM
-
Installation Dependencies: Pi-DPM is built with Python (>=3.8) and PyTorch. Install the required packages using pip (it is recommended to use a virtual environment): pip install -r requirements.txt
Once the environment is set up, you can use the provided scripts to train the model, detect anomalies on new trajectories, and generate synthetic trajectories. Below are the typical usage steps:
Once the environment is set up, you can use the provided scripts to train the model, detect anomalies on new trajectories, and generate synthetic trajectories. Below are the typical usage steps: python scripts/train.py --data data/train_dataset.csv --epochs 100 --batch_size 64 --out checkpoints/
In this example: --data specifies the path to the training dataset of normal trajectories. --epochs and --batch_size control the training iterations and batch size. --out is the directory to save model checkpoints and training logs.
Train Pi-DPM on your trajectory dataset by running the training script. This will learn the diffusion model on normal trajectory patterns: python scripts/detect.py --model checkpoints/pidpm_model.pth --data data/test_dataset.csv --threshold 0.1 --output results/anomalies.csv
Here:
--model: Trained Pi-DPM model checkpoint.--data: Input trajectory dataset.--threshold: Reconstruction error threshold (λ). Trajectories with error ≥ λ are flagged as anomalies.--output: Save results (scores, anomaly flags) to CSV.
The script will reconstruct or evaluate each trajectory and compute an anomaly score (e.g., based on reconstruction error). If a --threshold is provided, the script will label trajectories with a score above this threshold as anomalies. --output (optional) can be used to save the anomaly detection results (e.g., anomaly scores or flags for each trajectory) to a CSV file.
Pi-DPM can also generate new, synthetic trajectories that mimic the normal behavior learned from the training data. This can be useful for data augmentation or simulating trajectories under the learned model: python scripts/generate.py --model checkpoints/pidpm_model.pth --num_samples 50 --out results/synthetic_trajectories.csv
Physics-Informed-Diffusion-Probabilistic-Model/
├── pidpm/ # Core Python package for the Pi-DPM model
│ ├── __init__.py # Init file for package
│ ├── diffusion.py # Diffusion model implementation (forward & reverse process)
│ ├── physics.py # Module for physics-informed constraints and losses
│ ├── models.py # Neural network architectures for trajectory encoding/decoding
│ ├── utils.py # Helper functions (data loading, metrics, etc.)
│ └── __init__.py # Init file for package
├── scripts/ # Scripts for training, inference, and generation
│ ├── train.py # Script to train the Pi-DPM model on a dataset
│ ├── detect.py # Script to compute anomaly scores for trajectories using a trained model
│ └── generate.py # Script to generate synthetic trajectories from the model
├── data/ # Directory for datasets (user-provided, not included in repository)
│ └── sample_dataset.csv # Example placeholder for trajectory data
├── results/ # Output directory for results (model checkpoints, anomaly outputs, synthetic data)
├── requirements.txt # List of required Python packages for Pi-DPM
├── LICENSE # MIT License for this project
└── README.md # Project documentation (this file)
Pi-DPM achieves higher accuracy and F1-scores than state-of-the-art anomaly detection methods (iBAT, iBOAT, CausalTAD, LM-TAD). Incorporating both KBM (physics priors) and CIE (contextual encoder) yields the best results across maritime (MarineCadastre, DMA) and urban (Geolife) datasets. Ablation studies show that ignoring physics constraints significantly reduces detection performance.
If you use Pi-DPM, please cite:
@inproceedings{sharma2025pidpm,
title={Towards Physics-Informed Diffusion for Anomaly Detection in Trajectories: A Summary of Results},
author={Sharma, Arun and Yang, Mingzhou and Farhadloo, Majid and Ghosh, Subhankar and Jayaprakash, Bharat and Shekhar, Shashi},
booktitle={Proceedings of the 33rd International Conference on Advances in Geographic Information Systems (GeoAnomalies'25)},
year={2025},
organization={ACM}
}