📄 aismain.m
字号:
function [] = AISMAIN
%
% Function AISMAIN Demonstration
% Runs a Demo for the following immune tools:
% 1) CLONALG (Basic Clonal Selection Algorithm)-----CLONALG.doc
%
%
% Secondary Functions:
% Internal Subfunctions:
% present----show all method
% choose---decide which one is selected
% CADEIA---create init Ab and Ag matrix data
% Auxiliary Subfunctions:
% hardlim----transfer function,hardlims(n) = 1, if n >= 0; 0, otherwise
% hardlims----transfer function,hardlims(n) = 1, if n >= 0; -1, otherwise
% ga3d--------ENHANCED GENETIC ALGORITHM - Bi-classist Selection
% Copyrigth by Min Hu
% May, 2004
%
% Function chooses the demo
while 1,
p = present; choose(p);
disp('Press any key to continue...'); pause;
end;
% ------------------------- %
% INTERNAL SUBFUNCTIONS
% ------------------------- %
% Function presents the DEMO TOOLBOX
function p = present,
clc; disp('*-----------------------------------------------*');
disp(sprintf('ARTIFICIAL IMMUNE SYSTEMS - TUTORIAL PRESENTATION'));
disp(sprintf(' Min hu'));
disp(sprintf(' May 2004'));
disp('*-----------------------------------------------*');
disp(sprintf('Available Demos:'));
disp(sprintf('1) CLONALG'));
p = input('Type the desired demo number (or CTRL^C to Interrupt): ');
% End function PRESENT
% Function allows choosing Demos
function choose(p);
switch p,
case 1,
disp(sprintf('\n** PART III - CLONALG (The CLONal Selection ALGorithm) **'));
v = cadeia(100,44,0,0,0);
disp(sprintf('Available Demo Tasks:'));
disp(sprintf('1) GA (GLOBAL SEARCH)'));
disp(sprintf('2) CLONALG (MULTI-MODAL OPTIMIZATION)'));
ga_cga = input('Type the desired demo number (1) or (2): ');
switch ga_cga,
case 1,
disp(sprintf('** Standard Genetic Algorithm - GA **'));
figure(1); clf;
[x,y,fx,vx,vmfit,P] = ga3d(v);
disp(sprintf('Maximum found [x,y,f(x,y)]: [%.2f,%.2f,%.2f]',x,y,fx));
figure(2); plot(vx); title('f(x,y) x Mean'); xlabel('Generations'); ylabel('f(x)');
hold on; plot(vmfit,'r'); hold off;
case 2,
disp(sprintf('** Clonal Selection Algorithm - CLONALG **'));
figure(3); clf; %v = v(1:50,:);
[x,y,fx,vfx,vmfit,P,vpm] = imalg3d(v);
save data x y fx vfx;
disp(sprintf('Maximum found [x,y,f(x,y)]: [%.2f,%.2f,%.2f]',x,y,fx));
figure(4); clf; plot(vfx); title('f(x,y) x Mean'); xlabel('Generations'); ylabel('f(x)');
hold on; plot(vmfit,'r'); hold off;
otherwise,
display('Accepted values are (1) or (2) ');
end; % End Switch ga_cga
otherwise,
disp(sprintf('Accepted values are (1)'));
break;
end;%End Switch p
% End Function CHOOSE
% Function CADEIA
function [ab,ag] = cadeia(n1,s1,n2,s2,bip)
%default parameter value seeting
if nargin == 2,
n2 = n1; s2 = s1; bip = 1;
elseif nargin == 4,
bip = 1;
end;
% Antibody (Ab) chains
ab = 2 .* rand(n1,s1) - 1;%create n1 row s1 column array, its value range is between -1 or 1
if bip == 1,
ab = hardlims(ab);
else,
ab = hardlim(ab);
end;
% Antigen (Ag) chains
ag = 2 .* rand(n2,s2) - 1;
if bip == 1,
ag = hardlims(ag);
else,
ag = hardlim(ag);
end;
% End Function CADEIA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -