Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DynamicTimeWarpingWin.hs
dtwWin :: V.Vector a -> V.Vector a -> (a -> a -> Int) -> Int -> Array (Int,Int) Int
dtwWin x y cost window = runSTArray $ do
let n = V.length x
m = V.length y
maxCost = maxBound
w = max window (abs (n - m)) -- constrain window size
d <- newArray ((0,0),(m,n)) maxCost
writeArray d (0,0) 0
forM_ [1..n] $ \i ->
forM_ [max 1 (i-w) .. min m (i+w)] $ \j -> do
let c = cost (x ! (i - 1)) (y ! (j - 1))
insertion <- readArray d (j,i-1)
deletion <- readArray d (j-1,i)
match <- readArray d (j-1,i-1)
writeArray d (j,i) (c + minimum [insertion,deletion,match])
return d
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.