Created
November 29, 2014 21:22
-
-
Save timsgardner/6b7e3fbf5e2a413f88e1 to your computer and use it in GitHub Desktop.
dtw mathematica
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dtwMatrix2[s_List, t_List] := | |
With[{n = Length@s, m = Length@t}, | |
Fold[ | |
{acc, pos} \[Function] pos /. {i_, j_} :> | |
ReplacePart[acc, | |
pos -> (s[[i - 1]] - t[[j - 1]])^2 + | |
Min[Part[acc, ##] & @@@ {{i - 1, j}, {i, j - 1}, {i - 1, | |
j - 1}}]], | |
SparseArray[{{1, 1} -> | |
0, {1, _} -> \[Infinity], {_, 1} -> \[Infinity]}, {n, m} + 1], | |
Tuples[{Range[n], Range[m]} + 1]]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment