Skip to main content

Torch implementation of Soft-DTW, supports CUDA devices.

Project description

pysdtw

Torch implementation of the Soft-DTW algorithm, supports both cpu and CUDA hardware.

Note: This repository started as a fork from this project.

Installation

This package is available on pypi and depends on pytorch and numba.

Install with:

pip install pysdtw

Usage

import pysdtw

# the input data includes a batch dimension
X = torch.rand((10, 5, 7), requires_grad=True)
Y = torch.rand((10, 9, 7))

# optionally choose a pairwise distance function
fun = pysdtw.distance.pairwise_l2_squared

# create the SoftDTW distance function
sdtw = pysdtw.SoftDTW(gamma=1.0, dist_func=fun, use_cuda=False)

# soft-DTW discrepancy, approaches DTW as gamma -> 0
res = sdtw(X, Y)

# define a loss, which gradient can be backpropagated
loss = res.sum()
loss.backward()

# X.grad now contains the gradient with respect to the loss

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysdtw-0.0.5.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

pysdtw-0.0.5-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page