计算梯度的方法+BackPropagation
2019-02-15 本文已影响0人
我好菜啊_
参考cs231n与这位的博文https://www.zhihu.com/people/will-55-30/posts?page=1 非常感谢!
为找到最好的W,即使Li最小的W,使用梯度下降法
梯度是偏导数组成的向量
计算梯度->更新W 循环迭代进行这个过程
计算梯度有两个方法
-
数值法
数值法计算梯度
-
微积分法
loss是关于W的函数,可以求导
首先初始化W为随机值,计算损失和梯度,然后向梯度相反的方向更新权重值
步长是一个超参数,也被称作学习率learning rate,每次计算出梯度时,在那个方向移动多少距离
minibatch
每次迭代时只选取一小部分样本来进行运算
back propagation求gradient
每个节点出的gradient都是local gradient乘以后一个节点的gradient

可以将好几个节点合并

当一个节点前向影响好几个分支时

模块化的实现,对于网络中的每个节点都有一个前向API用于计算loss,后向API用于计算梯度

CNN中的每一层的实现其实也就是这样一个个模块化的forward/backward API
forward: compute result of an operation and save any intermediates needed for gradient computation in memory
backward: apply the chain rule to compute the gradient of the loss function with respect to the inputs