-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #800 from explorable-viz/example-fluid
Fluid example merged
- Loading branch information
Showing
17 changed files
with
104 additions
and
65 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let d x y = (x - y) * (x - y); | ||
let seq1 = [3,1,2,2,1]; | ||
seq2 = [2,0,0,3,3,1,0]; | ||
window = 2 | ||
in computeDTW seq1 seq2 d window |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
let nextIndices n m window = | ||
[(i, j) | i <- [1 .. n], | ||
j <- [(max 1 (i - window)) .. (min m (i + window))]]; | ||
|
||
let costMatrixInit rows cols window = | ||
[| let initV = if or (and (n == 1) (m == 1)) (and (abs n m <= window) (not (or (n == 1) (m == 1)))) | ||
then FNum 0 | ||
else Infty | ||
in initV | (n, m) in (rows, cols) |]; | ||
|
||
let minAndPrev (i, j) im1 jm1 ijm1 = | ||
let minim = minimal [im1, jm1, ijm1] in | ||
if eq minim im1 then | ||
((i, j + 1), minim) | ||
else | ||
if eq minim jm1 then | ||
((i + 1, j ), minim) | ||
else ((i, j), minim); | ||
let extractPath indmatrix (i, j) = | ||
let traverser (n,m) matrix accum = | ||
if and (n == 1) (m == 1) | ||
then accum | ||
else | ||
traverser (matrix!(n,m)) matrix ((n - 1,m - 1) : accum) | ||
in traverser (i,j) indmatrix Nil; | ||
let localMinUpdate seq1 seq2 cost (costmatrix, indmatrix) (i, j) = | ||
let iEntr = nth (i - 1) seq1; | ||
jEntr = nth (j - 1) seq2; | ||
dist = cost iEntr jEntr; | ||
im1 = costmatrix!(i , j + 1); | ||
jm1 = costmatrix!(i + 1, j); | ||
im1jm1 = costmatrix!(i , j); | ||
(prev, minim) = minAndPrev (i, j) im1 jm1 im1jm1; | ||
newVal = add (FNum dist) minim | ||
in (matrixUpdate costmatrix (i + 1,j + 1) newVal, matrixUpdate indmatrix (i + 1,j + 1) prev); | ||
|
||
let computeDTW seq1 seq2 cost window = | ||
let n = length seq1; | ||
m = length seq2; | ||
initD = costMatrixInit (n + 1) (m + 1) window; | ||
initI = [| 0 | (i,j) in (n + 1, m + 1)|]; | ||
indexing = nextIndices n m window; | ||
(finished, indices) = foldl (localMinUpdate seq1 seq2 cost) (initD, initI) indexing | ||
in | ||
(finished, extractPath indices (n + 1,m + 1)); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
let comp Infty Infty = EQ; | ||
comp Infty (FNum y) = GT; | ||
comp (FNum x) Infty = LT; | ||
comp (FNum x) (FNum y) = compare x y; | ||
|
||
let fmin x y = | ||
match comp x y as { | ||
LT -> x; | ||
EQ -> x; | ||
GT -> y | ||
}; | ||
|
||
let minimal = foldl1 fmin; | ||
|
||
let add Infty (FNum x) = Infty; | ||
add (FNum x) Infty = Infty; | ||
add (FNum x) (FNum y) = FNum (x + y); | ||
add Infty Infty = Infty; | ||
|
||
let eq Infty Infty = True; | ||
eq Infty (FNum x) = False; | ||
eq (FNum x) Infty = False; | ||
eq (FNum x) (FNum y) = x == y; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2529,7 +2529,7 @@ source-map@^0.6.1: | |
resolved "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz" | ||
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== | ||
|
||
[email protected]: | ||
spago@^0.20.9: | ||
version "0.20.9" | ||
resolved "https://registry.npmjs.org/spago/-/spago-0.20.9.tgz" | ||
integrity sha512-r5TUxnYn9HawlQyMswlhIk24BGFSN2KGbqgZFZrn47GjTpMscU14xkt9CqTWgoSQYsoZieG+3dUtOxUQ7GYD7w== | ||
|