Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DB-TRAD — Density-Based Trajectory Anomaly Detector (Hausdorff Neighborhood)

This repository provides a clean Python implementation of DB-TRAD, a density-based algorithm for detecting anomalous 2D trajectories using the Hausdorff neighborhood. It includes:

  • A minimal, dependency-light library (src/db_trad/) implementing:
    • directed and undirected Hausdorff distances for polylines
    • the DB-TRAD neighborhood queries and anomaly labeling
  • A synthetic trajectory dataset generator consistent with the paper’s setup
  • Reproducible experiments & figures (precision/recall vs. training set size)
  • A command‑line interface (scripts/run_experiment.py) to run sweeps and export results
  • Unit tests for core computations

Attribution / Credits
This implementation is inspired by and gives due credit to the paper:
“A Density-Based Algorithm for Detecting Anomalies in Trajectories” — Srikanth Baride, Rajesh P. Barnwal, CSIR-CMERI.
Please cite the original paper if you use this code or ideas in your work.

Quick Start

python -m venv .venv && source .venv/bin/activate  # on Windows: .venv\\Scripts\\activate
pip install -e .
python scripts/run_experiment.py --seed 42
python scripts/run_experiment.py --n-subsets 20 --eps 0.6 0.7 0.8 --min-trs 20 25 --make-plots

The script writes results into examples/outputs/ including CSVs and Matplotlib PNGs (and SVGs).

Library Usage

import numpy as np
from db_trad.db_trad import db_trad_labels
from db_trad.datasets import make_synthetic_subsets

subsets = make_synthetic_subsets(n_subsets=1, seed=7)
trajectories, true_labels = subsets[0]
pred = db_trad_labels(trajectories, eps=0.7, min_trs=20)

Notes on Design Choices

  • Hausdorff distance between polylines is implemented as the max of the two directed distances (max–min pointwise Euclidean), matching the definition used in the paper.
  • The hausdorff-neighborhood uses a threshold eps; inliers are those with at least min_trs neighbors within eps. Border trajectories have fewer than min_trs neighbors but lie in the neighborhood of an inlier. Others are labeled anomalous.
  • The synthetic data generator mirrors the paper’s configuration (five dense clusters + anomalies) but is provided here as reproducible NumPy code with fixed seeds.

Reproducing Figures

python scripts/run_experiment.py --n-subsets 50 --eps 0.5 0.6 0.7 0.8 0.9 --min-trs 20 25 --make-plots

This produces:

  • precision_vs_training_size.png / .svg
  • recall_vs_training_size.png / .svg
  • a sample panel plotting representative trajectories and anomaly labels

License

MIT (for this implementation). Please check the original paper for its own licensing terms.

Citation

If you use this implementation, please cite the following paper:

@inproceedings{barnwal2016density,
  title={A density-based algorithm for detecting anomalous trajectories},
  author={Barnwal, Rajesh P and Baride, S and Majumder, S and Ghosh, Soumya K},
  booktitle={2016 International Conference on Microelectronics, Computing and Communications (MicroCom)},
  pages={1--4},
  year={2016},
  organization={IEEE}
}

About

This repository provides a clean Python implementation of DB-TRAD, a density-based algorithm for detecting anomalous 2D trajectories using the Hausdorff neighborhood

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages