前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >RNN的简单的推导演算公式(BPTT)

RNN的简单的推导演算公式(BPTT)

作者头像
Gxjun
发布2018-03-27 11:40:53
1.6K0
发布2018-03-27 11:40:53
举报
文章被收录于专栏:ml

附上y=2x-b拟合的简单的代码.

代码语言:javascript
复制
 1 import numpy as np
 2 x = np.asarray([2,1,3,5,6]);
 3 y = np.zeros((1,5));
 4 learning_rate=0.1;
 5 w=5;
 6 
 7 for i in range(len(x)):
 8     y[0][i]= func(x[i]);
 9     
10 def func(x):
11     return 2*x -6;
12 
13 def forward(w,x):
14     return w*x -6;
15 
16 def backward(w,x,y):
17     pred_y = w*x -6;
18     loss = (y - pred_y);
19     delta_w = loss;
20     w += (learning_rate*loss);
21     return w;
22     
23 def train(w):
24     for epoch in range(5):
25         for i in range(len(x)):
26             print 'w = {} ,pred_y = {} ,y ={}'.format(w,forward(w,x[i]),y[0][i]);
27             w = backward(w,x[i],y[0][i]);
28 if __name__ == '__main__':
29     train(w);
代码语言:javascript
复制
w = 5 ,pred_y = 4 ,y =-2.0
w = 4.4 ,pred_y = -1.6 ,y =-4.0
w = 4.16 ,pred_y = 6.48 ,y =0.0
w = 3.512 ,pred_y = 11.56 ,y =4.0
w = 2.756 ,pred_y = 10.536 ,y =6.0
w = 2.3024 ,pred_y = -1.3952 ,y =-2.0
w = 2.24192 ,pred_y = -3.75808 ,y =-4.0
w = 2.217728 ,pred_y = 0.653184 ,y =0.0
w = 2.1524096 ,pred_y = 4.762048 ,y =4.0
w = 2.0762048 ,pred_y = 6.4572288 ,y =6.0
w = 2.03048192 ,pred_y = -1.93903616 ,y =-2.0
w = 2.024385536 ,pred_y = -3.975614464 ,y =-4.0
w = 2.0219469824 ,pred_y = 0.0658409472 ,y =0.0
w = 2.01536288768 ,pred_y = 4.0768144384 ,y =4.0
w = 2.00768144384 ,pred_y = 6.04608866304 ,y =6.0
w = 2.00307257754 ,pred_y = -1.99385484493 ,y =-2.0
w = 2.00245806203 ,pred_y = -3.99754193797 ,y =-4.0
w = 2.00221225583 ,pred_y = 0.00663676747776 ,y =0.0
w = 2.00154857908 ,pred_y = 4.00774289539 ,y =4.0
w = 2.00077428954 ,pred_y = 6.00464573723 ,y =6.0
w = 2.00030971582 ,pred_y = -1.99938056837 ,y =-2.0
w = 2.00024777265 ,pred_y = -3.99975222735 ,y =-4.0
w = 2.00022299539 ,pred_y = 0.000668986161758 ,y =0.0
w = 2.00015609677 ,pred_y = 4.00078048386 ,y =4.0
w = 2.00007804839 ,pred_y = 6.00046829031 ,y =6.0
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-09-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档