Giter Club home page Giter Club logo

pytorch-softdtw's Introduction

pytorch-softdtw

An implementation of SoftDTW [1] for PyTorch. Should run pretty fast.

More goodies: check out pytorch-softdtw-cuda by Maghoumi, a heavily upgraded version that runs parallel on CUDA.

Install

Just paste this file around. I don't believe in Python's package managers. Setting up the environment took me longer than actually writing this thing.

Depends on PyTorch and Numba.

How to use

SoftDTW autograd function computes the smoothed DTW distance (scalar) for a given distance matrix and calling backward on the result gives you the derivative (matrix) of the DTW distance (scalar) with respect to the distance matrix.

As the original authors pointed out [1], the derivative is the same as the expected DTW path. This is comparable to forward-backward algorithm for HMM.

You may also specify the temperature gamma (positive number). As gamma goes to zero, the result converges to that of the original "hard" DTW.

from soft_dtw import SoftDTW
...
criterion = SoftDTW(gamma=1.0, normalize=True) # just like nn.MSELoss()
...
loss = criterion(out, target)

Does it support pruning?

No. You can mess with the loop (line 13 and line 35) yourself.

License

Look, I just took their paper and wrote a single-file Python thingy. If you want to say thanks, which is of course welcome, then buy me a drink. Not a big fan of beer though. Umeshu in soda will be nice. Yeah sweety sweety.

Reference

[1] M. Cuturi and M. Blondel. "Soft-DTW: a Differentiable Loss Function for Time-Series". In Proceedings of ICML 2017.

pytorch-softdtw's People

Contributors

maghoumi avatar sleepwalking avatar ywatanabe1989 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.