def test_numeric_gradient(self): l = SigmoidLayer() 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)
def test_forward_backward(self): l = SigmoidLayer() y = l.forward(np.array([5, 5])) self.assertEqual(y.shape, (2, )) assert_almost_equal(y, np.array([0.993307, 0.993307]), decimal=5) d = l.backward(np.array([2, 3])) self.assertEqual(d.shape, (2, )) assert_almost_equal(d, np.array([0.0132961, 0.0199442]), decimal=5) return