Skip to main content

Python implementation of soft-DTW.

What is it?

The celebrated dynamic time warping (DTW) [1] defines the discrepancy between two time series, of possibly variable length, as their minimal alignment cost. Although the number of possible alignments is exponential in the length of the two time series, [1] showed that DTW can be computed in only quadractic time using dynamic programming.

Soft-DTW [2] proposes to replace this minimum by a soft minimum. Like the original DTW, soft-DTW can be computed in quadratic time using dynamic programming. However, the main advantage of soft-DTW stems from the fact that it is differentiable everywhere and that its gradient can also be computed in quadratic time. This enables to use soft-DTW for time series averaging or as a loss function, between a ground-truth time series and a time series predicted by a neural network, trained end-to-end using backpropagation.

Supported features

  • soft-DTW (forward pass) and gradient (backward pass) computations, implemented in Cython for speed

  • barycenters (time series averaging)

  • dataset loader for the UCR archive

  • Chainer function

Planned features

  • PyTorch function

Example

from sdtw import SoftDTW
from sdtw.distance import SquaredEuclidean

# Time series 1: numpy array, shape = [m, d] where m = length and d = dim
X = ...
# Time series 2: numpy array, shape = [n, d] where n = length and d = dim
Y = ...

# D can also be an arbitrary distance matrix: numpy array, shape [m, n]
D = SquaredEuclidean(X, Y)
sdtw = SoftDTW(D, gamma=1.0)
# soft-DTW discrepancy, approaches DTW as gamma -> 0
value = sdtw.compute()
# gradient w.r.t. D, shape = [m, n], which is also the expected alignment matrix
E = sdtw.grad()
# gradient w.r.t. X, shape = [m, d]
G = D.jacobian_product(E)

Installation

Binary packages are not available.

This project can be installed from its git repository. It is assumed that you have a working C compiler.

  1. Obtain the sources by:

    git clone https://github.com/mblondel/soft-dtw.git

or, if git is unavailable, download as a ZIP from GitHub.

  1. Install the dependencies:

    # via pip
    
    pip install numpy scipy scikit-learn cython nose
    
    
    # via conda
    
    conda install numpy scipy scikit-learn cython nose
  2. Build and install soft-dtw:

    cd soft-dtw
    python setup.py install

References

Author

  • Mathieu Blondel, 2017

Release files for soft-dtw 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for soft-dtw 0.1.6
File Size Uploaded
soft-dtw-0.1.6.tar.gz 58.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for soft-dtw 0.1.6
File Interpreter ABI Platform
soft_dtw-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.13+ x86-64 Details

Total release size: 87.4 kB

Release files / soft-dtw-0.1.6.tar.gz

Download URL soft-dtw-0.1.6.tar.gz
Size 58.1 kB
Tags Source
SHA-256 checksum
How to use checksums
60498ee2049a6a0b49276d26deca8abfa007a9ac9c51afbaecfb1fa403806da8
BLAKE2b-256 checksum
How to use checksums
eca899a1c684116c73dee995ed690a1ed9217ae0eb9514c0b06fdd386c7c21da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / soft_dtw-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl

Download URL soft_dtw-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl
Size 29.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
75092414fbdc31fe4c82e560aee4b4c5bd4993275e7934dea5dd24a461473f12
BLAKE2b-256 checksum
How to use checksums
26e998305d8a5b37d4e0754cbdc42c9678582ca21d0838dc5efaa1c07cce82a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page