-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mlp.py
More file actions
44 lines (33 loc) · 1.02 KB
/
test_mlp.py
File metadata and controls
44 lines (33 loc) · 1.02 KB
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
import numpy as np
import pytest
from modules.mlp import one_hot, softmax
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.array([7, 8, 9])
a1 = np.array([a, a, a])
b1 = np.array([b, b])
c1 = np.array([c, c])
def test_softmax():
with pytest.raises(np.AxisError):
softmax(0)
with pytest.raises(np.AxisError):
softmax(a)
res = [np.exp(1 - 3), np.exp(2 - 3), np.exp(3 - 3)]
res1 = np.array([res, res, res])
sum = np.exp(1 - 3) + np.exp(2 - 3) + np.exp(3 - 3)
assert np.array_equal(softmax(a1), res1 / sum)
return
def test_one_hot():
hot_0 = np.array([1])
hot_a = np.array([[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
hot_a1 = np.array(
[
[[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],
[[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],
[[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]],
]
)
assert np.array_equal(one_hot(a), hot_a)
assert np.array_equal(one_hot(a1), hot_a1)
assert np.array_equal(one_hot(0), hot_0)
return