神经网络反向传播算法
2017-08-21 17:25
246 查看
四个基本等式
证明
算法
代码
def backprop(self, x, y): """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) for b in self.biases] nabla_w = [np.zeros(w.shape) for w in self.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 for b, w in zip(self.biases, self.weights): z = np.dot(w, activation)+b zs.append(z) activation = sigmoid(z) activations.append(activation) # backward pass delta = self.cost_derivative(activations[-1], y) * \ sigmoid_prime(zs[-1]) nabla_b[-1] = delta nabla_w[-1] = np.dot(delta, activations[-2].transpose()) # Note that the variable l in the loop below 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. for l in xrange(2, self.num_layers): z = zs[-l] sp = sigmoid_prime(z) delta = np.dot(self.weights[-l+1].transpose(), delta) * sp nabla_b[-l] = delta nabla_w[-l] = np.dot(delta, activations[-l-1].transpose()) return (nabla_b, nabla_w) def cost_derivative(self, output_activations, y): """Return the vector of partial derivatives \partial C_x / \partial a for the output activations.""" return (output_activations-y) def sigmoid(z): """The sigmoid function.""" return 1.0/(1.0+np.exp(-z)) def sigmoid_prime(z): """Derivative of the sigmoid function.""" return sigmoid(z)*(1-sigmoid(z))
相关文章推荐
- 神经网络里面的反向传播算法的解释
- 神经网络与深度学习笔记——第2章 反向传播算法
- 深度学习——循环神经网络RNN(一)_反向传播算法
- 神经网络与深度学习 第二章 反向传播算法(两个假设、四个基本方程及其证明、代码及注释)
- 循环神经网络(RNN)模型与前向反向传播算法
- BP 神经网络 反向传播算法
- 神经网络笔记——反向传播算法
- 零基础入门深度学习(3) - 神经网络和反向传播算法
- 神经网络中的反向传播算法
- 多层神经网络与反向传播算法
- 循环神经网络(RNN)反向传播算法(BPTT)
- 【机器学习】神经网络(二)——反向传播算法
- 神经网络和深度学习(二)——BP(Backpropagation Algorithm, 反向传播算法)
- 零基础入门深度学习(3) - 神经网络和反向传播算法
- 神经网络训练中的Tricks之高效BP(反向传播算法)
- 人工神经网络——【BP】反向传播算法证明
- July深度学习笔记之神经网络与反向传播算法
- 一步一步学习 神经网络里面的反向传播算法
- 神经网络介绍―利用反向传播算法的模式学习
- 神经网络和反向传播算法——反向传播算法本质上是随机梯度下降,链式求导法则而来的