📄 p50.m
字号:
% p50.m
% 赋值、初始化
P=-1:0.1: 1; P2=-1:.025:1;
T=[-0.96 -.577 -.0729 .377 .641 .66 .461 .1336...
-.201 -.434 -.5 -.393 -.1647 .0988 .3072...
.396 .3449 .1816 -.0312 -.2183 -.3201];
[R,Q]=size(P), S1=5;
[S2,Q]=size(T),
%[S2,Q]=size(T2),
%画误差曲面
[W1,B1]=rands(S1,R);[W2,B2]=rands(S2,S1);
A1=tansig(W1*P,B1);A2=purelin(W2*A1,B2);
A22=purelin(W2*tansig(W1*P2,B1),B2);
h0=figure;
plot(P,T,'r+',P2,A22);axis([-1,1,-1,1]),title('初始网络');
E=T-A2;
SSE=sumsqr(E)
%训练权值
disp_freq=1000;
max_epoch=4000;
err_goal=0.02; % 期望误差
lr=0.01
for epoch=1:max_epoch
if SSE<err_goal
epoch=epoch-1;break, end
D2=deltalin(A2,E);
D1=deltatan(A1,D2,W2);
[dW1,dB1]=learnbp(P,D1,lr);
[dW2,dB2]=learnbp(A1,D2,lr);
dW1=W1+dW1;B1=B1+dB1;
dW2=W2+dW2;B2=B2+dB2;
A1=tansig(W1*P,B1);A2=purelin(W2*A1,B2);
E=T-A2;
SSE=sumsqr(E);
% SSE=sumsqr(T-purelin(W2*tansig(W1*P2,B1),B2);
% if rem(epoch,1000)==0
% n=epoch/1000
% A22=purelin(W2*tansig(W1*P2,B1),B2);
% h(n)=figure
%plot(P,T,'c+',P2,A22);axis(-1,1,-1,1),
%title('epoch=epoch');
%end
if epoch==1000
epoch
A22=purelin(W2*tansig(W1*P2,B1),B2);
h1=figure
plot(P,T,'g+',P2,A22);axis([-1,1,-1,1]),
title('epoch=1000');
SSE
pause
end
if epoch==6000
epoch
A22=purelin(W2*tansig(W1*P2,B1),B2);
h6=figure
plot(P,T,'b+',P2,A22);axis([-1,1,-1,1]),
title('epoch=6000');
SSE
end
if epoch==2000
A22=purelin(W2*tansig(W1*P2,B1),B2);
h2=figure, epoch
plot(P,T,'y+',P2,A22);axis([-1,1,-1,1]),
title('epoch=2000');SSE
pause
end
if epoch==3000
A22=purelin(W2*tansig(W1*P2,B1),B2);
h3=figure
epoch
plot(P,T,'c+',P2,A22);axis([-1,1,-1,1]),
title('epoch=3000');
SSE3=SSE
pause
end
if epoch==4000
A22=purelin(W2*tansig(W1*P2,B1),B2);
h4=figure, epoch
plot(P,T,'c*',P2,A22);axis([-1,1,-1,1]),
title('epoch=epoch');
SSE4=SSE
end
if epoch==5000
A22=purelin(W2*tansig(W1*P2,B1),B2);
h5=figure, epoch
plot(P,T,'c+',P2,A22);axis([-1,1,-1,1]),
title('epoch=5000');
SSE5=SSE
end
end
A22=purelin(W2*tansig(W1*P2,B1),B2);
h7=figure
plot(P,T,'c+',P2,A22);axis([-1,1,-1,1]),
title('epoch=epoch 终止网络');
SSEZ=SSE
epoch
end
% 最佳学习速率
% 最佳学习速率
%设置暂停方式为秒
%A=purelin(W*P,B)
%E=T-A2;
%SSE=sumsqr(E); %误差记录
%e%rrors=[SSE];
%for epoch=1:max_epoch
% if SSE<err_goal,epch=epoch-1;break,R3=R,
%end
% LW=W;LB=B;
% [DW,DB]=learnwh(P,E,lr);
% W=W+DW;B=B+DB;
%A=purelin(W*P,B); E=T-A; SSE=sumsqr(E); %学习后的再次表达式
%errors=[errors,SSE];
%训练过程中的显示
%TP=[disp_freq max_epoch err_goal lr];
%[W,B,epochs,error]=trainwh[W,B,P,T,TP] % 进行线形网络权值训练
%V=[-2 2 -2 2];
%plotpv(P,T,V);
%hold on
%plotpc(W,B)
%hold off
%end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -