def test_5_layers(self): training_input = np.array([[1]]) expected_output = np.array([[1]]) flexible_neural_network = FlexibleNeuralNetwork() flexible_neural_network.add_layer(NeuralNetworkLayer(1, 1)) flexible_neural_network.add_layer(NeuralNetworkLayer(1, 1)) flexible_neural_network.add_layer(NeuralNetworkLayer(1, 1)) flexible_neural_network.add_layer(NeuralNetworkLayer(1, 1)) flexible_neural_network.add_layer(NeuralNetworkLayer(1, 1)) loss = None for i in range(self.training_rounds): loss = flexible_neural_network.train([(training_input, expected_output)]) self.log.info("Loss: {}".format(loss)) prediction = flexible_neural_network.predict(training_input) self.log.info("Prediction, Expected: {}, {}".format( prediction, expected_output)) np.testing.assert_almost_equal(loss, 0, 2)
def test_2_layers(self): #training_input = np.array([[0, 0, 1], # [0, 1, 1], # [1, 0, 1], # [1, 1, 1]]) training_input = np.array([[0], [0], [1], [1]]) expected_output = np.array([[0], [1], [1], [0]]) flexible_neural_network = FlexibleNeuralNetwork() flexible_neural_network.add_layer(NeuralNetworkLayer(4, 4)) flexible_neural_network.add_layer(NeuralNetworkLayer(4, 4)) loss = None for i in range(self.training_rounds): loss = flexible_neural_network.train([(training_input, expected_output)]) self.log.info("Loss: {}".format(loss)) prediction = flexible_neural_network.predict(training_input) self.log.info("Prediction, Expected: {}, {}".format( prediction, expected_output))