Beispiel #1
0
    def test_biases_is_correct_vector(self):
        layer = Layer(size=5,
                      prev_size=2,
                      activation=activation_functions.Sigmoid)
        biases = layer.biases()
        self.assertTupleEqual(biases.shape, (5, ))

        layer = Layer(size=2,
                      prev_size=3,
                      activation=activation_functions.Sigmoid)
        biases = layer.biases()
        self.assertTupleEqual(biases.shape, (2, ))
Beispiel #2
0
 def test_biases_is_of_correct_type(self):
     layer = Layer(size=5,
                   prev_size=2,
                   activation=activation_functions.Sigmoid)
     biases = layer.biases()
     self.assertIsInstance(biases, np.ndarray)
     self.assertIn(biases.dtype, [np.float32, np.float64])
Beispiel #3
0
    def test_with_single_hidden_layer(self):
        layer = Layer(size=3,
                      prev_size=2,
                      activation=activation_functions.Sigmoid)
        biases = [-2, 0.5, 9]
        layer.set_biases(biases=np.array(biases, float))

        self.assertEqual(layer.biases().tolist(), [-2, 0.5, 9])
Beispiel #4
0
    def test_set_bias(self):
        layer = Layer(size=3,
                      prev_size=2,
                      activation=activation_functions.Sigmoid)
        layer.set_bias(row=0, new_value=2)
        layer.set_bias(row=1, new_value=-0.5)

        expected_b = np.array([2, -0.5, 0], float)

        self.assertEqual(layer.biases().tolist(), expected_b.tolist())