📄 ga_ex352.m
字号:
% GA_ex352.m file
% Find weights and bias of an EXOR gate by using GA
% PenChen Chou, 7-24-2001
%**********************************************************/
% User can modify the following in blocks
%**********************************************************/
global MIN_offset MUL_factor LOCUS x_data y_data
global Emin net
MIN_offset=2e5; LOCUS=0; x_data=[]; y_data=[];
MUL_factor=100000;
Emin=MIN_offset;
obj_fcn = 'GA_f352'; % Objective function
UB=5*ones(1,9); LB=-UB;
range = [LB;UB];
IC=[];elite=1;
gen_no=1000; popuSize=40;
bit_n=35; xover_rate=1; mutate_rate=0.08;
net = newff([0 1;0 1],[2 1],{'tansig' 'purelin'});
%************************************************************
% calling GA
tic
% function [popu, popu_real, fcn_value, upper, average,...
% lower, BEST_popu, popuSize, gen_no, para]=GA_genetic(obj_fcn,...
% range, IC, elite, gen_no, popuSize, bit_n, xover_rate,...
% mutate_rate);
[popu, popu_real, fcn_value, upper, average, lower, ...
BEST_popu, popuSize, gen_no, para] = GA_genetic(obj_fcn,...
range, IC, elite, gen_no, popuSize, bit_n, xover_rate,...
mutate_rate);
t=toc/60;
fprintf('==> Computation time is (%.2f) minutes.\n',t);
% Show the result using parameters found by GA
A1=para(1:2); A2=para(3:4); net.IW{1,1}=[A1;A2];
net.b{1}=para(5:6)';
net.LW{2,1}=para(7:8);
net.b{2}=para(9);
In_pattern=[ 0 0;0 1;1 0;1 1]';
Neural_out=sim(net,In_pattern)
Target=[1 0 0 1]
% Train these parameters now
net.trainParam.epochs = 500;
net=train(net,In_pattern,Target);
% Show the final result
Neural_out=sim(net,In_pattern)
Target=[1 0 0 1]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -