# tslearn.metrics.cdist_soft_dtw¶

tslearn.metrics.cdist_soft_dtw(dataset1, dataset2=None, gamma=1.0)[source]

Compute cross-similarity matrix using Soft-DTW metric.

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: dataset1 A dataset of time series dataset2 Another dataset of time series gamma : float (default 1.) Gamma paraneter for Soft-DTW numpy.ndarray Cross-similarity matrix

soft_dtw
Compute Soft-DTW
cdist_soft_dtw_normalized
Cross similarity matrix between time series datasets using a normalized version of Soft-DTW

References

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

Examples

>>> cdist_soft_dtw([[1, 2, 2, 3], [1., 2., 3., 4.]], gamma=.01)
array([[-0.01098612,  1.        ],
[ 1.        ,  0.        ]])
>>> cdist_soft_dtw([[1, 2, 2, 3], [1., 2., 3., 4.]],
...                [[1, 2, 2, 3], [1., 2., 3., 4.]], gamma=.01)
array([[-0.01098612,  1.        ],
[ 1.        ,  0.        ]])