def test_gradient_checking(self): layer = Loss('binary_crossentropy') X = np.random.rand(5, 1) y = np.random.randint(0, high=2, size=(5, )) expected = approx_fprime(X, layer.forwardprop, y) got = layer.backprop(X, y) np.testing.assert_array_almost_equal(got, expected, decimal=5)
def test_gradient_checking(self): layer = Loss('mse') X = np.random.rand(5, 1) y = np.random.rand(5, ) expected = approx_fprime(X, layer.forwardprop, y) got = layer.backprop(X, y) np.testing.assert_array_almost_equal(got, expected, decimal=6)
def test_gradient_checking(self): layer = Dropout(0.36) X = np.random.randn(5, 4) dout = np.random.randn(5, 4) layer.forwardprop(X, training=True) expected = approx_fprime(X, layer.forwardprop, True, False) got = layer.backprop(dout) np.testing.assert_array_almost_equal(got / dout, expected, decimal=6)
def test_gradient_checking(self): layer = Activation('tanh') X = np.random.randn(5, 4) expected = approx_fprime(X, layer.activation.forwardprop) got = layer.activation.backprop(X) np.testing.assert_array_almost_equal(got, expected, decimal=5)