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

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)  

 

转载于:https://www.cnblogs.com/yunyaniu/p/8469762.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值