Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
... [1., 2., 2.1, 3.2],
... gamma=0.01) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
0.089...
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.
"""
if gamma == 0.:
return dtw(ts1, ts2)
return SoftDTW(SquaredEuclidean(ts1[:ts_size(ts1)], ts2[:ts_size(ts2)]),
gamma=gamma).compute()
def _func(self, Z):
# Compute objective value and grad at Z.
Z = Z.reshape(self.barycenter_.shape)
G = numpy.zeros_like(Z)
obj = 0
for i in range(len(self._X_fit)):
D = SquaredEuclidean(Z, to_time_series(self._X_fit[i],
remove_nans=True))
sdtw = SoftDTW(D, gamma=self.gamma)
value = sdtw.compute()
E = sdtw.grad()
G_tmp = D.jacobian_product(E)
G += self.weights[i] * G_tmp
obj += self.weights[i] * value
return obj, G.ravel()
def _softdtw_func(Z, X, weights, barycenter, gamma):
# Compute objective value and grad at Z.
Z = Z.reshape(barycenter.shape)
G = numpy.zeros_like(Z)
obj = 0
for i in range(len(X)):
D = SquaredEuclidean(Z, X[i])
sdtw = SoftDTW(D, gamma=gamma)
value = sdtw.compute()
E = sdtw.grad()
G_tmp = D.jacobian_product(E)
G += weights[i] * G_tmp
obj += weights[i] * value
return obj, G.ravel()