traj-dist-rs
High-performance trajectory distance & similarity measures in Rust and Python.
A high-performance Rust implementation of trajectory distance algorithms with Python bindings, offering significant speed improvements over the original traj-dist library.
About
traj-dist-rs is a high-performance trajectory distance calculation library written in Rust, providing both native Rust APIs and Python bindings via PyO3. It is a complete rewrite of the original traj-dist library, focusing on performance optimization and modern language features.
Why traj-dist-rs?
- Performance: ~82x faster than Python implementation and ~3x faster than Cython implementation on average
- Batch Computation: Native
pdistandcdistfunctions with parallel support up to 130x faster thantraj-dist - Zero Dependencies: Only requires numpy >= 1.21 - no heavy dependencies like polars, pyarrow, pandas, or shapely
- Safety: Rust's memory safety guarantees eliminate common runtime errors
- Cross-platform: Supports Linux, macOS, and Windows with native binaries
- Dual API: Use it from Python or Rust with minimal overhead
- Accuracy: All algorithms verified against original implementation with < 1e-8 error margin
Features
Supported Distance Algorithms
| Algorithm | Full Name | Best For |
|---|---|---|
| SSPD | Symmetric Segment-Path Distance | General similarity, noise tolerance |
| DTW | Dynamic Time Warping | Similarity with time warping, flexible alignment |
| Discret Frechet | Discrete Fréchet Distance | Geometric similarity, path-based matching |
| Hausdorff | Hausdorff Distance | Maximum distance, outlier-sensitive similarity |
| LCSS | Longest Common Subsequence | Robust similarity with noise tolerance |
| EDR | Edit Distance on Real sequence | Similarity with noise and outlier tolerance |
| ERP | Edit distance with Real Penalty | Robust similarity with gap handling |
Distance Types
- Euclidean - 2D Euclidean distance
- Spherical - Haversine distance for geographic coordinates
Batch Computation
pdist- Pairwise distance matrix for trajectory collections (compressed format)cdist- Cross-distance matrix between two trajectory collections- Parallel processing - Automatic parallelization using Rayon for large datasets
- Metric API - Type-safe configuration with factory methods
Additional Features
- Matrix return for DP-based algorithms (DTW, LCSS, EDR, ERP, Discret Frechet)
- Precomputed distance matrix support for efficient batch computations
- Zero-copy NumPy array support for optimal performance
- Pickle serialization for
DpResultobjects (compatible with joblib) - Comprehensive error handling for invalid inputs
- Full Python type hints for better IDE support
Keywords / Search Terms
Common search terms related to this library:
- Core concepts: trajectory similarity, trajectory distance, similarity measures, trajectory analysis
- Algorithms: DTW, LCSS, EDR, ERP, Fréchet distance, Hausdorff distance, SSPD
- Applications: trajectory clustering, trajectory similarity search, nearest neighbor retrieval, mobility data analysis, GPS trace analysis
- Domains: time series similarity, spatiotemporal data, movement pattern mining, anomaly detection
Migration from traj-dist
If you used the original traj-dist library for trajectory similarity measurement, this library is compatible and offers significant performance improvements:
- Algorithm compatibility: Core algorithms (SSPD, DTW, Hausdorff, LCSS, EDR, ERP) supported
- Performance: 3-10x faster than Cython implementation