You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Return the output of the Network if "a" is input"""
forb, winzip(self.biases, self.weights):
a=sigmoid(np.dot(w,a)+b)
#view activations
returna
defscaleGSImg(self,wei):
min,max,minPos,maxPos=cv2.minMaxLoc(wei)
#print min,max
wei= (wei-min)*255/(max-min)
wei=wei.astype(int)
wei=cv2.convertScaleAbs(wei,alpha=1)
returnwei
defSGD(self, training_data, epochs, mini_batch_size, eta, test_data=None):
"""Train the neural network using mini-batch stochastic gradient descent. The "training_data" is a list of tuples "(x, y)" representing the training inputs and the desired outputs. The other non-optional parameters are self-explanatory. If "test_data" is provided then the network will be evaluated against the test data after each epoch, and partial progress printed out. This is useful for tracking prorgress, but slows things down substantially."""
iftest_data: n_test=len(test_data)
n=len(training_data)
forjinxrange(epochs):
random.shuffle(training_data)
mini_batches= [
training_data[k:k+mini_batch_size]
forkinxrange(0, n, mini_batch_size)]
formini_batchinmini_batches:
self.update_mini_batch(mini_batch, eta)
#display weights and biases after every training set
"""update the network's weights and biases by applyling gradient descent using backpropagation to a single mini batch.The "mini_batch" is a list of tuples "(x,y)", and "eta" is the learning rate."""
"""return a tuple ``(nabla_b, nabla_w)`` representing the gradient for the cost function C_x. ``nabla_b`` and ``nabla_w`` are layer-by-layer lists of numpy arrays, similar to ``self.biases`` and ``self.weights``."""
nabla_b= [np.zeros(b.shape) forbinself.biases]
nabla_w= [np.zeros(w.shape) forwinself.weights]
#feedforward
activation=x
activations= [x] #list to store all the activations, layer by layer
zs= [] # list to store all the z vectors, layer by layer
"""Note that the variable 1 in the loop is used a little differently to the notation in chapter 2 of the book. Here, l = 1 means the last layer of neurons,l = 2 is the second-last layer, and so on. It's a renumbering of the scheme in the book used here to take advantage of the fact that Python can use negative indices in lists."""
"""Return the number of test inputs for which the neural network outputs the correct result. Note that the neural network's output is assumed to be the index of whichever neuron in the final layer has the highest activation."""
test_results= [(np.argmax(self.feedforward(x)),y) for (x, y) intest_data]
returnsum(int(x==y) for (x,y) intest_results)
defcost_derivative(self, output_activations, y):
"""Return the vector of partial derivatives \partial C_x /\partial a for the output activations."""