Beispiel #1
0
 def test_numeric_gradient(self):
     l = ReluLayer()
     x = np.random.rand(2)
     gradient = l.numeric_gradient(x)
     l.forward(x)
     delta = l.backward([1, 1])
     assert_almost_equal(np.diag(gradient), delta, decimal=5)
Beispiel #2
0
 def test_forward_backward(self):
     l = ReluLayer()
     y = l.forward(np.array([5, 5]))
     self.assertEqual(y.shape, (2, ))
     assert_almost_equal(y, np.array([5, 5]))
     x = np.random.rand(2)
     d = l.backward(x)
     self.assertEqual(d.shape, (2, ))
     assert_almost_equal(d, np.array(x), decimal=5)
     return