File: dtw.txt

package info (click to toggle)
mlpy 3.5.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,124 kB
  • sloc: ansic: 8,656; cpp: 7,331; python: 2,604; makefile: 156
file content (38 lines) | stat: -rw-r--r-- 1,036 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
.. currentmodule:: mlpy

Dynamic Time Warping (DTW)
==========================

Standard DTW
------------

.. autofunction:: dtw_std(x, y, dist_only=True)

Example

Reproducing the Fig. 2 example in [Salvador04]_.

>>> import mlpy
>>> import matplotlib.pyplot as plt
>>> import matplotlib.cm as cm
>>> x = [0,0,0,0,1,1,2,2,3,2,1,1,0,0,0,0]
>>> y = [0,0,1,1,2,2,3,3,3,3,2,2,1,1,0,0]
>>> dist, cost, path = mlpy.dtw_std(x, y, dist_only=False)
>>> dist
0.0
>>> fig = plt.figure(1)
>>> ax = fig.add_subplot(111)
>>> plot1 = plt.imshow(cost.T, origin='lower', cmap=cm.gray, interpolation='nearest')
>>> plot2 = plt.plot(path[0], path[1], 'w')
>>> xlim = ax.set_xlim((-0.5, cost.shape[0]-0.5))
>>> ylim = ax.set_ylim((-0.5, cost.shape[1]-0.5))
>>> plt.show()

.. image:: images/dtw.png

.. [Salvador04] S Salvador and P Chan. FastDTW: Toward Accurate Dynamic Time Warping in Linear Time and Space. 3rd Wkshp. on Mining Temporal and Sequential Data, ACM KDD '04, 2004.

Subsequence DTW
---------------

.. autofunction:: dtw_subsequence(x, y)