tslearn.metrics.soft_dtw

tslearn.metrics.soft_dtw(ts1, ts2, gamma=1.0)[source]

Compute Soft-DTW metric between two time series.

Soft-DTW was originally presented in [1] and is discussed in more details in our user-guide page on DTW and its variants.

Soft-DTW is computed as:

\[\text{soft-DTW}_{\gamma}(X, Y) = \min_{\pi}{}^\gamma \sum_{(i, j) \in \pi} \|X_i, Y_j\|^2\]

where \(\min^\gamma\) is the soft-min operator of parameter \(\gamma\).

In the limit case \(\gamma = 0\), \(\min^\gamma\) reduces to a hard-min operator and soft-DTW is defined as the square of the DTW similarity measure.

Parameters:
ts1

A time series

ts2

Another time series

gamma : float (default 1.)

Gamma paraneter for Soft-DTW

Returns:
float

Similarity

See also

cdist_soft_dtw
Cross similarity matrix between time series datasets

References

[1]M. Cuturi, M. Blondel “Soft-DTW: a Differentiable Loss Function for Time-Series,” ICML 2017.

Examples

>>> soft_dtw([1, 2, 2, 3],
...          [1., 2., 3., 4.],
...          gamma=1.)  # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
-0.89...
>>> soft_dtw([1, 2, 3, 3],
...          [1., 2., 2.1, 3.2],
...          gamma=0.01)  # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
0.089...