📄 ga_tipper.m
字号:
% GA_tipper.m file
% This is a demo. program to illustrate how to involve a GA program
% to find the best MEMBERSHIP FUNCTIONS as well as RULES in a FIS
% system when I/O is given.
% PenChen Chou, 3-28-2002
clear all
!del xxx.dat
diary xxx.dat
ans=1; who
fprintf('>>>Start this program [GA_tipper] now. Please wait!\n');
pause(1)
global MUL_factor MIN_offset tipper3 Emin RESULT N_rules Target in
global out IN_main
MUL_factor=1; IN_main=0;
MIN_offset=0; % If =0, it is a maximization problem
MIN_offset=8e+5; % If it is a minimization problem, set it to
% positive integer.
Emin=MIN_offset;
% Read in data such as Target and in
load IO_data
%**********************************************************/
% User can modify the following in blocks
%**********************************************************/
obj_fcn = 'GA_fis'; % Objective function
% x(1,2)=0.1 ---2
% x(3) =0.05-- 8
% x(4) =0.1-- 10
% x(5) = 0-- 5
% x(6,7)=1 or 2 only (and, or)
% x(8,9)=1 or 2 or 3 only
% Range of the input variables
% x1 2 3 4 5 6 7 8 9
range=[0.10 0.10 2.00 2.1 0.10 1 1 1 1
2.00 2.00 5.00 10 15 2 2 3 3];
IC=[]; elite=1; gen_no=1000;
popuSize=50; bit_n=40;
xover_rate=0.77; mutate_rate=0.2;
%************************************************************
% call GA main function
tic
[popu, popu_real, fcn_value, upper, average,...
lower, BEST_popu, popuSize, gen_no, para, best_pi,...
bit_n, xover_rate, mutate_rate]=...
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\n',t);
% Show the final result
IN_main=1; x=para;
x(6)=round(x(6)); x(7)=round(x(7));
x(8)=round(x(8)); x(9)=round(x(9));
PI=GA_fis(x); load xxx1
% Check results
RESULT
[in Target out]
% Plot membership functions
figure(3);
subplot(221); plotmf(tipper3,'input',1);grid
subplot(222); plotmf(tipper3,'input',2);grid
subplot(212); plotmf(tipper3,'output',1);grid
% Show rules
showrule(tipper3,[1:N_rules],'verbose')
% Draw surface
figure(4); x=0:0.25:10; y=x;
[service, food]=meshgrid(x,y);
tip=0*service; [M,N]=size(service);
for i=1:M
for j=1:N
b=[service(i,j) food(i,j)];
tip(i,j)=evalfis(b,tipper3);
end
end
mesh(service,food,tip); xlabel('service')
ylabel('food'); zlabel('tip')
clear b M N i j x y
sum(abs(Target-out))
fprintf('See the log file---xxx.dat for more detail\n');
diary off
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -