对于如何评价两条曲线的相似度现已经存在许多较为直接有效的方法,诸如基于各种距离测度的距离评判、利用相关系数进行相似度分析等等,其中对于距离测度运用较为广泛便是欧式距离、Hausdorff距离等等。而在1906年法国数学家Maurice René Fréchet提出了一种基于空间路径相似度描述方式[1],其着重将路径空间距离考虑进去,使得其对于有一定空间时序的曲线相似度评价效率相比之下更高,这便是Fréchet distance(弗雷歇距离)。
对于其定义其中最为简单直观的一个理解,主人和狗在两条不同的轨迹上运动,主人和狗之间是由狗绳相连接的,Fréchet距离即两者能各自走完整个轨迹的情况下满足条件的狗绳的最短长度。
图2:A为主人行走轨迹,B为狗的运动轨迹,在此情况下可知Fréchet距离为0.25时刻或者0.75时刻人和狗之间的距离
离散Fréchet距离是连续Fréchet距离的近似,当曲线所选取的离散点足够多时离散Fréchet距离近似等于连续Fréchet距离。
Function dF(P,Q):real; F u n c t i o n d F ( P , Q ) : r e a l ;
input: i n p u t : P=(u1,...,up),Q=(v1,...,vq) P = ( u 1 , . . . , u p ) , Q = ( v 1 , . . . , v q )
return:δdF(P,Q) r e t u r n : δ d F ( P , Q )
ca: array [1..p,1..q] of real; c a : a r r a y [ 1.. p , 1.. q ] o f r e a l ;
function c(i,j):real; f u n c t i o n c ( i , j ) : r e a l ;
begin b e g i n
if ca(i,j)>−1 then return ca(i,j) i f c a ( i , j ) > − 1 t h e n r e t u r n c a ( i , j )
elseif i=1 and j=1 then ca(i,j):=d(u1,v1) e l s e i f i = 1 a n d j = 1 t h e n c a ( i , j ) := d ( u 1 , v 1 )
elseif i>1 and j=1 then ca(i,j):=max{c(i−1,1),d(ui,v1)} e l s e i f i > 1 a n d j = 1 t h e n c a ( i , j ) := max { c ( i − 1 , 1 ) , d ( u i , v 1 ) }
elseif i=1 and j>1 then ca(i,j):=max{c(1,j−1),d(u1,vi)} e l s e i f i = 1 a n d j > 1 t h e n c a ( i , j ) := max { c ( 1 , j − 1 ) , d ( u 1 , v i ) }
elseif i>1 and j>1 then ca(i,j):= e l s e i f i > 1 a n d j > 1 t h e n c a ( i , j ) :=
max{min(c(i−1,j),c(i−1,j−1),c(i,j−1)),d(ui,vi)} max { min ( c ( i − 1 , j ) , c ( i − 1 , j − 1 ) , c ( i , j − 1 ) ) , d ( u i , v i ) }
else ca(i,j)=∞ e l s e c a ( i , j ) = ∞
return ca(i,j); r e t u r n c a ( i , j ) ;
end; /∗ function c ∗/ e n d ; / ∗ f u n c t i o n c ∗ /
begin b e g i n
for i=1 to p do for j=1 to q do ca(i,j):=−1.0; f o r i = 1 t o p d o f o r j = 1 t o q d o c a ( i , j ) := − 1.0 ;
return c(p,q); r e t u r n c ( p , q ) ;
end. e n d .
function dF = DiscreteFrechetDistance(P,Q)
%%
%initialize
Size_P = size(P);
Size_Q = size(Q);
ca = ones(Size_P(1),Size_Q(1)) .* -1;
if Size_P(2) ~= Size_Q(2)
error('The input P and Q must be of the same dimension');
elseif Size_P(1) == 0 && Size_Q(1) == 0
dF = 0;
return;
end
dF = c(Size_P(1),Size_Q(1));
%%
%function c
function c_ij = c(i,j)
d = @(u,v) sqrt(sum((u - v).^2));
if ca(i,j) > -1
c_ij = ca(i,j);
elseif i==1 && j==1
ca(i,j) = d(P(1,:),Q(1,:));
c_ij = ca(i,j);
elseif i > 1 && j == 1
ca(i,j) = max(c(i - 1,1),d(P(i,:),Q(1,:)));
c_ij = ca(i,j);
elseif i == 1 && j > 1
ca(i,j) = max(c(1,j - 1),d(P(1,:),Q(j,:)));
c_ij = ca(i,j);
elseif i > 1 && j > 1
ca(i,j) = max(min([c(i - 1,j),c(i - 1,j - 1),c(i,j - 1)]),d(P(i,:),Q(j,:)));
c_ij = ca(i,j);
else
ca(i,j) = inf;
end
end
end
[1] Fréchet M M. Sur quelques points du calcul fonctionnel[J]. Rendiconti Del Circolo Matematico Di Palermo, 1906, 22(1):1-72.
[2] Wylie T, Zhu B. Intermittent Map Matching with the Discrete Fr\’echet Distance[J]. Eprint Arxiv, 2014.
[3] Alt H, Godau M. Computing the Fréchet Distance between Two Polygonal Curves[J]. International Journal of Computational Geometry & Applications, 1995, 5(01n02):75-91.
[4] Eiter T, Mannila H. Computing discrete Fréchet distance[R]. Tech. Report CD-TR 94/64, Information Systems Department, Technical University of Vienna, 1994.
[5] Timothy, Randall, Wylie. THE DISCRETE FRECHET DISTANCE AND APPLICATIONS[D]. Montana State University Bozeman, 2013,7-8.