Esempio n. 1
0
 def test_update_weights(self):
     layer = Layer(np.array([1, 1, 2]))
     w0 = layer.w
     acc_error, lr = np.array([0.5, 0.5, 0.5]), 5
     layer.solve_bwd(acc_error, lr)
     layer.update_weights()
     self.assertTrue((layer.w == (w0 + layer.delta_w)).all())
Esempio n. 2
0
 def test_solve_bwd_requires_one_arg(self):
     layer = Layer(np.array([1, 1, 2]))
     regex = 'missing 1 required positional argument: \'acc_error\''
     with self.assertRaisesRegex(TypeError, regex):
         layer.solve_bwd()
Esempio n. 3
0
 def test_delta_w_matches_neuron_dimension(self):
     layer = Layer(np.array([1, 1, 2]))
     layer.solve_bwd(np.zeros(3))
     self.assertEqual(len(layer.delta_w), layer.dim)
Esempio n. 4
0
 def test_error_passed_back_matches_neuron_dimension(self):
     layer = Layer(np.array([1, 1, 2]))
     layer.solve_bwd(np.zeros(3))
     self.assertEqual(len(layer.e), layer.dim)
Esempio n. 5
0
 def test_delta_w_value(self):
     layer = Layer(np.array([1, 1, 2]))
     acc_error, lr = np.array([0.5, 0.5, 0.5]), 5
     layer.solve_bwd(acc_error, lr)
     expected = -lr * acc_error * layer.partial_s * layer.x
     self.assertTrue((layer.delta_w == expected).all())
Esempio n. 6
0
 def test_error_passed_back_meets_chain_rule(self):
     layer = Layer(np.array([1, 1, 2]))
     acc_error = np.array([0.5, 0.5, 0.5])
     layer.solve_bwd(acc_error, 5)
     chain_rule = acc_error * layer.partial_s * layer.w
     self.assertTrue((layer.e == chain_rule).all())
Esempio n. 7
0
 def test_partial_s_dimension_matches_neuron_qty(self):
     layer = Layer(np.array([1, 1, 2]))
     layer.solve_bwd(np.zeros(3), 5)
     self.assertEqual(len(layer.partial_s), layer.dim)
Esempio n. 8
0
 def test_partial_s_is_the_derivative_of_sigmoid_function(self):
     layer = Layer(np.array([1, 1, 2]))
     part_s = layer.s * (1 - layer.s)
     layer.solve_bwd(np.zeros(3), 5)
     self.assertTrue((part_s == layer.partial_s).all())
Esempio n. 9
0
 def test_solve_bwd_acc_error_matches_dimension(self):
     layer = Layer(np.array([1, 1, 2]))
     regex = 'The accumulated error dimension doesn\'t match!'
     with self.assertRaisesRegex(ValueError, regex):
         layer.solve_bwd(np.zeros(5))
Esempio n. 10
0
 def test_solve_bwd_acc_error_should_be_np_array(self):
     layer = Layer(np.array([1, 1, 2]))
     regex = 'The accumulated error should be a numpy array'
     with self.assertRaisesRegex(TypeError, regex):
         layer.solve_bwd('void')