-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
35 lines (28 loc) · 2.64 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import dtw_algorithm
import math
def test_dtw():
# Christian's example from 4/10 talk
"""
desired end matrix looks like this: doing min of (cell above, to left, or diagonal to the upper left), going from top left to bottom right:
0 (1)inf (2)inf (1)inf
(1)inf 0 1 1
(1)inf 0 1 1
(2)inf 1 0 1
(1)inf 1 1 0*
"""
a = [1, 2, 1]
b = [1, 1, 2, 1]
assert(dtw_algorithm.dtw(a, b) == 0), "Basic Euclidean-distance based test failed"
s1 = sine_wave(360, 1)
s2 = sine_wave(360, 2)
assert(dtw_algorithm.dtw(s1, s2) < 2), "Sine wave test failed"
gesture_a = dtw_algorithm.create_gesture([[-7, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -4, 3], [-9, -4, 3], [-9, -4, 3], [-9, -4, 3], [-9, -4, 3], [-8, -4, 3], [-8, -4, 4], [-8, -4, 4], [-8, -4, 4], [-8, -4, 5], [-7, -4, 6], [-6, -4, 6], [-6, -4, 7], [-6, -4, 7], [-5, -4, 8], [-4, -4, 9], [-3, -4, 10], [-3, -5, 10], [-3, -5, 10], [-3, -4, 10], [-2, -4, 9], [-2, -4, 8], [-2, -4, 7], [-2, -3, 6], [-2, -3, 5], [-2, -4, 5], [-2, -4, 5], [-2, -4, 5], [-3, -4, 5], [-3, -4, 6], [-5, -3, 7], [-6, -3, 8], [-8, -2, 9], [-9, -1, 10], [-10, -1, 11], [-11, 0, 11], [-11, 0, 12], [-11, 0, 12], [-11, -1, 11], [-11, -1, 11], [-10, -1, 11], [-9, -1, 11], [-8, -1, 11], [-7, -1, 11], [-7, 0, 11], [-7, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 10], [-5, 1, 9], [-5, 2, 8], [-5, 2, 7], [-6, 2, 6], [-6, 2, 4]])
gesture_b = dtw_algorithm.create_gesture([[-7, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -5, 4], [-8, -4, 3], [-9, -4, 3], [-9, -4, 3], [-9, -4, 3], [-9, -4, 3], [-8, -4, 3], [-8, -4, 4], [-8, -4, 4], [-8, -4, 4], [-8, -4, 5], [-7, -4, 6], [-6, -4, 6], [-6, -4, 7], [-6, -4, 7], [-5, -4, 8], [-4, -4, 9], [-3, -4, 10], [-3, -5, 10], [-3, -5, 10], [-3, -4, 10], [-2, -4, 9], [-2, -4, 8], [-2, -4, 7], [-2, -3, 6], [-2, -3, 5], [-2, -4, 5], [-2, -4, 5], [-2, -4, 5], [-3, -4, 5], [-3, -4, 6], [-5, -3, 7], [-6, -3, 8], [-8, -2, 9], [-9, -1, 10], [-10, -1, 11], [-11, 0, 11], [-11, 0, 12], [-11, 0, 12], [-11, -1, 11], [-11, -1, 11], [-10, -1, 11], [-9, -1, 11], [-8, -1, 11], [-7, -1, 11], [-7, 0, 11], [-7, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 11], [-6, 1, 10], [-5, 1, 9], [-5, 2, 8], [-5, 2, 7], [-6, 2, 6], [-6, 2, 4]])
assert(gesture_a - gesture_b == 0), "Gesture objects failed"
# given degrees and step size, product and return list of vectors for a sine wave
def sine_wave(degrees, step):
vector_list = []
for i in range(1, degrees, step):
vector = math.sin(math.radians(i))
vector_list.append(vector)
return vector_list