Advanced Data Analytics Using Python_ With Machine Learning, Deep Learning and NLP Examples ( 2023)
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 5
Deep Learning and Neural Networks
to "self.biases" and "self.weights"."""
nabla_b1=[np.zeros(b1.shape)for b 1in self.biases]
nabla_w1=[np.zeros(w1.shape)for w1in self.weights]
# feedforward
activation1=x1
activations1=[x1]
zs1=[]
for b,winzip(self.biases,self.weights):
z1=np.dot(w1,activation1)+b1
zs1.append(z1)
activation1=sigmoid(z1)
activations1.append(activation1)
# backward pass
delta1=self.cost_derivative(activations1[-1],y1)* \
sigmoid_prime(zs1[-1])
nabla_b1[-1]=delta1
nabla_w1[-1]=np.dot(delta,activations1[-2].
transpose())
for l in xrange(2,self.num_layers):
z1=zs1[-l]
sp1=sigmoid_prime(z1)
delta1=np.dot(self.weights1[-l+1].
transpose(),delta)*sp1
nabla_b1[-l]=delta1
nabla_w1[-l]=np.
dot(delta,activations1[-l-1].transpose())
return(nabla_b1,nabla_w1)
def cost_derivative(self,output_activations,y):
"""Return the vector of partial derivatives \
partial C_x /
105