?? gabpfault.m
字號:
tic, %開始計時
% 首先進行遺傳算法
[P,T,R,S1,S2,S]=nninit;
aa=ones(S,1)*[-1 1];
popu=30;
initPpp=initializega(popu,aa,'gabpEval');
gen=80; % 遺傳代數
% 遺傳計算
[x endPop bPop trace]=ga(aa,'gabpEval',[],initPpp,[1e-6 1 1],'maxGenTerm',gen,... 'normGeomSelect',[0.09],['arithXover'],[2],'nonUnifMutation',[2 gen 3]);% x The best found
% Lets take a look at the performance of the ga during the run
subplot(2,1,1)plot(trace(:,1),1./trace(:,3),'r-')hold onplot(trace(:,1),1./trace(:,2),'b-')
xlabel('Generation');
ylabel('Sum-Squared Error');
subplot(2,1,2)plot(trace(:,1),trace(:,3),'r-')hold onplot(trace(:,1),trace(:,2),'b-')
xlabel('Generation');
ylabel('Fittness');
% 下面進行BP算法
figure(2)
% 將遺傳算法的結果分解為BP網絡所對應的權值、閾值
[W1 B1 W2 B2 P T A1 A2 SE val]=gadecod(x);
% BP網絡訓練的參數設置
disp_fqre=100; max_epoch=3000;err_goal=0.002;lr=0.01;
TP=[disp_fqre max_epoch err_goal lr];
[W1,B1,W2,B2,te,tr]=trainbp(W1,B1,'tansig',W2,B2,'purelin',P,T,TP);
% 仿真結果
TT=simuff(P,W1,B1,'tansig',W2,B2,'purelin')
toc % 結束計時
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -