码迷,mamicode.com
首页 > 其他好文 > 详细

GA:GA优化BP神经网络的初始权值、阈值,从而增强BP神经网络的鲁棒性—Jason niu

时间:2018-02-25 19:23:01      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:鲁棒性   神经网络   com   ali   lin   连接   ade   图片   glob   

global p     
global t     
global R     % 输入神经元个数,此处是6个
global S1    % 隐层神经元个数,此处是10个
global S2    % 输出神经元个数,此处是4个
global S     % 连接权值个数+阈值个数即(6*10+10*4)+(10+4)
S1 = 10;

p = [0.01 0.01 0.00 0.90 0.05 0.00;
     0.00 0.00 0.00 0.40 0.50 0.00;
     0.80 0.00 0.10 0.00 0.00 0.00;
     0.00 0.20 0.10 0.00 0.00 0.10]‘;
t = [1.00 0.00 0.00 0.00;
     0.00 1.00 0.00 0.00;
     0.00 0.00 1.00 0.00;
     0.00 0.00 0.00 1.00]‘;

P_test = [0.05 0    0.9  0.12 0.02 0.02;
          0    0    0.9  0.05 0.05 0.05;
          0.01 0.02 0.45 0.22 0.04 0.06;
          0    0    0.4  0.5  0.1  0;
          0    0.1  0    0    0    0]‘;

net = newff(minmax(p),[S1,4],{‘tansig‘,‘purelin‘},‘trainlm‘); 

net.trainParam.show = 10;
net.trainParam.epochs = 2000;
net.trainParam.goal = 1.0e-3;
net.trainParam.lr = 0.1;

[net,tr] = train(net,p,t);

s_bp = sim(net,P_test)   

R = size(p,1);
S2 = size(t,1);
S = R*S1 + S1*S2 + S1 + S2;
aa = ones(S,1)*[-1,1];

popu = 50;  
initPpp = initializega(popu,aa,‘gabpEval‘,[],[1e-6 1]);  

gen = 100;  

[x,endPop,bPop,trace] = ga(aa,‘gabpEval‘,[],initPpp,[1e-6 1 1],‘maxGenTerm‘,gen,...
                           ‘normGeomSelect‘,[0.09],[‘arithXover‘],[2],‘nonUnifMutation‘,[2 gen 3]);

figure(1)
plot(trace(:,1),1./trace(:,3),‘r-‘);
title( ‘GA优化BP神经网络,绘制均方误差变化曲线—Jason niu‘) 
hold on
plot(trace(:,1),1./trace(:,2),‘b-‘);
xlabel(‘Generation‘);
ylabel(‘Sum-Squared Error‘);

figure(2)
plot(trace(:,1),trace(:,3),‘r-‘);
title( ‘GA优化BP神经网络,绘制适应度函数变化曲线—Jason niu‘) 
hold on
plot(trace(:,1),trace(:,2),‘b-‘);
xlabel(‘Generation‘);
ylabel(‘Fittness‘);

[W1,B1,W2,B2,val] = gadecod(x);

net.IW{1,1} = W1;
net.LW{2,1} = W2;
net.b{1} = B1;
net.b{2} = B2;

net = train(net,p,t);

s_ga = sim(net,P_test)  

技术分享图片

技术分享图片

 

GA:GA优化BP神经网络的初始权值、阈值,从而增强BP神经网络的鲁棒性—Jason niu

标签:鲁棒性   神经网络   com   ali   lin   连接   ade   图片   glob   

原文地址:https://www.cnblogs.com/yunyaniu/p/8469762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!