DiscreteFrechetDist
计算离散的frechet 距离,通过计算两条曲线之间的点的距离,将两条曲线上的点按照距离以及曲线的趋势进行配对,最后根据这些配对的距离选出最后的离散frechet距离
(compute discrete frechet distance between two curves )
地图匹配算法实践:https://blog.csdn.net/happyduoduo1/article/details/51773613
路径相似性描述:https://zhuanlan.zhihu.com/p/20159963
function [cm, cSq] = DiscreteFrechetDist(P,Q,dfcn)
% Calculates the discrete Frechet distance between curves P and Q
%
% [cm, cSq] = DiscreteFrechetDist(P,Q)
% [cm, cSq] = DiscreteFrechetDist(...,dfcn)
%
% P and Q are two sets of points that define polygonal curves with rows of
% vertices (data points) and columns of dimensionality. The points along
% the curves are taken to be in the order as they appear in P and Q.
%
% Returned in cm is the discrete Frechet distance, aka the coupling
% measure, which is zero when P equals Q and grows positively as the curves
% become more dissimilar.
%
% The optional dfcn argument allows the user to specify a function with
% which to calculate distance between points in P and Q. If not provided,
% the L2 norm is used.
%
% The secondary output, cSq, is the coupling sequence, that is, the
% sequence of steps along each curve that must be followed to achieve the
% minimum coupling distance, cm. The output is returned in the form of a
% matrix with column 1 being the index of each point in P and column 2
% being the index of each point in Q. (NOTE: the coupling sequence is not
% unique in general)
%
% Explanation:
% The Frechet distance is a measure of similarity between to curves, P and
% Q. It is defined as the minimum cord-length sufficient to join a point
% traveling forward along P and one traveling forward along Q, although the
% rate of travel for either point may not necessarily be uniform.
%
% The Frechet distance, FD, is not in general computable for any given
% continuous P and Q. However, the discrete Frechet Distance, also called
% the coupling measure, cm, is a metric that acts on the endpoints of
% curves represented as polygonal chains. The magnitude of the coupling
% measure is bounded by FD plus the length of the longest segment in either
% P or Q, and approaches FD in the limit of sampling P and Q.
%
% This function implements the algorithm to calculate discrete Frechet
% distance outlined in:
% T. Eiter and H. Mannila. Computing discrete Frechet distance. Technical
% Report 94/64, Christian Doppler Laboratory, Vienna University of
% Technology, 1994.
%
%
%
% EXAMPLE:
% % create data
% t = 0:pi/8:2*pi;
% y = linspace(1,3,6);
% P = [(2:7)' y']+0.3.*randn(6,2);
% Q = [t' sin(t')]+2+0.3.*randn(length(t),2);
% [cm, cSq] = DiscreteFrechetDist(P,Q);
% % plot result
% figure
% plot(Q(:,1),Q(:,2),'o-r','linewidth',3,'markerfacecolor','r')
% hold on
% plot(P(:,1),P(:,2),'o-b','linewidth',3,'markerfacecolor','b')
% title(['Discrete Frechet Distance of curves P and Q: ' num2str(cm)])
% legend('Q','P','location','best')
% line([2 cm+2],[0.5 0.5],'color','m','linewidth',2)
% text(2,0.4,'dFD length')
% for i=1:length(cSq)
% line([P(cSq(i,1),1) Q(cSq(i,2),1)],...
% [P(cSq(i,1),2) Q(cSq(i,2),2)],...
% 'color',[0 0 0]+(i/length(cSq)/1.35));
% end
% axis equal
% % display the coupling sequence along with each distance between points
% disp([cSq sqrt(sum((P(cSq(:,1),:) - Q(cSq(:,2),:)).^2,2))])
%
%
%
% %%% ZCD June 2011 %%%
% %%% edits ZCD May 2013: 1) remove excess arguments to internal functions
% and persistence for speed, 2) added example, 3) allowed for user defined
% distance function, 4) added aditional output option for coupling sequence
%
% size of the data curves
sP = size(P);
sQ = size(Q);
% check validity of inputs
if sP(2)~=sQ(2)
error('Curves P and Q must be of the same dimension')
elseif sP(1)==0
cm = 0;
return;
end
% initialize CA to a matrix of -1s
CA = ones(sP(1),sQ(1)).*-1;
% distance function
if nargin==2
dfcn = @(u,v) sqrt(sum( (u-v).^2 ));
end
% final coupling measure value
cm = c(sP(1),sQ(1));
% obtain coupling measure via backtracking procedure
if nargout==2
cSq = zeros(sQ(1)+sP(1)+1,2); % coupling sequence
CApad = [ones(1,sQ(1)+1)*inf; [ones(sP(1),1)*inf CA]]; % pad CA
Pi=sP(1)+1; Qi=sQ(1)+1; count=1; % counting variables
while Pi~=2 || Qi~=2
% step down CA gradient
[v,ix] = min([CApad(Pi-1,Qi) CApad(Pi-1,Qi-1) CApad(Pi,Qi-1)]);
if ix==1
cSq(count,:) = [Pi-1 Qi];
Pi=Pi-1;
elseif ix==2
cSq(count,:) = [Pi-1 Qi-1];
Pi=Pi-1; Qi=Qi-1;
elseif ix==3
cSq(count,:) = [Pi Qi-1];
Qi=Qi-1;
end
count=count+1;
end
% format output: remove extra zeroes, reverse order, subtract off
% padding value, and add in the last point
cSq = [flipud(cSq(1:find(cSq(:,1)==0,1,'first')-1,:))-1; sP(1) sQ(1)];
end
% debug
% assignin('base','CAw',CA)
function CAij = c(i,j)
% coupling search function
if CA(i,j)>-1
% don't update CA in this case
CAij = CA(i,j);
elseif i==1 && j==1
CA(i,j) = dfcn(P(1,:),Q(1,:)); % update the CA permanent
CAij = CA(i,j); % set the current relevant value
elseif i>1 && j==1
CA(i,j) = max( c(i-1,1), dfcn(P(i,:),Q(1,:)) );
CAij = CA(i,j);
elseif i==1 && j>1
CA(i,j) = max( c(1,j-1), dfcn(P(1,:),Q(j,:)) );
CAij = 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)]),...
dfcn(P(i,:),Q(j,:)) );
CAij = CA(i,j);
else
CA(i,j) = inf;
end
end % end function, c
end % end main function
DiscreteFrechetDist的更多相关文章
随机推荐
- LeetCode Shortest Unsorted Continuous Subarray
原题链接在这里:https://leetcode.com/problems/shortest-unsorted-continuous-subarray/description/ 题目: Given a ...
- 基于JQ的简单左右轮播图
// 轮播图 主要实现思想: a.第一层div,设置overflow为hidden. b.里面是一个ul,每个li里面有个img或者为每个li设置背景图片也可以. c.li设置为左浮动,排成一行,还有 ...
- BZOJ2120:数颜色(分块版)
浅谈分块:https://www.cnblogs.com/AKMer/p/10369816.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?i ...
- bzoj 2142 礼物——扩展lucas模板
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2142 没给P的范围,但说 pi ^ ci<=1e5,一看就是扩展lucas. 学习材料 ...
- 编译cef 2526
fetch --nohooks chromium cd /path/to/chromium/src# git checkout -b 51.0.2704.103 refs/tags/51.0.2704 ...
- 记录启用HTTPS的全过程
因为 https 采用 ssl 加密,所以部署 https 时需要申请证书,证书的作用就是对浏览器和Web服务器双方的身份验证. 步骤1:申请证书 我们采用Let's Encrypt签发的免费证书,虽 ...
- 在U盘分区安装Kali并引导live CD 教程以及常见的注意事项
Kali Linux作为强大的全能渗透系统,把它制成Live CD基本算是必备技能了,但是官方提供的文档虽然简单,但是整个U盘都会被占用,确实是有点可惜,结合网上提供的一些思路加上自己的经验,向大家讲 ...
- mysql如何开启远程连接(默认未开启,即使密码正确,仍然无法访问)
mysql如何开启远程连接 | 浏览:1846 | 更新:2015-03-11 20:19 1 2 3 4 5 6 分步阅读 百度经验:jingyan.baidu.com 大家在公司工作中,经常会遇到 ...
- 【总结整理】js获取css的属性(内部,外部,内嵌(写在tag中))
在JS中需要获取某个元素的宽高或者是绝对定位的位置信息,通常我们会这么写: var elemWidth = elem.style.width; console.log(elemWidth); //(空 ...
- Codeforces 56D Changing a String (DP)
题意:你可以对字符串s进行3种操作: 1,在pos位置插入字符ch. 2,删除pos位置的字符. 3,替换pos位置的字符为ch. 问最少需要多少次操作可以把字符s变成字符s1? 思路: 设dp[i] ...