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

        layer = Layer(size=2,
                      prev_size=3,
                      activation=activation_functions.Sigmoid)
        weights = layer.weights()
        self.assertTupleEqual(weights.shape, (2, 3))
Beispiel #2
0
 def test_weights_is_of_correct_type(self):
     layer = Layer(size=5,
                   prev_size=2,
                   activation=activation_functions.Sigmoid)
     weights = layer.weights()
     self.assertIsInstance(weights, np.ndarray)
     self.assertIn(weights.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)
        weights = [[0, 10], [1, 1], [-1, 0.5]]
        layer.set_weights(weights=np.array(weights, float))

        self.assertEqual(layer.weights().tolist(),
                         [[0, 10], [1, 1], [-1, 0.5]])
Beispiel #4
0
    def test_set_weight(self):
        layer = Layer(size=2,
                      prev_size=3,
                      activation=activation_functions.Sigmoid)
        layer.set_weight(row=0, col=1, new_value=2)
        layer.set_weight(row=1, col=2, new_value=-0.5)

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

        self.assertEqual(layer.weights().tolist(), expected_w.tolist())