def test_update_neural_network_against_values(self): # Create and initialize neural net input = [3, 3, 3, 0.3] myNeuralNetwork = NeuralNetwork(input) myNeuralNetwork.init_neural_network() # overwrite arrays with book values default_input_vector_list = [0.9, 0.1, 0.8] default_input_vector = numpy.array(default_input_vector_list).reshape(len(default_input_vector_list), 1) myNeuralNetwork.set_array(myNeuralNetwork.get_input_vector(), default_input_vector) default_weight_input_hidden = numpy.array([[0.9, 0.3, 0.4], [0.2, 0.8, 0.2], [0.1, 0.5, 0.6]]) myNeuralNetwork.set_array(myNeuralNetwork.get_weight_input_hidden(), default_weight_input_hidden) default_weight_hidden_output = numpy.array([[0.3, 0.7, 0.5], [0.6, 0.5, 0.2], [0.8, 0.1, 0.9]]) myNeuralNetwork.set_array(myNeuralNetwork.get_weight_hidden_output(), default_weight_hidden_output) # Call function under test output = myNeuralNetwork.query(myNeuralNetwork.input_vector) # Validate results expected_output = [0.726,0.708,0.778] expected_output_array = numpy.array(expected_output).reshape(len(expected_output), 1) for n in range(0,expected_output_array.shape[0]): for m in range(0,expected_output_array.shape[1]): self.assertTrue(expected_output_array[n,m] == output[n,m],msg="output value is not equal as expected!".format(expected_output,output))
def create_neural_net(): input = [3, 3, 3, 0.3] myNeuralNetwork = NeuralNetwork(input) myNeuralNetwork.init_neural_network() default_input_vector_list = [0.9,0.1,0.8] default_input_vector = numpy.array(default_input_vector_list).reshape(len(default_input_vector_list), 1) myNeuralNetwork.set_array(myNeuralNetwork.get_input_vector(),default_input_vector) default_weight_input_hidden = numpy.array([[0.9,0.3,0.4],[0.2,0.8,0.2],[0.1,0.5,0.6]]) myNeuralNetwork.set_array(myNeuralNetwork.get_weight_input_hidden(),default_weight_input_hidden) default_weight_hidden_output = numpy.array([[0.3, 0.7, 0.5], [0.6, 0.5, 0.2], [0.8, 0.1, 0.9]]) myNeuralNetwork.set_array(myNeuralNetwork.get_weight_hidden_output(), default_weight_hidden_output) return myNeuralNetwork