该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
这是下载的用MATLAB实现的DTW算法,问题是怎么用这个算法简单测试一下,例如两个序列(3,5,6,7,7,1)(3,6,6,7,8,1,1)用这个算法计算这两个序列的相似性?哪个大神帮帮忙,本人菜鸟一枚
function [Dist,D,k,w,rw,tw]=dtw(r,t)
%
% [Dist,D,k,w,rw,tw]=dtw(r,t,pflag)
%
% Dynamic Time Warping Algorithm 动态时间规整算法
% Dist is unnormalized distance between t and r Dist是t和r之间的非标准化距离
% D is the accumulated distance matrix D是累积的距离矩阵
% k is the normalizing factor k是正态因子
% w is the optimal path w是最佳路径
% t is the vector you are testing against t是你要测试的矢量
% r is the vector you are testing r是你正在测试的矢量
% rw is the warped r vector rw是扭曲的r矢量
% tw is the warped t vector tw是扭曲的t矢量
% pflag plot flag: 1 (yes), 0(no) pflag图标记:1(yes),0(no)
%
% Version comments: 文本的评论:
% rw, tw and pflag added by Pau Mic
[row,M]=size(r); if (row > M) M=row; r=r'; end;
[row,N]=size(t); if (row > N) N=row; t=t'; end;
d=sqrt((repmat(r',1,N)-repmat(t,M,1)).^2); %this makes clear the above instruction Thanks Pau Mic
D=zeros(size(d));
D(1,1)=d(1,1);
for m=2:M
D(m,1)=d(m,1)+D(m-1,1);
end
for n=2:N
D(1,n)=d(1,n)+D(1,n-1);
end
for m=2:M
for n=2:N
D(m,n)=d(m,n)+min(D(m-1,n),min(D(m-1,n-1),D(m,n-1))); % this double MIn construction improves in 10-fold the Speed-up. Thanks Sven Mensing
end
end
Dist=D(M,N);
n=N;
m=M;
k=1;
w=[M N];
while ((n+m)~=2)
if (n-1)==0
m=m-1;
elseif (m-1)==0
n=n-1;
else
[values,number]=min([D(m-1,n),D(m,n-1),D(m-1,n-1)]);
switch number
case 1
m=m-1;
case 2
n=n-1;
case 3
m=m-1;
n=n-1;
end
end
k=k+1;
w=[m n; w]; % this replace the above sentence. Thanks Pau Mic
end
% warped waves
rw=r(w(:,1));
tw=t(w(:,2));
end