⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tutorial.m

📁 This manual describes how to run the Matlab&reg Artificial Immune Systems tutorial presentation deve
💻 M
字号:
function [] = tutorial
%
% Function TUTORIAL Demonstration
% Runs a Demo for the following immune tools:
% 1) ABNET (Growing Boolean Competitive Network - journal.doc)
% 2) CLONALG (Clonal Selection Algorithm - gecco00.doc)
% 3) AINET (Artificial Immune Network - ainet.doc)
%
% Other Sources of Reference: RT DCA 01/99 (Artificial Immune Systems Part I - Basic Theory and Applications)
%
% Secondary Functions: 
% Internal Subfunctions: PRESENT, CHOOSE, DRAW_ABNET, PLOTVET, CADEIA
% Auxiliary Subfunctions: ABNET, GA3D, IMALG3D, AINET, ANALYSIS, DENDRO
%
% Copyrigth by Leandro Nunes de Castro
% April/May, 2000
%

% Function chooses the demo
while 1,
   p = present; choose(p);
   disp(sprintf('Pressione qualquer tecla para continuar...'));pause;
end;


% ------------------------- %
%   INTERNAL SUBFUNCTIONS
% ------------------------- %

% Function presents the DEMO TOOLBOX
function p = present,
clc; disp('*-----------------------------------------------*');
disp(sprintf('    ENGENHARIA IMUNOL覩ICA - DEFESA DE TESE'));
disp(sprintf('    Candidato: Leandro Nunes de Castro'));
disp(sprintf('    Data: 11 de Maio de 2001'));
disp('*-----------------------------------------------*');
disp(sprintf('Demos Dispon韛eis:'));
disp(sprintf('1) SAND'));
disp(sprintf('2) CLONALG'));
disp(sprintf('3) ABNET'));
disp(sprintf('4) aiNet'));
p = input('Escolha o demo desejado (ou CTRL^C para Sair): ');
% End function PRESENT


% Function allows choosing Demos
function choose(p);
switch p,
case 1,
   disp(sprintf('\n** PARTE I - SAND (Simulated ANnealing Approach to Increase Diversity) **'));
   disp(sprintf('Demos dispon韛eis:'));
   disp(sprintf('1) Espa鏾 de Formas Bin醨io de Hamming'));
   disp(sprintf('2) Espa鏾 de Formas Euclidiano'));
   disp(sprintf('3) Inicializa玢o de MLP Treinado via Backpropagation'));
   task = input('Escolha o demo desejado (1), (2) or (3): ');
   switch task,
   case 1,
      N = input('Escolha o tamanho N da popula玢o [2,8]: ');
      [ab,vE,E] = sacubic(N);
      figure(3); plot(vE); title('Evolu玢o da Energia (E)');
      axis([0 length(vE) 0 105]);
   case 2,
      N = input('Escolha o tamanho N da popula玢o: ');
      ab = randn(N,2);
      [ab,vE,vRb,E,Rb] = sareal(ab);
      figure(3); plot(vRb); title('Evolu玢o da Energia (E)');
      axis([0 length(vRb) 0 105]);
   case 3,
      disp(sprintf('Problema de Paridade 3'));
      nh = 3; minerr = 0.01; maxep = 200; val = 0.1;
      % dados_soja; P = norma(P); T = norma(T);
      load dados_par3; vNep1 = []; vNep2 = [];
      [np,ni] = size(P); [np,no] = size(T);
      disp(sprintf('N鷐ero m醲imo de itera珲es: %d',maxep));
      disp(sprintf('N鷐ero de amostras: %d',length(T)));
      disp(sprintf('Crit閞io de parada: SSE=%.2f',minerr));
      disp(sprintf('Dimens鉶 da rede: [%d,%d,%d]',ni,nh,no));
      disp(sprintf('Pressione qualquer tecla para continuar...'));pause;
      for i=1:3,
         w1 = 2.* val.*rand(ni+1,nh) - val; w1sa = w1;
         w2 = 2.* val.*rand(nh+1,no) - val; w2sa = w2;
         [Nep1,T1] = scgm(P,T,nh,minerr,maxep,w1,w2);
         [w1sa,Tsand] = sareal_init(w1);
         % w1sa = val.*w1sa;
         [Nep2,Tscgm] = scgm(P,T,nh,minerr,maxep,w1sa,w2sa);
         T2 = Tsand + Tscgm;
         vNep1 = [vNep1;Nep1]; vNep2 = [vNep2;Nep2];
      end;
      disp('   Rand  SAND');
      m = [vNep1,vNep2]; disp(m);
      %disp(sprintf('Inicializa玢o aleat髍ia: Nep = %d, T = %.1f',Nep1,T1));
      %disp(sprintf('Inicializa玢o via SAND: Nep = %d, T = %.1f',Nep2,T2));
   otherwise,
      disp('Os valores aceitos s鉶 (1), (2) ou (3)');
   end; % End switch task SAD
