-
-
Notifications
You must be signed in to change notification settings - Fork 297
/
test_sigmoid.py
37 lines (30 loc) · 1.09 KB
/
test_sigmoid.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
import unittest
import numpy as np
from dezero import Variable
import dezero.functions as F
from dezero.utils import gradient_check, array_allclose
import chainer.functions as CF
class TestSigmoid(unittest.TestCase):
def test_forward1(self):
x = np.array([[0, 1, 2], [0, 2, 4]], np.float32)
y2 = CF.sigmoid(x)
y = F.sigmoid(Variable(x))
res = array_allclose(y.data, y2.data)
self.assertTrue(res)
def test_forward2(self):
x = np.random.randn(10, 10).astype(np.float32)
y2 = CF.sigmoid(x)
y = F.sigmoid(Variable(x))
res = array_allclose(y.data, y2.data)
self.assertTrue(res)
def test_backward1(self):
x_data = np.array([[0, 1, 2], [0, 2, 4]])
self.assertTrue(gradient_check(F.sigmoid, x_data))
def test_backward2(self):
np.random.seed(0)
x_data = np.random.rand(10, 10)
self.assertTrue(gradient_check(F.sigmoid, x_data))
def test_backward3(self):
np.random.seed(0)
x_data = np.random.rand(10, 10, 10)
self.assertTrue(gradient_check(F.sigmoid, x_data))