GithubHelp home page GithubHelp logo

siseulemen / dtw Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pollen-robotics/dtw

0.0 0.0 0.0 192 KB

DTW (Dynamic Time Warping) python module

License: GNU General Public License v3.0

Python 100.00%

dtw's Introduction

Dynamic Time Warping Python Module

Build Status

Dynamic time warping is used as a similarity measured between temporal sequences. This package provides two implementations:

  • the basic version (see here) for the algorithm
  • an accelerated version which relies on scipy cdist (see pollen-robotics#8 for detail)
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 plt

plt.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

Other examples are available as notebook

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.

dtw's People

Contributors

pierre-rouanet avatar mynameisvinn avatar capkuro avatar jlc-christie avatar nightscape avatar mutex86 avatar encukou avatar rob-med avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.