TVP

# 从零学习：从Python和R理解和编码神经网络

“从零学习”系列第一篇从Python和R理解和编码神经网络来自Analytics Vidhya博主、印度资深数据科学开发人员SUNIL RAY。

x为输入矩阵；

y为输出矩阵。

wh为隐藏层的权值矩阵；

bh为隐藏层的bias矩阵；

wout为输出层的权值矩阵；

bout为输出层的bias矩阵。

hiddenlayerinput = matrixdotproduct（X，wh）+bh

hiddenlayeractivations = sigmoid（hiddenlayer_input）

outputlayerinput = matrixdotproduct (hiddenlayeractivations × wout ) + bout output = sigmoid(outputlayer_input)

E=y–output

slopeoutputlayer = derivativessigmoid(output) slopehiddenlayer = derivativessigmoid(hiddenlayer_activations)

doutput = E × slopeoutput_layer

Errorathiddenlayer = matrixdotproduct（doutput，wout.Transpose）

dhiddenlayer = Errorathiddenlayer × slopehiddenlayer

wout = wout + matrixdotproduct（hiddenlayeractivations.Transpose，doutput）× learning_rate

wh = wh + matrixdotproduct（X.Transpose，dhiddenlayer）× learningrate

bias at outputlayer =bias at outputlayer + sum of delta of outputlayer at row-wise × learningrate

bias at hiddenlayer =bias at hiddenlayer + sum of delta of outputlayer at row-wise × learningrate

bh = bh + sum(dhiddenlayer, axis=0)×learningrate

bout = bout + sum(doutput, axis=0)×learningrate

hiddenlayerinput = matrixdotproduct（X，wh）+ bh

hiddenlayeractivations = sigmoid（hiddenlayer_input）

outputlayerinput = matrixdotproduct（hiddenlayeractivations × wout）+ bout output = sigmoid（outputlayer_input）

E = y-output

Slopeoutputlayer= derivativessigmoid(output) Slopehiddenlayer = derivativessigmoid(hiddenlayer_activations)

doutput = E × slopeoutput_layer*lr

Errorathiddenlayer = matrixdotproduct(doutput, wout.Transpose)

dhiddenlayer = Errorathiddenlayer × slopehiddenlayer

wout = wout + matrixdotproduct(hiddenlayeractivations.Transpose, doutput)×learningrate wh = wh+ matrixdotproduct(X.Transpose,dhiddenlayer)×learning_rate

bh = bh + sum(dhiddenlayer, axis=0) ×learningrate bout = bout + sum(doutput, axis=0)×learningrate

h=σ(u)= σ (WiX)，其中h是u的函数，u是Wi和x的函数。这里我们将激活函数表示为σ。

Y=σ(u')=σ(Whh)，其中Y是u'的函数，u'是Wh和h的函数。

∂E/∂Wh = (∂E/∂Y).( ∂Y/∂u’).( ∂u’/∂Wh)……（1）

(∂Y/∂u’)= ∂( σ(u’)/ ∂u’= σ(u’)(1-σ(u’))

(∂Y/∂u’)=Y(1-Y)

∂E/∂Wh = (Y-t). Y(1-Y).h

∂E/∂Wi =(∂E/∂h). (∂h/∂u).( ∂u/∂Wi)

∂E/∂Wi =[(∂E/∂Y).( ∂Y/∂u’).( ∂u’/∂h)]. (∂h/∂u).( ∂u/∂Wi)……（2）

∂u’/∂h = ∂(Whh)/ ∂h = Wh

∂h/∂u = ∂( σ(u)/ ∂u= σ(u)(1- σ(u))

(∂Y/∂u)=h(1-h)

∂E/∂Wi = [(Y-t). Y(1-Y).Wh].h(1-h).X

Wh = Wh + η . ∂E/∂Wh

Wi = Wi + η . ∂E/∂Wi

• 发表于:
• 原文链接http://kuaibao.qq.com/s/20171216G0DR1S00?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23

2024-04-23