tslearn.metrics.soft_dtw_alignment¶

tslearn.metrics.
soft_dtw_alignment
(ts1, ts2, gamma=1.0)[source]¶ Compute SoftDTW metric between two time series and return both the similarity measure and the alignment matrix.
SoftDTW was originally presented in [1] and is discussed in more details in our userguide page on DTW and its variants.
SoftDTW is computed as:
\[\text{softDTW}_{\gamma}(X, Y) = \min_{\pi}{}^\gamma \sum_{(i, j) \in \pi} \X_i, Y_j\^2\]where \(\min^\gamma\) is the softmin operator of parameter \(\gamma\).
In the limit case \(\gamma = 0\), \(\min^\gamma\) reduces to a hardmin operator and softDTW 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 SoftDTW
Returns:  numpy.ndarray
Softalignment matrix
 float
Similarity
See also
soft_dtw
 Returns softDTW score alone
References
[1] M. Cuturi, M. Blondel “SoftDTW: a Differentiable Loss Function for TimeSeries,” ICML 2017. Examples
>>> a, dist = soft_dtw_alignment([1, 2, 2, 3], ... [1., 2., 3., 4.], ... gamma=1.) # doctest: +ELLIPSIS >>> dist 0.89... >>> a # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE array([[1.00...e+00, 1.88...e01, 2.83...e04, 4.19...e11], [3.40...e01, 8.17...e01, 8.87...e02, 3.94...e05], [5.05...e02, 7.09...e01, 5.30...e01, 6.98...e03], [1.37...e04, 1.31...e01, 7.30...e01, 1.00...e+00]])