📄 bp1.m
字号:
% bp1;例4.1
P=-1:0.1:1;
P2=-1:0.1:1;
T=[-0.96 -0.577 -0.0729 0.377 0.641 0.66 0.461 0.1336 ...
-0.201 -0.434 -0.5 -0.393 -0.1647 0.0988 0.3072 ...
0.396 0.3449 0.1816 -0.0312 -0.2183 -0.3201];
plot(P,T,'r+');
[R,Q]=size(P);[S2,Q]=size(T);S1=5;
[W1,B1]=rands(S1,R);
[W2,B2]=rands(S2,S1);
b1=[];b2=[];
b1=B1*ones(1,21);
b2=B2*ones(1,21);
a2=W2*tansig(W1*P2+b1)+b2;
A2=purelin(a2);
hold on
plot(P,A2)
hold off
disp('按任一键继续')
pause
net=newcf(minmax(P),[5,1],{'tansig','purelin'},'traingd'); %创建两层前向回馈网络
net.trainParam.epochs=7000; %初始化训练次数
net.trainParam.goal=9.5238e-004; % sse=0.02 %初始化误差值
net.trainParam.lr = 0.15;
[net,tr]=train(net,P,T); %训练网络
Y=sim(net,P) ; %计算结果
plot(P,Y,'r-')
hold
plot(P,T,'r+');
hold off
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -