PythonNN_demo003
def train(self, input_list, target_list): | |
inputs = np.array(input_list, ndmin=2).T | |
targets = np.array(target_list, ndmin=2).T | |
# signals into hidden layer | |
hidden_inputs = np.dot(self.wih, inputs) | |
# signals from hidden layer | |
hidden_outputs = self.activation_func(hidden_inputs) | |
# signals into output | |
final_inputs = np.dot(self.who, hidden_outputs) | |
# signals from output | |
outputs = self.activation_func(final_inputs) | |
# error between hidden and output | |
output_errors = targets - outputs | |
# error between input and hiddent | |
hidden_errors = np.dot(self.who.T, output_errors) | |
# updating weight between hidden and output layers | |
self.who += self.alpha * np.dot((output_errors * outputs * (1.0 - outputs)), | |
np.transpose(hidden_outputs)) | |
# updating weight between input and hidden | |
self.wih += self.alpha * np.dot((hidden_errors * hidden_outputs * (1.0 - hidden_outputs)), | |
np.transpose(inputs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment