1 importnumpy as np2 importscipy.special as ss3 importmatplotlib.pyplot as plt4 importimageio as im5 importglob as gl6
7
8 classNeuralNetwork:9 #initialise the network
10 def __init__(self, inputnodes, hiddennodes, outputnodes, learningrate):11 #set number of each layer
12 self.inodes =inputnodes13 self.hnodes =hiddennodes14 self.onodes =outputnodes15 self.wih = np.random.normal(0.0, pow(self.inodes, -0.5), (self.hnodes, self.inodes))16 self.who = np.random.normal(0.0, pow(self.hnodes, -0.5), (self.onodes, self.hnodes))17 #learning rate
18 self.lr =learningrate19 #activation function is sigmoid
20 self.activation_function = lambdax: ss.expit(x)21 pass
22
23 #train the neural network
24 deftrain(self, inputs_list, targets_list):25 inputs = np.array(inputs_list, ndmin=2).T26 targets = np.array(targets_list, ndmin=2).T27 hidden_inp