Skip to content

Instantly share code, notes, and snippets.

@nbenn

nbenn/dtw-py-vs-r.R

Created Aug 22, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.