Skip to content

Instantly share code, notes, and snippets.

@instance01
Created July 19, 2020 08:21
Show Gist options
  • Save instance01/042733d8a6e6f2c4a01b6971eb3435c4 to your computer and use it in GitHub Desktop.
Save instance01/042733d8a6e6f2c4a01b6971eb3435c4 to your computer and use it in GitHub Desktop.
# Calculate uniform time warping (UTW) of two small time series.
# The arguably better alternative is dynamic time warping (DTW).
import numpy as np
X = np.array([3, 5, 9, 2, 3, 6, 3])
Y = np.array([3, 4, 6, 10, 1, 3, 2, 7, 4])
X_len = X.shape[0]
Y_len = Y.shape[0]
X = np.repeat(X, Y_len)
Y = np.repeat(Y, X_len)
utw = ((X - Y) ** 2).sum() / (X_len * Y_len)
print(utw) # ~3.60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment