130 likes | 264 Vues
BP 算法汇总. ( 1 ). ( 2 ). ( 3 ). sigmoid 函数(取值在 [0 , 1] 之间)的导数. sigmoid 函数(取值在 [0 , 1] 之间)的导数. 对称型 Sigmoid 函数(取值在 [-1 , 1] 之间. 对称型 Sigmoid 函数(取值在 [-1 , 1] 之间. 对称型 Sigmoid 函数的导数. BP 算法的实现(初始化). clear in=5; hid=5; out=1; N=2000; w2=rand(hid,in)-0.5; w3=rand(out,hid)-0.5;
E N D
BP算法汇总 (1) (2) (3)
BP算法的实现(初始化) clear in=5; hid=5; out=1; N=2000; w2=rand(hid,in)-0.5; w3=rand(out,hid)-0.5; a=0.1; y(:,1:3)=zeros(1,3); u=2*(rand(1,N)-.5); for k=4:N y(k)=0.7*(y(k-1)*y(k-2)*y(k-3)*u(k-2)*(y(k-3)-1)+u(k-1))/(1+y(k-2)^2+y(k-3)^2); end
BP算法的实现(前向计算) for k=4:N x1=[y(k-1)y(k-2)y(k-3)u(k-1)u(k-2)]; for i=1:hid x2(:,i)=sigmoid2(x1*w2(i,:)'); end y1(k)=sigmoid2(x2*w3'); e(k)=y(k)-y1(k); e1(k)=e(k)*e(k); mste(k)=sum(e1)/k; disp([k mste(k)]);
BP算法的实现(误差反向传播) delt3=e(k)*(1-y1(k))*(1+y1(k))/2; for j=1:hid delt2(j)=(1+x2(j)).*(1-x2(j))./2.*delt3.*w3(j) ; w3(j)=w3(j)+a*delt3*x2(j) end for j=1:hid for l=1:in w2(j,l)=w2(j,l)+a*delt2(j)*x1(l); end end end %End of the train
BP算法的实现(测试数据产生) for k=1:500 u(k)=sin(2*pi*k/250); end for k=501:1000 u(k)=0.8*sin(2*pi*k/250)+0.2*sin(2*pi*k/25); end for k=4:1000 y(k)=0.7*(y(k-1)*y(k-2)*y(k-3)*u(k-2)*(y(k-3)-1)+u(k-1))/(1+y(k-2)^2+y(k-3)^2); end
BP算法的实现(测试数据产生) for k=4:1000 x1=[y(k-1)y(k-2)y(k-3)u(k-1)u(k-2)] for i=1:hid x2(:,i)=sigmoid2(x1*w2(i,:)'); end y1(k)=sigmoid2(x2*w3'); ee(k)=y(k)-y1(k); disp([k,ee(k)]); End
BP算法的实现(学习结果显示) clf t=1:1000; subplot(211),plot(t,y(t),'r',t,y1(t),'-g') xlabel('Time k') grid subplot(212),plot(mste) xlabel('Time k')
Sigmoid2.m 函数文件 • function y=sigmoid2(x) • y=(1-exp(-x))/(1+exp(-x)) • end