pollen-robotics / dtw

DTW (Dynamic Time Warping) python module
GNU General Public License v3.0
1.16k stars 233 forks source link

Why is there a '-1' in min(i+k,r-1) and min(j+k, c-1) in third for loop of dtw function? #27

Closed DihengChen closed 6 years ago

DihengChen commented 6 years ago

image

mxsrc commented 6 years ago

Since r and c correspond to the input's lengths, this will prevent indexing out of the array's bounds.

DihengChen commented 6 years ago

Thanks you for your reply! But I am still confused. The i_k and j_k are used as index of matrix D0, and D0 is (c+1)*(r+1) matrix. So r and c will not be out of D0's bound.

mxsrc commented 6 years ago

While r and c won't be out of bounds, i + k and j + k might. In the last loop iteration, i will be r-1. When a warp different from 1, e.g., 2, is given, i + k will be r - 1 + 2 and thus out of bounds for D0. The same applies for j of course.

jlc-christie commented 6 years ago

@pierre-rouanet resolved, close?