movingpandas.Trajectory.lcss_distance#
- Trajectory.lcss_distance(other, epsilon, delta=None)#
Return the Longest Common Subsequence (LCSS) distance to the other trajectory or geometric object.
LCSS counts how many points can be matched between the two ordered sequences such that each matched pair is within
epsilonand, ifdeltais given, no more thandeltapositions apart in the sequences. The similarity is that count divided by the length of the shorter sequence, and the returned distance is1 - similarity. So 0 means every point of the shorter trajectory found a match, i.e. it is essentially a (noisy) subsequence of the other, and 1 means no points match withinepsilon. Points of the longer trajectory that are left over do not count against the result. Because unmatched points are simply skipped, LCSS is more robust to noise and outliers than DTW and Fréchet distance, which must account for every point. Values are only comparable between trajectory pairs when they were computed with the sameepsilonanddelta.The similarity is computed with a vectorized dynamic program that keeps only two anti-diagonals of the DP matrix in memory. Without
deltathe computation takes O(n*m) time and O(n+m) memory. Withdeltaonly the band of cells at mostdeltapositions off the diagonal is evaluated, taking O((n+m) * delta) time, so a smalldeltamakes the computation linear in trajectory length.Distances are computed using Euclidean geometry, so a
UserWarningis raised for trajectories in a geographic (lat/lon) CRS. Project to a suitable planar CRS first for meaningful results.- Parameters:
other (Trajectory, LineString, or Point) – Other trajectory or geometric object
epsilon (float) – Spatial matching threshold, in CRS units. Two points are considered a match when their Euclidean distance is at most
epsilon.delta (int, optional) – Maximum allowed difference between the sequence positions of two matched points. Default None (no constraint on sequence alignment).
- Returns:
LCSS distance in the range [0, 1] (dimensionless)
- Return type:
float