Skip to content

Commit

Permalink
tidied it up
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephBond committed Sep 29, 2023
1 parent 5eff262 commit 30699e2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions example/Util/DTW.purs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ distanceDTWWindow seq1 seq2 window cost = result × (extractPath priorcells (n
worker :: Matrix NumInf × Matrix (Int × Int) -> (Int × Int) -> Matrix NumInf × Matrix (Int × Int)
worker (dists × inds) (i' × j') =
let
im1j = dists ! i'-1 ! j'
ijm1 = dists ! i' ! j'-1
im1jm1 = dists ! i'-1 ! j'-1
im1j = dists ! i' - 1 ! j'
ijm1 = dists ! i' ! j' - 1
im1jm1 = dists ! i' - 1 ! j' - 1
minim × prev = costAndPrevD (i' × j') im1j ijm1 im1jm1
costij = cost (seq1 ! i' - 1) (seq2 ! j' - 1) `plus` minim
in
Expand All @@ -64,6 +64,7 @@ costAndPrevD (i × j) im1j ijm1 im1jm1 =
else if minimal == ijm1 then
ijm1 × i × (j - 1)
else -- minimal == im1jm1

im1jm1 × (i - 1) × (j - 1)

extractPath :: Matrix (Int × Int) -> (Int × Int) -> List (Int × Int)
Expand All @@ -75,7 +76,7 @@ extractPath matrix (n × m) = traverser n m matrix Nil
traverser x y mat accum = traverser nextX nextY mat newPath
where
newPath = Cons (x × y) accum
(nextX × nextY) = mat ! x ! y
(nextX × nextY) = mat ! x ! y

distEuclid :: Number -> Number -> NumInf
distEuclid x y = FNum ((x - y) * (x - y))
Expand Down

0 comments on commit 30699e2

Please sign in to comment.