High-dimensional curves: comparison with Fred
This page compares FrechetDist with Fred (Dennis Rohde's C++ library with Python bindings, version 1.14.5) on real curves in ℝ^963, ℝ^6000 and ℝ^19200: the continuous Fréchet distance between every pair of curves in three datasets. The scripts are in example_higher/ of the repository; see Reproducing the results.
In short:
- Faster. On one thread, FrechetDist's exact algorithm takes 3.3 s for 45 traffic pairs (Fred: 52.1 s) and 5.7 s for 10 video pairs (Fred: 102.7 s): 16 and 18 times faster than Fred. On all 16 hardware threads of the machine it takes 0.64 s and 0.65 s: 81 and 158 times faster than Fred. On the hydraulic curves in ℝ^6000,
frechet_c_computecomputes all 15 distances of the full curves (2205 vertices) in 227 s, where the paper they come from reports hours. - Correct where Fred is not. Fred returns a distance that is too low for 5 of the 55 traffic and video pairs, by up to 1.3%, although it was asked for 10⁻⁹ relative accuracy. No matching of the two curves achieves the distance it returns. FrechetDist's results agree with an independent decision procedure.
- Exact.
frechet_c_compute_exacthas no tolerance: it returns the exact distance (a critical value of Alt and Godau, computed in floating point).frechet_c_computereturns the leash of an actual matching, with a certified lower bound, to a chosen tolerance; at the default 10⁻⁵ it takes 3.2 s and 4.1 s for the traffic and video pairs, 9 and 13 times faster than Fred at the same tolerance.
The datasets
| Set | Curves | Pairs | Vertices per curve | Dimension | Source |
|---|---|---|---|---|---|
| Freeway traffic | 10 days | 45 | 144 | 963 | UCI PEMS-SF |
| Video | 5 clips | 10 | 64–150 | 19 200 | KTH human actions |
| Hydraulic sensors | 6 sensors | 15 | 200 (against Fred), 2205 | 6000 | UCI hydraulic test rig |
- Freeway traffic (PEMS-SF, CC BY 4.0). Occupancy rates of 963 freeway sensors in the San Francisco Bay Area, every 10 minutes. Each day (2008–2009) is a curve: 144 vertices, one per 10 minutes, each holding the 963 sensor readings. The first 10 days are used.
- Video (KTH; Schuldt, Laptev and Caputo, ICPR 2004). Grayscale 160×120 video at 25 frames per second. Each frame is a vertex, its 19 200 pixels scaled to [0, 1]. A curve is the first repetition of an action in a video (64 to 150 frames), outdoors, for persons walking and boxing; the first 5 curves are used.
- Hydraulic sensors (UCI). Six pressure sensors PS1–PS6 of a hydraulic test rig. Each vertex is one machine cycle, its 6000 samples (60 s at 100 Hz) the coordinates. These are the curves of Meintrup, Munteanu and Rohde, Random Projections and Sampling Algorithms for Clustering of High-Dimensional Polygonal Curves (NeurIPS 2019), who report "roughly three hours" for a sequential implementation of Alt and Godau's algorithm. Fred is compared on their first 50, 100 and 200 vertices, where it takes 1.5, 6.2 and 25.8 s for the 15 pairs: its time grows quickly with the length.
What is compared
| Computes | Accuracy | Threads | |
|---|---|---|---|
frechet_c_compute_exact(P, Q) | the exact distance | exact: no tolerance | the tables use all threads; otherwise one |
frechet_c_compute(P, Q, true, tol) | a matching (Morphing) whose leash is the distance, and a certified lower bound | relative tol (10⁻⁹ or the default 10⁻⁵) | one |
Fred continuous_frechet | a value | asked for continuous_frechet_error percent (10⁻⁷ or 10⁻³, i.e. 10⁻⁹ or 10⁻⁵ relative) | one |
frechet_c_compute_exact implements the randomized algorithm of Har-Peled and Raichel, "The Fréchet distance revisited and extended" (Section 6), for two curves. The distance is one of the critical values of Alt and Godau (vertex–vertex, vertex–segment and monotonicity events), the smallest one that the free-space decision procedure accepts:
- It tabulates, for every vertex of one curve and every segment of the other, the closest point on the segment's line and the squared distance to it, and all vertex–vertex distances: O(nmd) time, once, on all threads.
- It draws 4N² random critical values from the tables (N the larger number of vertices), sorts them, and binary searches them with the decision procedure. This leaves an interval holding the distance and, with high probability, only O(N log N) critical values.
- It lists the critical values in that interval. The monotonicity values come from a kinetic sweep along each segment, which keeps the intersection points of the growing spheres in a balanced search tree (O(log N) per event).
- It binary searches the list. Each decision reads the tables, O(nm) time.
The result does not depend on the random choices, bit for bit; only the running time does. frechet_c_decide_exact(P, Q, r), the decision procedure (is the distance at most r?), is exported too.
frechet_c_compute computes lower and upper bounds that meet: it simplifies the curves, computes the VE-retractable Fréchet distance between the simplifications (a lower bound) and a monotone matching (an upper bound), and refines until the two agree to the tolerance. Its result is the leash of an actual matching, which it returns, so it is never below the true distance.
Fred computes the continuous Fréchet distance by a binary search with the Alt–Godau decision procedure, stopping when its bounds are within continuous_frechet_error percent.
Results
AMD Ryzen 7 5700G (8 cores, 16 hardware threads), 62 GB, Julia 1.13.4, Python 3.14.10, Fred 1.14.5. Times are for all pairs of a set, excluding compilation. "Wrong" counts the pairs more than 10⁻⁸ relative away from the exact distance. ruby examples/benchmarks/reproduce.rb fred hydraulic reruns everything (about 15 minutes).
High accuracy: 10⁻⁹
| Set | Fred | frechet_c_compute | exact, 1 thread | exact, 16 threads | Speed-up over Fred (exact, 1 / 16 threads) |
|---|---|---|---|---|---|
| Traffic, ℝ^963, 45 pairs | 52.1 s | 8.3 s | 3.3 s | 0.64 s | 16× / 81× |
| Video, ℝ^19200, 10 pairs | 102.7 s | 6.8 s | 5.7 s | 0.65 s | 18× / 158× |
| Hydraulic, ℝ^6000, 200 vertices, 15 pairs | 25.8 s | 1.4 s | 8.7 s | 0.94 s | 3× / 27× |
| Hydraulic, ℝ^6000, 2205 vertices, 15 pairs | – | 226.7 s | – | – | – |
| Set | Fred: wrong | Fred: worst | frechet_c_compute: worst |
|---|---|---|---|
| Traffic | 4 of 45 | −1.3% | +2.5·10⁻¹⁰ |
| Video | 1 of 10 | −1.3% | +8.8·10⁻¹⁰ |
| Hydraulic, 200 vertices | 0 of 15 | +8.6·10⁻¹⁰ | 1.5·10⁻¹⁴ |
On the truncated hydraulic curves frechet_c_compute beats the exact algorithm (1.4 s against 8.7 s): for a few hundred vertices in ℝ^6000, the tables (O(nmd)) cost more than the bisection saves.
Practical accuracy: 10⁻⁵
The package's default tolerance for frechet_c_compute, and Fred at 10⁻³ percent.
| Set | Fred | frechet_c_compute | exact, 16 threads | Speed-up over Fred (frechet_c_compute / exact, 16 threads) |
|---|---|---|---|---|
| Traffic, ℝ^963, 45 pairs | 29.4 s | 3.2 s | 0.64 s | 9.2× / 46× |
| Video, ℝ^19200, 10 pairs | 54.1 s | 4.1 s | 0.65 s | 13× / 83× |
frechet_c_computekeeps its tolerance: every result is within 10⁻⁵ of the exact distance (worst +8.7·10⁻⁶), and never below it by more than rounding (2·10⁻¹⁴).- Fred does not: the same 4 traffic pairs and 1 video pair as at 10⁻⁹ are too low, by up to 1.3%.
Notes
- Fred's errors are all too low. The distance Fred returns for these pairs is not the leash of any matching: the decision procedure rejects it. For the traffic pair of days 7 and 9, Fred returns 1.8692; the distance is 1.8946.
- Two independent checks. On the traffic and video sets,
example_higher/check_frechet.jl, a textbook Alt–Godau decision procedure written from scratch (no shared code), confirms the results offrechet_c_compute(within 8.8·10⁻¹⁰) and finds the same 5 answers of Fred below the true distance. On the hydraulic curves,frechet_c_computeandfrechet_c_compute_exactagree to 1.5·10⁻¹⁴. - The paper's experiment. Meintrup, Munteanu and Rohde report "roughly three hours" for their sequential Alt–Godau implementation on the full hydraulic curves, and about 30 s with random projections and CUDA on Nvidia K40 GPUs. Their hardware and implementations differ, and they do not say whether the times are per distance or for all 15.
frechet_c_computetakes 0.7 to 49 s per pair on one thread.
Code
High-dimensional curves should use Vector points (GPntSeq{AnyDim,Float64,Vector{Float64}}): the code is compiled once for every dimension (static points, Point{D}, are compiled for each D, which takes minutes at D = 6000). A matrix with one column per vertex converts directly:
using FrechetDist
using BasicCompGeometry: AnyDim, GPntSeq
const Curve = GPntSeq{AnyDim,Float64,Vector{Float64}}
curve(M::Matrix{Float64}) = Curve([M[:, j] for j in axes(M, 2)]) # D × n: one column per vertex
P, Q = curve(A), curve(B)
d = frechet_c_compute_exact(P, Q) # the exact distance
frechet_c_decide_exact(P, Q, d) # true: some matching has leash d
m = frechet_c_compute(P, Q) # tolerance 1e-5 (the default)
m.leash, m.lower_bound # the distance is between these two
m = frechet_c_compute(P, Q, true, 1e-9) # tighterStart Julia with -t auto (or set JULIA_NUM_THREADS=auto) for the exact algorithm to use all cores; the result is the same for any number of threads.
The same distance with Fred, as example_higher/fred_curves.py runs it:
import Fred
Fred.config.continuous_frechet_error = 1e-7 # percent: 1e-9 relative
Fred.config.number_threads = 1
Fred.continuous_frechet(Fred.Curve(A), Fred.Curve(B)).value # A, B: n × D arraysReproducing the results
ruby examples/benchmarks/reproduce.rb fred hydraulic downloads the data and Fred, runs all of the following, and writes the tables (see Reproducing the benchmarks). By hand, from the repository root (the examples have their own environment, example_higher/Project.toml; see example_higher/README.md for installing Fred):
ruby example_higher/prepare_pems.rb # traffic: download, convert
ruby example_higher/prepare_kth.rb # video: download, convert (needs ffmpeg)
ruby example_higher/download_hydraulic.rb # hydraulic sensors
python example_higher/fred_curves.py pems 1 10 # Fred: all pairs of days 1-10
python example_higher/fred_curves.py kth 1 5
python example_higher/fred_hydraulic.py 50,100,200 # the first 50, 100, 200 vertices
julia -t 1 example_higher/curves.jl pems 1 10 # frechet_c_compute, tolerance 1e-9
julia -t 1 example_higher/curves.jl kth 1 5
julia -t 1 example_higher/hydraulic.jl 50,100,200
julia -t 1 example_higher/hydraulic.jl 2205 # the full curves
julia -t auto example_higher/exact_curves.jl pems 1 10 # frechet_c_compute_exact, and
julia -t auto example_higher/exact_curves.jl kth 1 5 # the errors of the others
julia -t auto example_higher/exact_curves.jl hydraulic 200
julia example_higher/check_frechet.jl pems 1 10 # independent check
julia example_higher/check_frechet.jl kth 1 5The environment variable FRECHET_TOL (default 1e-9) sets the relative tolerance of curves.jl, hydraulic.jl and fred_curves.py (Fred: 100 × FRECHET_TOL percent); results at other tolerances go to their own files.