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

Add partial matching #59

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

trueroad
Copy link

Add partial matching

This pull request adds partial matching DTW like #27 .
The difference between #27 and this is as follows.

  • This has both .py and .pyx implementations.
  • This allows a path's starting and ending points to be specified independently as full or partial matching.
  • This allows fine control of partial match precision by specifying different radius in the x-directions (long data) and y-directions (short data).

Examples

>>> import numpy as np
>>> import fastdtw
>>> x = np.array([1, 2, 3, 4, 5], dtype='float')
>>> y = np.array([2, 3, 4], dtype='float')
>>> fastdtw.fastdtw(x, y)
(2.0, [(0, 0), (1, 0), (2, 1), (3, 2), (4, 2)])
>>> fastdtw.fastdtw(x, y, b_partial_start=True)
(1.0, [(1, 0), (2, 1), (3, 2), (4, 2)])
>>> fastdtw.fastdtw(x, y, b_partial_end=True)
(1.0, [(0, 0), (1, 0), (2, 1), (3, 2)])
>>> fastdtw.fastdtw(x, y, b_partial_start=True, b_partial_end=True)
(0.0, [(1, 0), (2, 1), (3, 2)])

I created this pull request with reference to SPRING [1][2].

SPRING
is a streaming method for subsequence matching in data streams.
It differs from regular DTW in that it calculates partial matching.

In SPRING, the starting point for partial matching is obtained
by star-padding and STWM.
This commit adds b_partial_start flag, and if it is True,
__dtw() calculates the matching start point
by the star-padding-like and the STWM-like behavior.

In SPRING, the ending point for the partial matching is obtained
as the ending point of the optimal subsequence
as the data streaming progresses.
However, __dtw() does not handle data streams.
This commit adds b_partial_end flag, and if it is True,
__dtw() calculates the matching ending point as the point
with the lowest DTW distance.

[1]
Yasushi Sakurai, Christos Faloutsos, Masashi Yamamuro:
Stream Monitoring under the Time Warping Distance, ICDE2007,
https://doi.org/10.1109/ICDE.2007.368963

[2]
Yasushi Sakurai, Christos Faloutsos, Masashi Yamamuro:
Stream Processing under the Dynamic Time Warping Distance, DEWS2007,
https://www.ieice.org/iss/de/DEWS/DEWS2007/pdf/l6-5.pdf

trueroad added 12 commits March 19, 2023 13:11
SPRING [1][2]
is a streaming method for subsequence matching in data streams.
It differs from regular DTW in that it calculates partial matching.

In SPRING, the starting point for partial matching is obtained
by star-padding and STWM.
This commit adds `b_partial_start` flag, and if it is True,
`__dtw()` calculates the matching start point
by the star-padding-like and the STWM-like behavior.

In SPRING, the ending point for the partial matching is obtained
as the ending point of the optimal subsequence
as the data streaming progresses.
However, `__dtw()` does not handle data streams.
This commit adds `b_partial_end` flag, and if it is True,
`__dtw()` calculates the matching ending point as the point
with the lowest DTW distance.

[1]
Yasushi Sakurai, Christos Faloutsos, Masashi Yamamuro:
Stream Monitoring under the Time Warping Distance, ICDE2007,
https://doi.org/10.1109/ICDE.2007.368963

[2]
Yasushi Sakurai, Christos Faloutsos, Masashi Yamamuro:
Stream Processing under the Dynamic Time Warping Distance, DEWS2007,
https://www.ieice.org/iss/de/DEWS/DEWS2007/pdf/l6-5.pdf
Same functionality as previous commit added to pyx.
Negative indexes are excluded when generating `window` at a later step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant