前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >深度学习 — 反向传播(BP)理论推导"BP" Math Principle前向传播反向传播应用实例Reference

深度学习 — 反向传播(BP)理论推导"BP" Math Principle前向传播反向传播应用实例Reference

作者头像
zhwhong
发布2018-05-16 17:05:46
1.1K0
发布2018-05-16 17:05:46
举报
文章被收录于专栏:技术随笔技术随笔

【知识预备】: UFLDL教程 - 反向传导算法

首先我们不讲数学,先上图解,看完图不懂再看后面:





"BP" Math Principle

======================================================================

Example:下面看一个简单的三层神经网络模型,一层输入层,一层隐藏层,一层输出层。

注:定义输入分别为x1, x2(对应图中的i1,i2),期望输出为y1,y2,假设logistic函数采用sigmoid函数:

undefined

undefined

易知:

undefined

undefined

下面开始正式分析(纯手打!!!)。

前向传播

首先分析神经元h1:

undefined

undefined

undefined

undefined

同理可得神经元h2:

undefined

undefined

undefined

undefined

对输出层神经元重复这个过程,使用隐藏层神经元的输出作为输入。这样就能给出o1,o2的输入输出:

undefined

undefined

undefined

undefined

undefined

undefined

undefined

undefined

现在开始统计所有误差,如下:

undefined

undefined

undefined

undefined

undefined

undefined

反向传播

【输出层】

对于w5,想知道其改变对总误差有多少影响,于是求Jtotal对w5的偏导数,如下:

undefined

undefined

分别求每一项:

undefined

undefined

undefined

undefined

undefined

undefined

于是有Jtotal对w5的偏导数:

undefined

16:http://latex.codecogs.com/png.latex?\frac{\partial%20J_{total}}{\partial%20w5}=(output_{(o1)}-y1)[output_{(o1)}(1%20-%20output_{(o1)})]*output_{(h1)}

据此更新权重w5,有:

undefined

undefined

同理可以更新参数w6,w7,w8。

在有新权重导入隐藏层神经元(即,当继续下面的反向传播算法时,使用原始权重,而不是更新的权重)之后,执行神经网络中的实际更新。

【隐藏层】

对于w1,想知道其改变对总误差有多少影响,于是求Jtotal对w1的偏导数,如下:

undefined

undefined

分别求每一项:


undefined

undefined

undefined

undefined

undefined

21:http://latex.codecogs.com/png.latex?=(output_{(o1)}-y1)[output_{(o1)}(1%20-%20output_{(o1)})]*w5

undefined

undefined

undefined

23:http://latex.codecogs.com/png.latex?=(output_{(o2)}-y2)[output_{(o2)}(1%20-%20output_{(o2)})]*w7


undefined

undefined


undefined

undefined

于是有Jtotal对w1的偏导数:

undefined

26:http://latex.codecogs.com/png.latex?\frac{\partial%20J_{total}}{\partial%20w1}={(output_{(o1)}-y1)[output_{(o1)}(1%20-%20output_{(o1)})]*w5

undefined

27:http://latex.codecogs.com/png.latex?+%20(output_{(o2)}-y2)[output_{(o2)}(1%20-%20output_{(o2)})]w7}

undefined

28:http://latex.codecogs.com/png.latex?[output_{(h1)}_(1%20-%20output_{(h1)})]_x1

据此更新w1,有:

undefined

undefined

同理可以更新参数w2,w3,w4。

======================================================================

应用实例

假设对于上述简单三层网络模型,按如下方式初始化权重和偏置:

根据上述推导的公式:

undefined

得到:

input(h1) = 0.15 * 0.05 + 0.20 * 0.10 + 0.35 = 0.3775

output(h1) = f(input(h1)) = 1 / (1 + e^(-input(h1))) = 1 / (1 + e^-0.3775) = 0.593269992

同样得到:

input(h2) = 0.25 * 0.05 + 0.30 * 0.10 + 0.35 = 0.3925

output(h2) = f(input(h2)) = 1 / (1 + e^(-input(h2))) = 1 / (1 + e^-0.3925) = 0.596884378

对输出层神经元重复这个过程,使用隐藏层神经元的输出作为输入。这样就能给出o1的输出:

input(o1) = w5 * output(h1) + w6 * (output(h2)) + b2 = 0.40 * 0.593269992 + 0.45 * 0.596884378 + 0.60 = 1.105905967

output(o1) = f(input(o1)) = 1 / (1 + e^-1.105905967) = 0.75136507

同理output(o2) = 0.772928465

开始统计所有误差,求代价函数:

Jo1 = 1/2 * (0.75136507 - 0.01)^2 = 0.298371109

Jo2 = 1/2 * (0.772928465 - 0.99)^2 = 0.023560026

综合所述,可以得到总误差为:Jtotal = Jo1 + Jo2 = 0.321931135

然后反向传播,根据公式

undefined

求出 Jtotal对w5的偏导数为:

a = (0.75136507 - 0.01)*0.75136507*(1-0.75136507)*0.593269992 = 0.082167041

为了减少误差,然后从当前的权重减去这个值(可选择乘以一个学习率,比如设置为0.5),得:

w5+ = w5 - eta * a = 0.40 - 0.5 * 0.082167041 = 0.35891648

同理可以求出:

w6+ = 0.408666186

w7+ = 0.511301270

w8+ = 0.561370121

对于隐藏层,更新w1,求Jtotal对w1的偏导数:

undefined

undefined

undefined

偏导数为:

b = (tmp1 + tmp2) * tmp3

tmp1 = (0.75136507 - 0.01) * 0.75136507 * (1 - 0.75136507) * 0.40 = 0.74136507 * 0.186815602 * 0.40 = 0.055399425

tmp2 = -0.019049119

tmp3 = 0.593269992 * (1 - 0.593269992) * 0.05 = 0.012065035

于是b = 0.000438568

更新权重w1为:

w1+ = w1 - eta * b = 0.15 - 0.5 * 0.000438568 = 0.149780716

同样可以求得:

w2+ = 0.19956143

w3+ = 0.24975114

w4+ = 0.29950229

最后,更新了所有的权重! 当最初前馈传播时输入为0.05和0.1,网络上的误差是0.298371109。 在第一轮反向传播之后,总误差现在下降到0.291027924。 它可能看起来不太多,但是在重复此过程10,000次之后。例如,错误倾斜到0.000035085。

在这一点上,当前馈输入为0.05和0.1时,两个输出神经元产生0.015912196(相对于目标为0.01)和0.984065734(相对于目标为0.99),已经很接近了O(∩_∩)O~~

Reference


(注:感谢您的阅读,希望本文对您有所帮助。如果觉得不错欢迎分享转载,但请先点击 这里 获取授权。本文由 版权印 提供保护,禁止任何形式的未授权违规转载,谢谢!)

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016.12.13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • "BP" Math Principle
  • 前向传播
  • 反向传播
    • 【输出层】
      • 【隐藏层】
      • 应用实例
      • Reference
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档