case 2,
   disp(sprintf('\n** PARTE II - CLONALG (CLONal Selection ALGorithm) **'));
   % figure(1); clf;
   v = cadeia(100,44,0,0,0);
   disp(sprintf('Demos dispon韛eis:'));
   disp(sprintf('1) CHARACTER (APRENDIZAGEM DE M罳UINA)'));
   disp(sprintf('2) GA (OTIMIZA敲O GLOBAL)'));
   disp(sprintf('3) CLONALG (OTIMIZA敲O MULTIMODAL)'));
   ga_cga = input('Escolha o demo desejado (1), (2) or (3): ');
   switch ga_cga,
   case 1,
      disp(sprintf('** CLONALG - APRENDIZAGEM DE M罳UINA**'));
      load num8_12x10; X = v(1,:); P = cadeia(10,120,0,0,0);
      M = imalgchar(P,X);
   case 2,
      disp(sprintf('** Algoritmo Gen閠ico Padr鉶 - GA **'));
      figure(1); clf;
      [x,y,fx,vx,vmfit,P] = ga3d(v);
      disp(sprintf('M醲imo encontrado [x,y,f(x,y)]: [%.2f,%.2f,%.2f]',x,y,fx));
      figure(2); plot(vx); title('f(x,y) x M閐ia'); xlabel('gera珲es'); ylabel('f(x)');
      hold on; plot(vmfit,'r'); hold off;
   case 3,
      disp(sprintf('** Algoritmo de Sele玢o Clonal - 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('M醲imo encontrado [x,y,f(x,y)]: [%.2f,%.2f,%.2f]',x,y,fx));
      figure(4); clf; plot(vfx); title('f(x,y) x M閐ia'); xlabel('Gera珲es'); ylabel('f(x)');
      hold on; plot(vmfit,'r'); hold off;
   otherwise,
      disp('Os valores aceitos s鉶 (1), (2) ou (3)');
   end; % End Switch ga_cga
case 3,
   disp(sprintf('\n** PARTE III - ABNET (AntiBody NETwork) **'));
   L = 10; aux1 = ones(1,L); aux2 = zeros(1,L);
   ag = [aux1;[0,aux1(2:end)];[0,0,aux1(3:end)];[aux1(1:end-1),0];[aux1(1:end-2),0,0];...
         aux2;[1,aux2(2:end)];[1,1,aux2(3:end)];[aux2(1:end-1),1];[aux2(1:end-2),1,1]];
   disp(sprintf('\nAnt韌enos (colunas) a Serem Reconhecidos: [%d,%d]',size(ag,1),L)); 
   disp(ag'); ag = ag - 0.1; ag = hardlims(ag);
   eps = input('Escolha o Limiar de Afinidade [0,L]: ');
   [w,win,cwin,D] = abnet(ag,eps);
   figure(2); clf; draw_abnet(w);
case 4,
   disp(sprintf('\n** PARTE IV - aiNet (Artificial Immune NETwork) **'));
   disp(sprintf('Demos dispon韛eis:'));
   disp(sprintf('1) CLASSES LINERAMENTE SEPAR罺EIS'));
   disp(sprintf('2) 2-SPIRAIS'));
   disp(sprintf('3) CHAINLINK'));
   disp(sprintf('4) DEFINI敲O DE CENTROS DE RBF - R

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -