?? 4--2.m
字號:
%隱層節點數對公式E的影響
clear all
p = -1:0.2:1;
t = 0.5+0.4*sin(2*pi*p);
x=40;
for n=1:1:7
net=newff(minmax(p),[n,1],{'tansig','purelin'},'traingd');
net.trainParam.show = 50;
net.trainParam.lr = 0.1;
net.trainParam.lr_inc = 1.05;
net.trainParam.epochs = 1000;
net.trainParam.goal = 1e-5;
[net,tr,y,e]=train(net,p,t);
pert1=mae(e);
pert2=mae((e.^2).*0.5);
laste=1/2*pert2+1/2*x*(sum(net.iw{1,1}.^2)+sum(net.lw{2,1}.^2));
w(n)=n;
z(n)=laste;
end
figure(1)
plot(w,z,'r-o')
%λ的取值對公式E的影響
p = -1:0.2:1;
t = 0.5+0.4*sin(2*pi*p);
n=1;
for x=10:5:70
net=newff(minmax(p),[5,1],{'tansig','purelin'},'traingd');
net.trainParam.show = 50;
net.trainParam.lr = 0.1;
net.trainParam.lr_inc = 1.05;
net.trainParam.epochs = 1000;
net.trainParam.goal = 1e-5;
[net,tr,y,e]=train(net,p,t);
pert1=mae(e);
pert2=mae((e.^2).*0.5);
laste=1/2*pert2+1/2*x*(sum(net.iw{1,1}.^2)+sum(net.lw{2,1}.^2));
w(n)=x;
z(n)=laste;
n=n+1;
end
figure(2)
plot(w,z,'r-o')
%利用設計的網絡對測試集進行測試后所得的擬合曲線
p = -1:0.2:1;
t = 0.5+0.4*sin(2*pi*p);
x=40;
net=newff(minmax(p),[5,1],{'tansig','purelin'},'traingd');
net.trainParam.show = 50;
net.trainParam.lr = 0.1;
net.trainParam.lr_inc = 1.05;
net.trainParam.epochs = 1000;
net.trainParam.goal = 1e-5;
[net,tr,y1,e]=train(net,p,t);
net.iw{1,1}
net.lw{2,1}
net.b{1}
net.b{2}
pert1=mae(e);
pert2=mae((e.^2).*0.5);
laste=1/2*pert2+1/2*x*(sum(net.iw{1,1}.^2)+sum(net.lw{2,1}.^2));
p1= -1:0.05:1;
t1 = 0.5+0.4*sin(2*pi*p1);
n=1;
for p2=-1:0.05:1
y2(n)=purelin(net.lw{2,1}*tansig(net.iw{1,1}.*p2+net.b{1})+net.b{2});
n=n+1;
end
e=t1-y2;
pert1=mae(e);
plot(p1,t1,'g-+',p1,y2,'b--*');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -