question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

librosa.dtw with subseq=True is not symmetric w.r.t. its inputs

See original GitHub issue

cc @stefan-balke

My expectation for subsequence matching is that implies that either X can be matched to a subsequence of Y or Y can be matched to a subsequence of X. librosa.dtw doesn’t exhibit this behavior:

In [1]: import librosa
In [2]: import numpy as np
In [3]: X = np.array([10., 10., 0., 1., 2., 3., 10., 10.]).reshape([1, -1])
In [4]: Y = np.arange(4).astype(float).reshape([1, -1])
In [5]: librosa.dtw(X, Y, subseq=True)
Out[5]:
(array([[ 10.,   9.,   8.,   7.],
        [ 20.,  18.,  16.,  14.],
        [ 20.,  19.,  18.,  17.],
        [ 21.,  19.,  19.,  19.],
        [ 23.,  20.,  19.,  20.],
        [ 26.,  22.,  20.,  19.],
        [ 36.,  31.,  28.,  26.],
        [ 46.,  40.,  36.,  33.]]), array([[7, 3],
        [6, 3],
        [5, 3],
        [4, 2],
        [3, 1],
        [2, 1],
        [1, 1],
        [0, 1]]))
In [6]: librosa.dtw(Y, X, subseq=True)
Out[6]:
(array([[ 10.,  10.,   0.,   1.,   2.,   3.,  10.,  10.],
        [ 19.,  19.,   1.,   0.,   1.,   3.,  12.,  19.],
        [ 27.,  27.,   3.,   1.,   0.,   1.,   9.,  17.],
        [ 34.,  34.,   6.,   3.,   1.,   0.,   7.,  14.]]), array([[3, 5],
        [2, 4],
        [1, 3],
        [0, 2]]))

This is in contrast to djitw’s behavior (my expected behavior, obviously 😉

In [7]: import djitw

In [8]: import scipy

In [9]: djitw.dtw(scipy.spatial.distance.cdist(X.T, Y.T))
Out[9]: (array([2, 3, 4, 5]), array([0, 1, 2, 3]), 0.0)

In [10]: djitw.dtw(scipy.spatial.distance.cdist(Y.T, X.T))
Out[10]: (array([0, 1, 2, 3]), array([2, 3, 4, 5]), 0.0)

What is the motivation for making it non-symmetric? We should at least document it more specifically, saying that subseq=True allows for a subsequence of Y to be matched to the entirety of X but not vice-versa.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
craffelcommented, May 31, 2017

I’m gonna make a PR! Maybe you can CR then?

Great. I’ll give it the ol’ CR CR.

1reaction
stefan-balkecommented, Sep 1, 2017

Yes. Sorry. Trying to squeeze it in next week.

Am 01.09.2017 um 19:45 schrieb Brian McFee <notifications@github.commailto:notifications@github.com>:

@stefan-balkehttps://github.com/stefan-balke you still planning on this one? (Trying to triage issues for the 0.6 milestone.)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/librosa/librosa/issues/581#issuecomment-326642697, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AG_MDHucC9tkZYmKBx2Tmq2cnawrF9HQks5seEK5gaJpZM4NipDJ.

Read more comments on GitHub >

github_iconTop Results From Across the Web

librosa.sequence.dtw — librosa 0.10.0.dev0 documentation
This function performs a DTW and path backtracking on two sequences. We follow the nomenclature and algorithmic approach as described in 1.
Read more >
Changelog — librosa 0.10.0.dev0 documentation
It is not longer necessary to explicitly import librosa.display. Brian McFee ... #621 dtw is now symmetric with respect to input arguments. Stefan...
Read more >
librosa.sequence.dtw — librosa 0.9.0 documentation
This function performs a DTW and path backtracking on two sequences. We follow the nomenclature and algorithmic approach as described in 1. 1....
Read more >
Music Synchronization with Dynamic Time Warping - Librosa
7 seconds and the second recording for ca. 5 seconds. Our objective is now to find an alignment between these two recordings by...
Read more >
Source code for librosa.sequence
n" "Please provide your input in the form X.shape=(K, N) " "and Y.shape=(K, ... Stop criteria: # Setting it to (0, 0) does...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found