Created
July 21, 2014 07:24
-
-
Save fffej/e2b737d341ef102b5a94 to your computer and use it in GitHub Desktop.
DynamicTimeWarpingWin.hs
This file contains 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
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