Skip to content

Instantly share code, notes, and snippets.

@nbenn
Created August 22, 2019 06:33
Show Gist options
  • Save nbenn/c05e394d6384aac4cbc82a86d6608742 to your computer and use it in GitHub Desktop.
Save nbenn/c05e394d6384aac4cbc82a86d6608742 to your computer and use it in GitHub Desktop.
Comparison of python tslearn and R dtw implementations
library(reticulate)
library(dtw)
use_condaenv("dtw")
tslearn <- import("tslearn")
tslearn$metrics$dtw(rep(0, 3), 1:4)
dtw(rep(0, 3), 1:4, keep.internals = T, step.pattern = symmetric1)[
c("distance", "costMatrix")
]
dtw(dist(rep(0, 3), 1:4), keep.internals = T, step.pattern = symmetric1)[
c("distance", "costMatrix")
]
dtw(dist(rep(0, 3), 1:4) ^ 2, keep.internals = T, step.pattern = symmetric1)[
c("distance", "costMatrix")
]
sqrt(30)
idx <- seq(0, 6.28, len = 100);
x <- sin(idx) + runif(100) / 10;
y <- cos(idx)
tslearn$metrics$dtw(x, y)
sqrt(dtw(dist(x, y) ^ 2, step.pattern = symmetric1)[["distance"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment