Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pollen-robotics/dtw
DTW (Dynamic Time Warping) python module
https://github.com/pollen-robotics/dtw
distance distance-measures distance-metric dtw python
Last synced: 29 days ago
JSON representation
DTW (Dynamic Time Warping) python module
- Host: GitHub
- URL: https://github.com/pollen-robotics/dtw
- Owner: pollen-robotics
- License: gpl-3.0
- Created: 2014-07-28T10:01:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-29T11:30:12.000Z (8 months ago)
- Last Synced: 2024-10-02T00:01:28.428Z (about 1 month ago)
- Topics: distance, distance-measures, distance-metric, dtw, python
- Language: Python
- Size: 191 KB
- Stars: 1,156
- Watchers: 31
- Forks: 233
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [Dynamic Time Warping](https://en.wikipedia.org/wiki/Dynamic_time_warping) Python Module
[![Build Status](https://travis-ci.org/pierre-rouanet/dtw.svg?branch=master)](https://travis-ci.org/pierre-rouanet/dtw)
Dynamic time warping is used as a similarity measured between temporal sequences. This package provides two implementations:
* the basic version (see [here](https://en.wikipedia.org/wiki/Dynamic_time_warping)) for the algorithm
* an accelerated version which relies on scipy cdist (see https://github.com/pierre-rouanet/dtw/pull/8 for detail)```python
import numpy as np
# We define two sequences x, y as numpy array
# where y is actually a sub-sequence from x
x = np.array([2, 0, 1, 1, 2, 4, 2, 1, 2, 0]).reshape(-1, 1)
y = np.array([1, 1, 2, 4, 2, 1, 2, 0]).reshape(-1, 1)from dtw import dtw
manhattan_distance = lambda x, y: np.abs(x - y)
d, cost_matrix, acc_cost_matrix, path = dtw(x, y, dist=manhattan_distance)
print(d)
>>> 2.0 # Only the cost for the insertions is kept# You can also visualise the accumulated cost and the shortest path
import matplotlib.pyplot as pltplt.imshow(acc_cost_matrix.T, origin='lower', cmap='gray', interpolation='nearest')
plt.plot(path[0], path[1], 'w')
plt.show()```
Result of the accumulated cost matrix and the shortest path (in white) found:
![Acc cost matrix and shortest path](./acc.png)## Other examples are available as notebook
* [the code above as a notebook](./examples/simple%20example.ipynb)
* [a sound comparison based on DTW + MFCC](./examples/MFCC%20%2B%20DTW.ipynb)
* [simple speech recognition](./examples/speech-recognition.ipynb)## Installation
```
python -m pip install dtw
```It is tested on Python 2.7, 3.4, 3.5 and 3.6. It requires numpy and scipy.