Beispiel #1
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())
Beispiel #2
0
    def test_raises_exception_for_erroneous_index(self):
        layer = Layer(size=2,
                      prev_size=3,
                      activation=activation_functions.Sigmoid)

        self.assertRaises(IndexError,
                          lambda: layer.set_weight(row=2, col=0, new_value=2))
        self.assertRaises(IndexError,
                          lambda: layer.set_weight(row=0, col=3, new_value=2))
        self.assertRaises(IndexError,
                          lambda: layer.set_weight(row=1, col=3, new_value=2))
        self.assertRaises(IndexError,
                          lambda: layer.set_weight(row=2, col=3, new_value=2))