Ejemplo n.º 1
0
    def test_connection_errors(self):
        with self.assertRaises(NetworkConnectionError):
            # Missed Input layer
            GradientDescent(layers.Sigmoid(10) > layers.Sigmoid(1))

        with self.assertRaises(NetworkConnectionError):
            # Cannot use input layer inside the netowkr
            GradientDescent([
                layers.Input(1),
                layers.Sigmoid(10),
                layers.Input(1),
                layers.Sigmoid(1),
            ])
Ejemplo n.º 2
0
    def test_train_epoch_end(self):
        global triggered_times

        triggered_times = 0
        epochs = 4

        def print_message(network):
            global triggered_times
            triggered_times += 1

        network = GradientDescent(
            connection=(2, 2, 1),
            epoch_end_signal=print_message,
        )

        network.train(xor_input_train, xor_target_train, epochs=epochs)
        self.assertEqual(triggered_times, epochs)
Ejemplo n.º 3
0
 def test_list_of_layers(self):
     bpnet = GradientDescent([
         layers.Input(2),
         layers.Sigmoid(3),
         layers.Sigmoid(1),
         layers.Sigmoid(10),
     ])
     self.assertEqual([layer.size for layer in bpnet.layers], [2, 3, 1, 10])
Ejemplo n.º 4
0
    def test_layers_iteratinos(self):
        network = GradientDescent((2, 2, 1))

        layers = list(network.all_layers)
        output_layer = layers.pop()

        self.assertIsNone(output_layer.relate_to_layer)
        for layer in layers:
            self.assertIsNotNone(layer.relate_to_layer)
Ejemplo n.º 5
0
    def test_recurrent_connections(self):
        inp = Sigmoid(2)
        hd = [Sigmoid(2), Sigmoid(2)]
        out = Output(1)

        GradientDescent(connection=(
            inp > hd[0] > out,
            hd[0] > hd[1],
            hd[1] > hd[0],
        ))
Ejemplo n.º 6
0
    def test_connection_initializations(self):
        possible_connections = (
            (2, 3, 1),
            [Sigmoid(2), Tanh(3), Output(1)],
            Relu(2) > Tanh(10) > Output(1),
        )

        for connection in possible_connections:
            network = GradientDescent(connection)
            self.assertEqual(len(network.all_layers), 3)
Ejemplo n.º 7
0
 def test_list_of_layers(self):
     bpnet = GradientDescent(
         [Sigmoid(2), Sigmoid(3),
          Sigmoid(1), Output(10)])
     self.assertEqual([layer.size for layer in bpnet.all_layers],
                      [2, 3, 1, 10])
Ejemplo n.º 8
0
 def test_without_output_layer(self):
     with self.assertRaises(NetworkConnectionError):
         GradientDescent(layers.Sigmoid(10) > layers.Sigmoid(1))