slaypni / fastdtw

A Python implementation of FastDTW
MIT License
774 stars 122 forks source link

Using with x/y sizes of (n, m) where m >1 #44

Open danomics-cam opened 4 years ago

danomics-cam commented 4 years ago

I appreciate your package - it has made my life much easier. However, I have a question that I was hoping you could resolve: In the case of: X being an array of size (n,1), and Y being an array of size (m,1), where m/n are number of samples,

What if I had arrays of: X being size (n,2), and Y being size (n,2).

Example of use case being if I have two related time series measurements such as machine vibration frequency and machine operating temperature. Both are distinct measurements, and when doing a manual correlation you can better match events when using both indicators in tandem than just one.

The code certainly runs in both scenarios, and outputs unique paths when I run just component 1 vs. just component 2 vs. both 1 and 2 at same time.

However, with existing documentation it's hard to understand the workings of what is going on.

slaypni commented 4 years ago

The function passed as dist parameter is used to calculate distances between each sample of X and Y. Therefore, as long as the dist function can compute distances between two samples, it is not a problem that each sample has multiple dimensions.

udithhaputhanthri commented 3 years ago

@slaypni Hi, thanks for the great package.

I have a couple of points to clarify. In the original paper, DTW is measured between just 2 two-time series. But in the example given in the documentation, (5,2) and (3,2) shape data (x,y) are used to get the DTW distance.

  1. What are those dimensions in the data
  2. First I thought that the 1st dimension is the number of samples/ data points and the 2nd dimension is the sequence length. But then the DTW measurement does not make sense to me. Because the number of samples in x and y are different.

Can you please explain how can we use the metric. I could not find the documentation for this in the repository.

(original paper mentioned in the repo: https://www.semanticscholar.org/paper/FastDTW%3A-Toward-Accurate-Dynamic-Time-Warping-in-Salvador-Chan/05a20cde15e172fc82f32774dd0cf4fe5827cad2)

Thanks.

slaypni commented 3 years ago

Please take a look at the test code. There are 1d and 2d examples. https://github.com/slaypni/fastdtw/blob/master/tests/test_fastdtw.py