-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_connectivity.py
135 lines (88 loc) · 4.61 KB
/
test_connectivity.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import numpy as np
import numpy.testing as npt
import unittest
from data_transformer import transform_normal_to_neural_single
from data_transformer import transform_neural_to_normal_single
from data_transformer import transform_neural_to_normal
from connectivity_functions import calculate_probability, calculate_coactivations
from connectivity_functions import softmax
class TestDataTransformer(unittest.TestCase):
def test_normal_to_neural_simplest(self):
test_input_1 = np.array((1, 0, 1, 0))
test_input_2 = np.array((0, 1, 0, 1))
desired_1 = np.array((0, 1, 1, 0, 0, 1, 1, 0))
desired_2 = np.array((1, 0, 0, 1, 1, 0, 0, 1))
transform_1 = transform_normal_to_neural_single(test_input_1)
transform_2 = transform_normal_to_neural_single(test_input_2)
npt.assert_almost_equal(transform_1, desired_1)
npt.assert_almost_equal(transform_2, desired_2)
def test_normal_to_neural_more_than_two_minicolumns(self):
test_input = np.array((0, 1, 2, 3))
desired = np.array((1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1))
minicolumns = 4
transform = transform_normal_to_neural_single(test_input, minicolumns)
npt.assert_almost_equal(desired, transform)
test_input = np.array((0, 1, 3))
desired = np.array((1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1))
minicolumns = 4
transform = transform_normal_to_neural_single(test_input, minicolumns)
npt.assert_almost_equal(desired, transform)
def test_neural_to_normal_simplest(self):
test_input_1 = np.array((0, 1, 1, 0, 0, 1, 1, 0))
test_input_2 = np.array((1, 0, 0, 1, 1, 0, 0, 1))
desired_1 = np.array((1, 0, 1, 0))
desired_2 = np.array((0, 1, 0, 1))
transform_1 = transform_neural_to_normal_single(test_input_1)
transform_2 = transform_neural_to_normal_single(test_input_2)
npt.assert_almost_equal(transform_1, desired_1)
npt.assert_almost_equal(transform_2, desired_2)
def test_neural_to_normal_more_than_two_minicolumns(self):
test_input = np.array((1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1))
desired = np.array((0, 1, 2, 3))
minicolumns = 4
transform = transform_neural_to_normal_single(test_input, minicolumns)
npt.assert_almost_equal(transform, desired)
test_input = np.array((1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1))
desired = np.array((0, 1, 3))
minicolumns = 4
transform = transform_neural_to_normal_single(test_input,minicolumns)
npt.assert_almost_equal(desired, transform)
def test_neural_to_normal(self):
test_input = np.array(((0, 1, 1, 0, 0, 1), (1, 0, 0, 1, 0, 1), (0, 1, 1, 0, 0, 1)))
desired = np.array(((1, 0, 1), (0, 1, 1), (1, 0, 1)))
transform = transform_neural_to_normal(test_input)
npt.assert_almost_equal(transform, desired)
class TestSoftmax(unittest.TestCase):
def test_softmax_for_more_than_two_minicolumns(self):
minicolumns = 4
test_input1 = np.array((4, 1, 1, 2))
test_input2 = np.array((10, 5, 3, 2))
test_input3 = np.array((3, 1, 1, 1))
test_input = np.concatenate((test_input1, test_input2, test_input3))
exp_input1 = np.exp(test_input1)
exp_input2 = np.exp(test_input2)
exp_input3 = np.exp(test_input3)
desired1 = exp_input1 / np.sum(exp_input1)
desired2 = exp_input2 / np.sum(exp_input2)
desired3 = exp_input3 / np.sum(exp_input3)
desired = np.concatenate((desired1, desired2, desired3))
transformed = softmax(test_input, 1.0, minicolumns=minicolumns)
npt.assert_almost_equal(transformed, desired)
class TestProbabilities(unittest.TestCase):
def test_unit_probabilities(self):
test_pattern1 = np.array((1, 0, 1, 0))
test_pattern2 = np.array((0, 1, 0, 1))
patterns = [test_pattern1, test_pattern2]
desired_probability = np.array((0.5, 0.5, 0.5, 0.5))
calculated_probability = calculate_probability(patterns)
npt.assert_almost_equal(calculated_probability, desired_probability)
def test_coactivations(self):
test_pattern1 = np.array((1, 0, 1, 0))
test_pattern2 = np.array((0, 1, 0, 1))
patterns = [test_pattern1, test_pattern2]
desired_coactivations = np.array(((0.5, 0, 0.5, 0), (0, 0.5, 0, 0.5),
(0.5, 0, 0.5, 0), (0, 0.5, 0, 0.5)))
calculated_coactivations = calculate_coactivations(patterns)
npt.assert_almost_equal(desired_coactivations, calculated_coactivations)
if __name__ == '__main__':
unittest.main()