-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_helper.py
61 lines (46 loc) · 1.96 KB
/
test_helper.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
57
58
59
60
61
#import context
import pymtrf
import numpy as np
from .simulate_test_data import build_test_data
def test_lag_builder_positive_lags():
# Test lag_builder for the creation of a positive lag vector
lags = pymtrf.lag_builder(1, 4)
assert np.all(lags == [1, 2, 3, 4])
def test_lag_builder_negative_lags():
# Test lag_builder for the creation of a negative lag vector, starting with
# a negative value
lags = pymtrf.lag_builder(-2, 2)
assert np.all(lags == [-2, -1, 0, 1, 2])
def test_lag_builder_negative_lags_reverse():
# Test lag_builder for the creation of a negative lag vector, starting with
# a positive value
lags = pymtrf.lag_builder(2, -2)
assert np.all(lags == [2, 1, 0, -1, -2])
def test_lag_builder_starting_from_zero():
# Test lag_builder for the creation of a negative lag vector, starting with
# a positive value
lags = pymtrf.lag_builder(0, 3)
assert np.all(lags == [0, 1, 2, 3])
def test_lag_builder_only_zero():
# Test lag_builder for the creation of a negative lag vector, starting with
# a positive value
lags = pymtrf.lag_builder(0, 0)
assert np.all(lags == [0])
def test_quadratic_regularization_3():
m_mat = pymtrf.quadratic_regularization(3)
test_mat = np.array([[1, -1, 0], [-1, 2, -1], [0, -1, 1]])
assert np.all(m_mat == test_mat)
def test_quadratic_regularization_5():
m_mat = pymtrf.quadratic_regularization(5)
test_mat = np.array([[1, -1, 0, 0, 0], [-1, 2, -1, 0, 0],
[0, -1, 2, -1, 0], [0, 0, -1, 2, -1],
[0, 0, 0, -1, 1]])
assert np.all(m_mat == test_mat)
def test_create_test_data():
x_shape = np.array([64 * 8, 5])
y_shape = np.array([64 * 8, 6])
model_shape = np.array([5, 9, 6])
x, model, y =build_test_data()
assert np.all(x.shape == x_shape)
assert np.all(model.shape == model_shape)
assert np.all(y.shape == y_shape)