MATLAB使用pdist处理时间序列Clustering
MATLAB using pdist to deal with Time series Clustering
我在使用 MATLAB 进行时间序列数据聚类方面遇到问题
我正在尝试使用下面的 DTW 库作为我的距离测量方法
http://www.mathworks.com/matlabcentral/fileexchange/16350-continuous-dynamic-time-warping
TimeData = csvread('testData10.csv',1,0)
Y = pdist(TimeData,@dtw_dist)
Z = linkage(Y,'complete')
dendrogram(Z)
我做了一个函数来适应'pdist'距离函数
的格式
function d2 = dtw_dist(XI,XJ)
[dist,D,k,w,rw,tw] = dtw2(XI,XJ,0)
d2 = dist
end
但我收到错误消息
Error using pdist (line 373)
Error evaluating distance function 'dtw_dist'.
Caused by:
Error using -
Matrix dimensions must agree.
如果有人帮助我,我会很开心
谢谢!
---2015.1.5更新---
我改变了我的功能来调用 dtw 以适应格式
并且有效
function d2 = dtw_dist(XI,XJ)
result =[];
[m1,n1] = size(XI);
[m2,n2] = size(XJ);
for j=1:m2
result = horzcat(result,dtw(XI,XJ(j,:)));
end
d2=result;
end
如果不知道 dtw2
是什么,就很难分辨。但这里有一个可能的原因:当您使用自定义距离函数调用 pdist2
时,它应该满足以下条件:
A distance function must be of the form
function D2 = DISTFUN(ZI,ZJ)
taking as arguments a 1-by-N vector ZI containing a single observation from X or Y, an M2-by-N matrix ZJ containing multiple observations from X or Y, and returning an M2-by-1 vector of distances D2, whose Jth element is the distance between the observations ZI and ZJ(J,:).
检查 dtw2
是否满足,如果不满足,相应地修改它(或使用循环而不是 pdist2
)。
我在使用 MATLAB 进行时间序列数据聚类方面遇到问题
我正在尝试使用下面的 DTW 库作为我的距离测量方法 http://www.mathworks.com/matlabcentral/fileexchange/16350-continuous-dynamic-time-warping
TimeData = csvread('testData10.csv',1,0)
Y = pdist(TimeData,@dtw_dist)
Z = linkage(Y,'complete')
dendrogram(Z)
我做了一个函数来适应'pdist'距离函数
的格式function d2 = dtw_dist(XI,XJ)
[dist,D,k,w,rw,tw] = dtw2(XI,XJ,0)
d2 = dist
end
但我收到错误消息
Error using pdist (line 373)
Error evaluating distance function 'dtw_dist'.
Caused by:
Error using -
Matrix dimensions must agree.
如果有人帮助我,我会很开心
谢谢!
---2015.1.5更新---
我改变了我的功能来调用 dtw 以适应格式 并且有效
function d2 = dtw_dist(XI,XJ)
result =[];
[m1,n1] = size(XI);
[m2,n2] = size(XJ);
for j=1:m2
result = horzcat(result,dtw(XI,XJ(j,:)));
end
d2=result;
end
如果不知道 dtw2
是什么,就很难分辨。但这里有一个可能的原因:当您使用自定义距离函数调用 pdist2
时,它应该满足以下条件:
A distance function must be of the form
function D2 = DISTFUN(ZI,ZJ)
taking as arguments a 1-by-N vector ZI containing a single observation from X or Y, an M2-by-N matrix ZJ containing multiple observations from X or Y, and returning an M2-by-1 vector of distances D2, whose Jth element is the distance between the observations ZI and ZJ(J,:).
检查 dtw2
是否满足,如果不满足,相应地修改它(或使用循环而不是 pdist2
)。