示例#1
0
 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)
示例#2
0
 def test_backprop(self):
     layer = Loss('binary_crossentropy', self.pre_activation)
     layer.forwardprop(self.X, self.y)
     got = layer.backprop(self.X, self.y)
     expected = np.array([[-0.121425], [-0.129134], [0.024423],
                          [-0.141438]])
     np.testing.assert_array_almost_equal(got, expected)
示例#3
0
 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)
示例#4
0
 def test_backprop(self):
     layer = Loss('categorical_crossentropy')
     got = layer.backprop(self.X, self.Y)
     expected = np.array([[-0.75884941, 0.31418862, 0.4683878],
                          [0.27145113, -2.66022481, 1.44507894],
                          [0.25905253, 0.31131663, -0.32548008],
                          [-1.38090534, 0.35791875, 0.51807233]])
     np.testing.assert_array_almost_equal(got, expected)
示例#5
0
 def test_backprop(self):
     layer = Loss('categorical_crossentropy', self.pre_activation)
     layer.forwardprop(self.X, self.Y)
     got = layer.backprop(self.X, self.Y)
     expected = np.array([[-0.16763847, 0.05107491, 0.11656356],
                          [0.01975598, -0.22650574, 0.20674977],
                          [0.00873619, 0.04923977, -0.05797596],
                          [-0.20473984, 0.07537936, 0.12936047]])
     np.testing.assert_array_almost_equal(got, expected)
示例#6
0
 def test_forwardprop(self):
     layer = Loss('categorical_crossentropy')
     got = layer.forwardprop(self.X, self.Y)
     expected = 2.370872
     np.testing.assert_almost_equal(got, expected, decimal=6)
示例#7
0
 def test_forwardprop(self):
     layer = Loss('binary_crossentropy', self.pre_activation)
     got = layer.forwardprop(self.X, self.y)
     expected = 0.582168
     np.testing.assert_almost_equal(got, expected, decimal=6)
示例#8
0
 def test_backprop(self):
     layer = Loss('binary_crossentropy')
     got = layer.backprop(self.X, self.y)
     expected = np.array([[-0.486099], [-0.517103], [0.277067],
                          [-0.575709]])
     np.testing.assert_array_almost_equal(got, expected)
示例#9
0
 def test_backprop(self):
     layer = Loss('mse')
     got = layer.backprop(self.X, self.y)
     expected = np.array([[-3.639313], [-0.242277], [0.872887],
                          [-2.622873]])
     np.testing.assert_array_almost_equal(got, expected)
示例#10
0
 def test_forwardprop(self):
     layer = Loss('mse')
     got = layer.forwardprop(self.X, self.y)
     expected = 41.889377
     np.testing.assert_almost_equal(got, expected, decimal=6)