手算前向与后向神经网络
其中,
输入数据 i1=0.05,i2=0.10;
输出数据 o1=0.01,o2=0.99;
初始权重 w1=0.15,w2=0.20,w3=0.25,w4=0.30;
w5=0.40,w6=0.45,w7=0.50,w8=0.55
激活函数 sigmoid函数
1 1 + e − x \frac{1}{1+e^{-x}} 1+e−x1
损失函数(与老师上课板书内容一致,课件中均方差不同)
1 2 ( y − o u t ) 2 \frac{1}{2}(y-out)^2 21(y−out)2
目标:给出输入数据i1,i2(0.05和0.10),使输出尽可能与原始输出o1,o2(0.01和0.99)接近。
给出解答
前向传播:
输入->隐藏层:
n e t h 1 = i 1 × w 1 + i 2 × w 2 + 1 × b 1 = 0.15 ∗ 0.05 + 0.2 ∗ 0.1 + 0.35 ∗ 1 = 0.3775 net_{h1}=i1\times w1+i2\times w2+1\times b1=0.15*0.05+0.2*0.1+0.35*1=0.3775 neth1=i1×w1+i2×w2+1×b1=0.15∗0.05+0.2∗0.1+0.35∗1=0.3775
o u t h 1 = s i g m i o d ( n e t h 1 ) = 0.5933 out_{h1}=sigmiod\left( net_{h1} \right) =0.5933 outh1=sigmiod(neth1)=0.5933
同理
o u t h 2 = s i g m i o d ( n e t h 2 ) = 0.5969 out_{h2}=sigmiod\left( net_{h2} \right) =0.5969 outh2=sigmiod(neth2)=0.5969
隐藏层->输出层
同样算法可以得到:
n e t o 1 = w 5 × o u t h 1 + w 6 × o u t h 2 + b 2 × 1 net_{o1}=w5\times out_{h1}+w6\times out_{h2}+b2\times 1 neto1=w5×outh1+w6×outh2+b2×1
o u t o 1 = s i g m o i d ( n e t o 1 ) = 0.7514 out_{o1}=sigmoid\left( net_{o1} \right) =0.7514 outo1=sigmoid(neto1)=0.7514
o u t o 2 = s i g m o i d ( n e t o 2 ) = 0.7729 out_{o2}=sigmoid\left( net_{o2} \right) =0.7729 outo2=sigmoid(neto2)=0.7729
我们得到输出值为[0.7514,0.7729],与实际值[0.01 , 0.99]相差还很远,
所以我们需要对权值进行修改,然后使得实际值与输出值相似。此时我们需要对其进行反向传播。
反向传播:
本质上,我们是使用梯度下降法,求出我们