📄 auto_elevator_design.m
字号:
% auto_elevator_design.m
% Use FFNN to design a special ELEVATOR.
% Refer to Demuth's Neural Network Design textbook.
% This is the example on P.6-147 of Chou's textbook.
% PenChen Chou, Aug. 20, 2001
% Revised on Apl. 21, 2002
% ChiZen May , Aug. 20, 2001
global net P T Emin MUL_factor MIN_offset
% Use 5-2 FFNN, given input and target patterns
P=[ 0 0 0 1 1 -1 1 -1 -1 1 -1 -1 -1 1 1 1 1 -1
0 0 0 1 -1 1 -1 1 -1 1 -1 1 -1 -1 1 -1 1 -1
1 0 0 1 0 0 0 1 1 1 0 0 0 0 0 1 0 0
0 1 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1 0
0 0 1 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1];
T= [1 1 -1 1 1 -1 1 -1 -1 1 -1 -1 -1 1 1 1 1 -1
1 -1 1 1 -1 1 -1 1 -1 1 -1 1 -1 -1 1 -1 1 -1];
% New NN. Transfer function can be tansig or purelin, but
% it would not help.
net=newff([-1 1;-1 1;0 1;0 1;0 1],[2],{'hardlims'});
net.trainFcn='traingdx';
net.trainParam.epochs=2000;
% Start learning
fprintf('===>Start NN training.\n');
net=train(net,P,T);
% Get NN output
Y=sim(net,P);
% See if it is OK or not.
disp('==>See result from NN learning');
T-Y
if sum(sum(T-Y))==0
disp('Good job, no GA search required.')
else
disp('Type <CR> to continue');
pause
% Use of GA to find those weights and bias of NN
MUL_factor=1; MIN_offset=1000;
Emin=MIN_offset;
LO=-500*ones(1,12); HI=500*ones(1,12);
range=[LO;HI];
obj_fcn='auto_func';
bit_n = 100; % Bit number for each input variable
gen_no = 80; % Number of generations
popuSize = 56; % Population size
xover_rate = 0.97; % Crossover rate (BETTER)
mutate_rate = 0.1; % Mutation rate (BETTER)
elite=1;IC=[];
% call GA
tic
[popu, popu_real, fcn_value, upper, average, lower, ...
BEST_popu, popuSize, gen_no, para] = GA_genetic(obj_fcn,...
range, IC, elite, gen_no, popuSize);
tc=toc/60;
fprintf('==> Computation time is (%.2f) minutes.\n',tc);
% Get weights and bias
net.IW{1,1}=[popu_real(1,1:5);popu_real(1,6:10)];
net.b{1}=[popu_real(1,11);popu_real(1,12)];
Y=sim(net,P);
disp('==>See result from GA search');
T-Y
if sum(sum(T-Y))~=0
% NN training again
net.trainParam.epochs=1000;
net=train(net,P,T);
Y=sim(net,P);
disp('==>See result from 2nd-time NN learning');
T-Y
end;
if sum(sum(T-Y))==0
disp('==>You got a perfect solution, the W and b are:');
net.IW{1,1}
net.b{1}
else
disp('<<<<< Sorry, try again');
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -