How to get pairwise distance matrices from dynamic time warping dtw on a matrix of time series ?

13 次查看(过去 30 天)
I have a matrix (1018 x 3744) where each column is a timeseries. The timestamps, which are the same for each row, are in a separete vector. Some of the time series contain NaN values at a variety of time points (rows).
1) If there are no NaNs, How can I generate pairwise distance matrices for all of the time series using the dynamic time warping function? I know how to do it for a single pair of time series vectors but not for all of the pairwise combinations in this matrix.
2) How can I do this if there are NaNs?
A subsample of the matrix (the first 10 columns is attached).
Thanks!

回答(1 个)

Greg Dionne
Greg Dionne 2019-5-2
Your signals look extremely well time-aligned (within a sample).
Since you have NaN, I suppose you could just perform a weighted comparison over the points you currently have. Maybe something like:
function D = mdist(X)
n = size(X,2);
D = zeros(n);
for i=1:n
for j=i+1:n
idx = isfinite(X(:,i))&isfinite(X(:,j));
D(i,j) = rms(X(idx,i)-X(idx,j));
end
end
D = D+D';
>> mdist(subset)
ans =
0 0.0002 0.0005 0.0009 0.0015 0.0022 0.0030 0.0039 0.0049 0.0059
0.0002 0 0.0003 0.0008 0.0013 0.0021 0.0029 0.0038 0.0047 0.0058
0.0005 0.0003 0 0.0005 0.0010 0.0018 0.0026 0.0035 0.0044 0.0055
0.0009 0.0008 0.0005 0 0.0006 0.0013 0.0021 0.0030 0.0040 0.0051
0.0015 0.0013 0.0010 0.0006 0 0.0007 0.0015 0.0024 0.0034 0.0045
0.0022 0.0021 0.0018 0.0013 0.0007 0 0.0008 0.0017 0.0027 0.0038
0.0030 0.0029 0.0026 0.0021 0.0015 0.0008 0 0.0009 0.0019 0.0030
0.0039 0.0038 0.0035 0.0030 0.0024 0.0017 0.0009 0 0.0010 0.0021
0.0049 0.0047 0.0044 0.0040 0.0034 0.0027 0.0019 0.0010 0 0.0011
0.0059 0.0058 0.0055 0.0051 0.0045 0.0038 0.0030 0.0021 0.0011 0
  1 个评论
Joel Singley
Joel Singley 2019-5-6
Thanks, I'll give this a try. There are quite a few time periods were the time series (especially those not in the sample) diverge from each other, so they are not always so well aligned.

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by