Computational Movement Analysis Lecture 1: Similarity Joachim Gudmundsson Aim Goal: Extract and make sense of information from trajectories (GPS, mobile, video, rfid…). Provide fundamental software tools to simplify and support qualitative analysis. Our model Input: Locations sampled over time 0 31 30 5 6 28 12 38 25 53 48 47 16 Our model Input: Locations sampled over time Assumptions: a) Straight-line movement between consecutive samples b) Constant velocity 0 31 30 5 6 28 12 38 25 53 48 47 16 Brownian bridge movement model Input: Locations sampled over time Other models? Brownian bridge Brownian motion conditioned under starting and ending position Probability that object visits region A Our model Input: a sequence of (x,y,t) - coordinates and a time stamp for example GPS data, mobile phone, radar, … Additional information Input: a sequence of (x, y, t, z, temperature, speed, direction…) Trajectory data 2005 Animal Country Number Frequency Wolves Spain 15 Daily Wolves Finland 16 4 hours Elks Sweden 25 30 min Reindeer Finland 19 8 hours Red deer Germany 7 4 hours Leopards South Africa 32 Daily Mountain Goats USA 32 3 hours Trajectory data 2011 Objects Number Frequency Football 23 25Hz Supermarket large 100Hz Mobile phones huge 5 min Applications: Behavioural ecology › Migration patterns › “Popular places” › Home region ›… Applications: Behavioural ecology › Migration patterns › “Popular places” › Home range › Flock movements ›… Applications: Behavioural ecology • Interaction between jackdaws? • Effect of external factors ? [Joint work: Georgina Wilcox, Kevin buchin, Maike Buchin, Ran Nathan and Anael Engel] Applications: Behavioural ecology Behavioural ecology Short term: - Annual migration behaviour - Automatically detect activity - Home range Long term: - Foraging search strategies - Factors that may influence animal movement - How changes in the environment affects wildlife Applications: Sport Data Accuracy: 100 mm Frequency: 25Hz [Joint work: Thomas Wolle and many others] Applications: Sport Tools • • • to support sports analysts and coaches Evaluate a players ability to pass (receive, execute…) Evaluate a players ability to move into open areas Evaluate a players ability to follow instructions • Detect frequent movement patterns • Detect correlations between players’ movement • Detect frequent passing patterns • Analyse turn-overs • Which events change the intensity of the game? • … Applications: Hurricanes Goal: Early detection of hurricanes that may hit land Applications: Transport › Collision prevention › Maximize unloading/loading Applications: Shopping behaviour › Detect movement patterns › Change structure of shop to increase sales? Examples of general problems General problems Repetitive patterns Popular places Trajectory segmentation Trajectory simplification Trajectory clustering Subtrajectory clustering Movement patterns • Single file • Formations • Leadership • Meetings • … • • • • • • • Seminar schedule Lecture 1: Similarity Lecture 2: Curve clustering Lecture 3: Simplification Lecture 4: Movement patterns Lecture 5: Trajectory segmentation Fundamental tools: clustering When are two trajectories similar? In most cases the spatial similarity is much more important than the temporal aspect. Similarity of curves…measurements Agrawal, Lin, Sawhney & Shim, 1995 Alt & Godau, 1995 Yi, Jagadish & Faloutsos, 1998 Gaffney & Smyth, 1999 Kalpakis, Gada & Puttagunta, 2001 Vlachos, Gunopulos & Kollios, 2002 Gunopoulos, 2002 Mamoulis, Cao, Kollios, Hadjieleftheriou, Tao & Cheung, 2004 Chen, Ozsu & Oria, 2005 Nanni & Pedreschi, 2006 Van Kreveld & Luo, 2007 Gaffney, Robertson, Smyth, Camargo & Ghil, 2007 Lee, Han & Whang, 2007 Buchin, Buchin, van Kreveld & Luo, 2009 Agarwal, Aranov, van Kreveld, Löffler & Silveira, 2010 Sankaraman, Agarwal, Molhave, Pan and Boedihardjo, 2013 ... Similarity measures Input: Two polygonal curves P and Q of size m in Rd Approach: Map curve into a point in dm-dimensional space 2D 10D Similarity measures Input: Two polygonal curves P and Q of size m in Rd Approach: Map curve into a point in dm-dimensional space Similar? 10D 2D Similarity measures Input: Two polygonal curves P and Q of size m in Rd Approach: Map curve into a point in dm-dimensional space Drawbacks: P and Q must have same number points Only takes the vertices into consideration 2D Not similar 6D Similarity measures: Hausdorff Input: Two polygonal curves P and Q in Rd Distance: Hausdorff distance H(PQ) = maxpP minqQ |p-q| dH(P,Q) = max [H(PQ), H(QP)] Similarity measures: Hausdorff Input: Two polygonal curves P and Q in Rd Distance: Hausdorff distance H(PQ) = maxpP minqQ |p-q| dH(P,Q) = max [H(PQ), H(QP)] P Q P Q Similarity measures: Hausdorff Input: Two polygonal curves P and Q in Rd Distance: Hausdorff distance H(PQ) = maxpP minqQ |p-q| dH(P,Q) = max [H(PQ), H(QP)] P Q Drawbacks: Fail to capture the distance between curves. Similarity measures: Fréchet Input: Two polygonal curves P and Q in Rd Other interesting measures are: • Dynamic Time Warping (DTW) • Longest Common Subsequence (LCSS) • Model-Driven matching (MDM) Drawback: Non-metrics (triangle inequality does not hold) which makes clustering complicated. Similarity measure: Fréchet Distance Fréchet Distance measures the similarity of two curves. Dog walking example - Person is walking his dog (person on one curve and the dog on other) - Allowed to control their speeds but not allowed to go backwards! - Fréchet distance of the curves: minimal leash length necessary for both to walk the curves from beginning to end Fréchet Distance Fréchet Distance measures the similarity of two curves. Dog walking example - Person is walking his dog (person on one curve and the dog on other) - Allowed to control their speeds but not allowed to go backwards! - Fréchet distance of the curves: minimal leash length necessary for both to walk the curves from beginning to end Fréchet Distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. The Fréchet distance between P and Q is: 𝛿𝐹 (P,Q) = 𝛼:[0,1]→𝑃 inf max |𝑃(𝛼 𝑡 ∈[0,1] 𝑡 ) − 𝑄(𝛽 𝑡 )| 𝛽:[0,1]→𝑄 where and range over all continuous non-decreasing reparametrizations. Note that (0)=p1, (1)=pn, (0)=q1 and (1)=qm. Well-suited for the comparison of curves since it takes the continuity of the curves into account. Discrete Fréchet Distance The discrete Fréchet distance considers only positions of the leash where its endpoints are located at vertices of the two polygonal curves and never in the interior of an edge. May give large errors! Compute the continuous Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P P Q r Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P r Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P r Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? P Q P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? Freespace diagram of P and Q P free space Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? How do we find a reparametrization between P and Q that realises the Fréchet distance r? P Q Compute the Fréchet distance Input: Two polygonal chains P=p1, … , pn and Q=q1, … , qm in Rd. Decision problem: F(P, Q) ≤ r ? How do we find a reparametrization between P and Q that realises the Fréchet distance r? P Recall that it has to be continuous, non-decreasing, q1 p1 and qm pn. Q Compute the Fréchet distance › q1 p1 P Q Compute the Fréchet distance › q1 p1 › qm pn P Q Compute the Fréchet distance › q1 p1 › qm pn › must lie in the free space Not valid! P Q Compute the Fréchet distance › q1 p1 › qm pn › must lie in the free space › continuous P Q Compute the Fréchet distance › q1 p1 › qm pn › must lie in the free space › continuous › non-decreasing P Q Compute the Fréchet distance › q1 p1 › qm pn › must lie in the free space P › continuous › non-decreasing Q If there exists an xy-non-decreasing path inside the freespace from the bottom left to the top right corner of the diagram then the Fréchet distance is at most r. Free Space Diagram Decision version Is the Fréchet distance between two paths at most r? P P Q r Q Free Space Diagram Decision version Is the Fréchet distance between two paths at most r? P r Q Free Space Diagram If there exists a non-decreasing path in the free space from (q1,p1) to (qm,pn) which is non-decreasing in both coordinates, then curves P and Q have Fréchet distance at most r. P (qm, pn) P Q r (q1,p1) Q Free Space Diagram If there exists a non-decreasing path in the free space from (q1,p1) to (qm,pn) which is non-decreasing in both coordinates, then curves P and Q have Fréchet distance at most r. P (qm, pn) P Q r (q1,p1) Q Free Space Diagram If there exists a non-decreasing path in the free space from (q1,p1) to (qm,pn) which is non-decreasing in both coordinates, then curves P and Q have Fréchet distance at most r. P (qm, pn) P Q r (q1,p1) Q Free Space Diagram If there exists a non-decreasing path in the free space from (q1,p1) to (qm,pn) which is non-decreasing in both coordinates, then curves P and Q have Fréchet distance at most r. P (qm, pn) P Q r (q1,p1) Q Free Space Diagram If there exists a non-decreasing path in the free space from (q1,p1) to (qm,pn) which is non-decreasing in both coordinates, then curves P and Q have Fréchet distance at most r. P (qm, pn) P Q r (q1,p1) Q Free Space Diagram If there exists a non-decreasing path in the free space from (q1,p1) to (qm,pn) which is non-decreasing in both coordinates, then curves P and Q have Fréchet distance at most r. P (qm, pn) P Q r (q1,p1) Q Free Space Diagram If there exists a non-decreasing path in the free space from (q1,p1) to (qm,pn) which is non-decreasing in both coordinates, then curves P and Q have Fréchet distance at most r. P (qm, pn) P Q r (q1,p1) Q Free Space Diagram If there exists a non-decreasing path in the free space from (q1,p1) to (qm,pn) which is non-decreasing in both coordinates, then curves P and Q have Fréchet distance at most r. P (qm, pn) P Q r (q1,p1) Q Free Space Diagram If there exists a non-decreasing path in the free space from (q1,p1) to (qm,pn) which is non-decreasing in both coordinates, then curves P and Q have Fréchet distance at most r. P (qm, pn) P Q r (q1,p1) Q Decision algorithm: free space diagram Algorithm: 1. Compute Free Space diagram O(mn) time A square and an ellipsoid can intersect in at most 8 points. (critical points) The free space in a cell is a convex region. One cell can be constructed in time O(1). Compute the Fréchet distance One cell can be constructed in time O(1). How? Note that we do not need the exact shape. We only need the intersection points between the cell boundary and the ellipsoid. P Q P Q Compute the Fréchet distance One cell can be constructed in time O(1). How? Note that we do not need the exact shape. We only need the intersection points between the cell boundary and the ellipsoid. P Q P Q Compute the Fréchet distance One cell can be constructed in time O(1). How? Note that we do not need the exact shape. We only need the intersection points between the cell boundary and the ellipsoid. P Q P Q Compute the Fréchet distance One cell can be constructed in time O(1). How? Note that we do not need the exact shape. We only need the intersection points between the cell boundary and the ellipsoid. P Q P Q Compute the Fréchet distance One cell can be constructed in time O(1). How? Note that we do not need the exact shape. We only need the intersection points between the cell boundary and the ellipsoid. P Q P Q Compute the Fréchet distance One cell can be constructed in time O(1). How? Note that we do not need the exact shape. We only need the intersection points between the cell boundary and the ellipsoid. P Q P Q Decision algorithm: free space algorithm Algorithm: 1. Compute Free Space diagram O(mn) time Critical points A square and an ellipsoid can intersect in at most 8 points. The free space in a cell is a convex region. One cell can be constructed in time O(1). Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). Build network O(mn) time. P (q1,p1) Q Decision algorithm: compute path Algorithm: 1. Compute Free Space diagram mn cells O(mn) time (qm,pn) 2. Compute a non-xy-decreasing path from (q1,p1) to (qm,pn). Build network O(mn) time. Find a path O(mn) time. P (q1,p1) Q Compute the Fréchet distance Theorem: Given two polygonal curves P, Q and r0 one can decide in O(mn) time, whether (P,Q) r. How can we use the algorithm to compute the Fréchet distance? Binary search on r? But what do we do binary search on? Compute the Fréchet distance Theorem: Given two polygonal curves P, Q and r0 one can decide in O(mn) time, whether (P,Q) r. How can we use the algorithm to compute the Fréchet distance? In practice: Determine r bit by bit O(mn log “accuracy”) time. Compute the Fréchet distance Assume r=0 and the let r grow. The free space will become larger and larger. Aim: Determine the smallest r such that it contains a montone path from (q1,p1) to (qm,pn). This can only occur when: 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Case 2: Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Case 2: Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Case 2: Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Case 2: Number of events? Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Case 2: Number of events: O(mn) Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Case 2: O(mn) events Case 3: Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Case 2: O(mn) events Case 3: Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Case 2: O(mn) events Case 3: Number of events? Compute the Fréchet distance 1. r is minimal with (q1,p1) to (qm,pn) in the free space, 2. r is minimal when a new vertical or horizontal passage opens up between two adjacent cells in the free space. 3. r is minimal when a new vertical or horizontal passage opens up between two non-adjacent cells in the free space. Case 1 is easy to test in constant time. Case 2: O(mn) events Case 3: O(m2n+mn2) Compute the Fréchet distance Case 1: easy to test in constant time. Case 2: O(mn) possible events Case 3: O(m2n+mn2) possible events Perform binary search on the events O((m2n+mn2) log mn) time. Compute the Fréchet distance Case 1: easy to test in constant time. Case 2: O(mn) possible events Case 3: O(m2n+mn2) possible events Improvement: Use parametric search [Meggido’83, Cole’88] O(mn log mn) time. Parametric search The decision version F(r) of the Fréchet distance depends on the parameter r, and it is monotone in r. Aim: Find minimum r such that F(r) is true. Our algorithm As can solve F(r) in Ts=O(mn) time. Meggido’83 and Cole’88 (simplified): If there exists a parallel algorithm Ap that can solve F(r) in Tp time using P processors then there exists a sequential algorithm with running time O(PTp+TpTs+Ts log P). For our problem we get: O(mn log mn) time using a parallel sorting network [n processors and O(log n) time] Compute the Fréchet distance Case 1: easy to test in constant time. Case 2: O(mn) possible events Case 3: O(m2n+mn2) possible events Improvement: Use parametric search [Meggido’83, Cole’88] O(mn log mn) time. Summary: Lecture 1 Many different similarity measures. We use the Fréchet distance! Theorem: Given two polygonal curves P, Q and r 0 one can decide in O(mn) time, whether (P,Q) r. Theorem: The Fréchet distance between two polygonal curves P and Q can be computed in O(mn log mn) time. Open problems 1. Can the Fréchet distance be computed in subquadratic time or is there an (n2) lower bound? 2. Approximate the Fréchet distance in subquadratic time? 3. Special cases in subquadratic time? If the curves are c-packed then a (1+ )-approximation of the Fréchet distance can be computed in O(cn/+cn log n). similar results for low density. [Driemel, Har-Peled and Wenk’12] Open problems 1. Can the Fréchet distance be computed in subquadratic time or is there an (n2) lower bound? 2. Approximate the Fréchet distance in subquadratic time? 3. Special cases in subquadratic time? If the curves are c-packed then a (1+ )-approximation of the Fréchet distance can be computed in O(cn/+cn log n). similar results for low density. [Driemel, Har-Peled and Wenk’12] Part of P inside any ball B is at most c times the radius of B. References H. Alt and M. Godau. Computing the Fréchet distance between two polygonal curves. IJCGA, 1995. K. Buchin, M. Buchin, W. Meulemans and W. Mulzer. Four Soviets Walk the Dog - with an Application to Alt's Conjecture SODA, 2014 Time: O(n2 (log n)1/2 (loglog n)3/2) R. van Oostrum and R. Veltkamp. Parametric search made practical. CGTA, 2004