Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug in lb_keogh C implementation that caused it to produce incorrect results #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dtaidistance/lib/DTAIDistanceC/DTAIDistanceC/dd_dtw.c
Original file line number Diff line number Diff line change
Expand Up @@ -4090,7 +4090,7 @@ seq_t lb_keogh(seq_t *s1, idx_t l1, seq_t *s2, idx_t l2, DTWSettings *settings)
if (imax > l2) {
imax = l2;
}
ui = 0;
ui = -INFINITY;
for (idx_t j=imin; j<imax; j++) {
if (s2[j] > ui) {
ui = s2[j];
Expand Down Expand Up @@ -4145,7 +4145,7 @@ seq_t lb_keogh_euclidean(seq_t *s1, idx_t l1, seq_t *s2, idx_t l2, DTWSettings *
if (imax > l2) {
imax = l2;
}
ui = 0;
ui = -INFINITY;
for (idx_t j=imin; j<imax; j++) {
if (s2[j] > ui) {
ui = s2[j];
Expand Down
10 changes: 10 additions & 0 deletions tests/test_subsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,16 @@ def test_lb1(use_c):
lb = lb_keogh(a, b, window=2, use_c=use_c)
assert lb == pytest.approx(2.23606797749979)

@numpyonly
@pytest.mark.parametrize("use_c", [False, True])
def test_lb2(use_c):
with util_numpy.test_uses_numpy() as np:
a = np.array([-1., -2, -1, -3])
b = np.array([-3., -4, -3, 0])
lb = lb_keogh(a, b, window=2, use_c=use_c)
assert lb == pytest.approx(2.23606797749979)



if __name__ == "__main__":
directory = Path(os.environ.get('TESTDIR', Path(__file__).parent))
Expand Down