{"id":1715,"date":"2021-01-24T13:45:23","date_gmt":"2021-01-24T13:45:23","guid":{"rendered":"http:\/\/192.168.31.181\/muthu\/?p=1715"},"modified":"2021-05-24T03:53:08","modified_gmt":"2021-05-24T03:53:08","slug":"computing-the-discrete-frechet-distance-using-dynamic-programming","status":"publish","type":"post","link":"http:\/\/write.muthu.co\/computing-the-discrete-frechet-distance-using-dynamic-programming\/","title":{"rendered":"Computing the discrete Fr\u00e9chet distance using dynamic programming"},"content":{"rendered":"\n

Definition<\/h2>\n\n\n\n

The Fr\u00e9chet distance is usually explained using the analogy of a man walking his dog.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

A man is walking a dog on a leash: the man can move on one curve, the dog on the other; both may vary their speed, but backtracking is not allowed. What is the length of the shortest leash that is sufficient for traversing both curves?<\/p>\n\n\n\n

Intuition<\/h2>\n\n\n\n

We can formally define it as: <\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Given two sequence of points in \\(\\mathbb{R}^d \\), p={p1, p2, p3…..pn} and q= {q1, q2, q3…. qm}, Fr\u00e9chet distance represented by \\(f(x,y) \\) is the maximum of the minimum distances between points pi<\/sub> and qi<\/sub>. To understand it more intuitively, let us look at a simple example. <\/p>\n\n\n\n

In the below graph, I have two set of polylines with positions:<\/p>\n\n\n\n

\\(P = {(2,1) , (3,1), (4,2), (5,1)} \\)
\\(Q = {(2,0),(3,0),(4,0)} \\)<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Starting and ending points being (p1,q1) and (p4,q3) respectively.<\/p>\n\n\n\n

We find all the pairs of walks between p and q given as,<\/p>\n\n\n\n

\\(p1 -> (p1, q1) , (p1,q2), (p1,q3)\\)
\\(p2 -> (p2, q1), (p2,q2), (p2,q3) \\)
\\(p3 -> (p3, q2), (p3,q2), (p3,q3) \\)
\\(p4 -> (p4, q2), (p4,q2), (p4,q3) \\)<\/p>\n\n\n\n

then, we find the minimum distances for each pair.<\/p>\n\n\n\n

\\(min\\{p1\\} = min\\{dist(p1,q1), dist(p1,q2), dist(p1,q3)\\} = min\\{1, 1.4, 2.2\\} = 1 \\)
\\(min\\{p2\\} = min\\{dist(p2,q1), dist(p2,q2), dist(p2,q3)\\} = min\\{1.4, 1, 1.4\\} = 1\\)
\\(min\\{p3\\} = min\\{dist(p3,q1), dist(p3,q2), dist(p3,q3)\\} = min\\{2.8, 2.2, 2\\} = 2 \\}\\)
\\(min\\{p4\\} = min\\{dist(p3,q1), dist(p3,q2), dist(p3,q3)\\} = min\\{3.2, 2.2, 2\\} = 2\\)<\/p>\n\n\n\n

Now, we can find the Fr\u00e9chet distance by finding the maximum of all the minimums we calculated in the last step.<\/p>\n\n\n\n

\\(f(x,y) = max\\{min\\{p1\\}, min\\{p2\\}, min\\{p3\\}, min\\{p4\\}\\} = max\\{1,1,2,2\\} = 2 \\)<\/p>\n\n\n\n

Implementation<\/h2>\n\n\n\n

The implementation described by Thomas Eiter and Heikki Mannila [1]<\/sup><\/sub> uses dynamic programming to reduce the time complexity of finding the Fr\u00e9chet distance by navigating through only three possible paths.<\/p>\n\n\n\n