-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocorrelation_tests.py
56 lines (40 loc) · 1.96 KB
/
autocorrelation_tests.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import unittest
import numpy as np
from autocorrelation import (
one_hot_encode,
index_autocorrelate,
index_autocorrelate_old,
vector_autocorrelate,
vector_autocorrelate_signal
)
class TestACMethods(unittest.TestCase):
def test_oh(self):
zero = 0
max_num = 5
num = 4
self.assertTrue(np.all(one_hot_encode(num, max_num) == np.array([0, 0, 0, 1, 0])))
self.assertTrue(np.all(one_hot_encode(zero, max_num) == np.array([0, 0, 0, 0, 0])))
self.assertTrue(np.all(one_hot_encode(zero, 1) == np.array([0])))
self.assertTrue(np.all(one_hot_encode(1, 1) == np.array([1])))
self.assertTrue(np.all(one_hot_encode(0, 0) == np.array([0])))
def test_id_ac(self):
index_ts = [35, 35, 36, 0]
self.assertTrue(np.all(np.abs(index_autocorrelate(index_ts) - np.array([3/4, 1/3, 0, 0])) < 0.000001))
self.assertTrue(np.all(np.abs(index_autocorrelate([35, 35, 36]) - np.array([1, 1/2, 0])) < 0.000001))
self.assertTrue(np.all(np.abs(index_autocorrelate([0, 0]) - np.array([0, 0])) < 0.000001))
self.assertTrue(np.all(np.abs(index_autocorrelate([35, 35, 35]) - np.array([1,1,1])) < 0.000001))
def test_id_ac_old(self):
index_ts = [35, 35, 36, 0]
self.assertTrue(np.all(np.abs(index_autocorrelate_old(index_ts) - np.array([3/4, 1/3, 0, 0])) < 0.000001))
def test_vec_ac(self):
ts_array = np.array([
[1,0,0],[1,0,0],[0.8, 0.6, 0],[0,1,0]
])
self.assertTrue(np.all(np.abs(vector_autocorrelate(ts_array) - np.array([1, 0.8, 0.4, 0.0])) < 0.000001))
def test_vec_ac_signal(self):
ts_array = np.array([
[1,0,0],[1,0,0],[0.8, 0.6, 0],[0,1,0]
])
self.assertTrue(np.all(np.abs(vector_autocorrelate_signal(ts_array) - np.array([1, 0.8, 0.4, 0.0])) < 0.000001))
if __name__ == '__main__':
unittest.main()