A list,

1. Immune Algorithm

1.1 Basic steps of immune algorithm:

(1) Antigen recognition. Input objective functions and various constraints as antigens for the immune algorithm.

(2) Initial antibody generation. Random generation of initial antibody population.

(3) Affinity calculation. Calculate the fitness of antibodies. Comprehensive evaluation of each solution individual in the solution population, including the fitness (affinity) of the solution (antibody) and the problem (antigen) and the similarity between solutions (affinity)

(4) Immune treatment. Immune treatment includes immune selection, cloning, mutation and suppression.

(5) Immune selection: select antibodies with high affinity according to their affinity.

(6) Cloning: to replicate the selected antibody with high affinity.

(7) variation: to clone the individual crossover, variation operation, so that its affinity changes.

(8) Inhibition: Select mutated antibodies and retain those with higher affinity.

(9) Group refresh. The immunoselected antibodies and immunosuppressed antibodies are formed into a set, and the antibodies with higher affinity are retained to make these antibodies enter a new population. New populations of deficient parts are randomly generated to increase diversity.

The difference between immune algorithm and genetic algorithm



Immune algorithm is a multi-peak search algorithm designed to simulate the immune system’s ability to recognize the diversity of bacteria (that is, the immune system can recognize almost infinite kinds of bacteria), and its specific steps are as follows



Ii. Source code

Clear all CLC TIC POPsize =15;
lanti=10;
maxgen=50; % Maximum algebra cross_rate=0.4; % Cross rate mutation_rate=0.1; % variation rate a0=0.7;
zpopsize=5;
bestf=0;
nf=0;
number=0;
I=imread('bird.bmp'); q=isrgb(I); % Determine whether it is RGB true color imageif q==1I=rgb2gray(I); End [m,n]=size(I); p=imhist(I); % Display image data histogram p=p'; % array changes from column to row p=p/(m*n); % transforms the value of p to (0.1) figure (1)
subplot(1.2.1);
imshow(I);
title('Grayscale image of the original image'); Hold on %%% antibody population initialization %%%%%%%%%%% pop=2*rand(popsize,lanti)- 1; % pop for10*8A value of (- 1.1) between random number matrix pop=hardlim(pop); % greater than or equal to0for1That is less than0for0%%%%%% immunization operation %%%%%%%%%%%%%%%%%%for gen=1:maxgen [fitness,yuzhi,number]=fitnessty(pop,lanti,I,popsize,m,n,number); %% The antibody-antigen affinity was calculatedif max(fitness)>bestf
    bestf=max(fitness);
    nf=0;
  for i=1:popsize
        if fitness(1, I)==bestf % Find the serial number v= I of the maximum fitness in vector fitness; end end yu=yuzhi(1,v);
  elseif max(fitness)==bestf
    nf=nf+1;
  end
    if nf>=20
     break; end A=shontt(pop); % Calculate the antibody -- antibody similarity f=fit(A,fitness); Pop =select(POP,f); Pop =coss(pop,cross_rate,popsize,lanti); Cross pop % = mutation_compute (pop, mutation_rate lanti, popsize); A = % variation shonqt (pop); % To calculate the similarity of antibody populationif a>a0
    zpop=2*rand(zpopsize,lanti)- 1; zpop=hardlim(zpop); Random generation of zPOPsize new antibody POP (POPsize +1:popsize+zpopsize,:)=zpop(:,:); [fitness,yuzhi,number]=fitnessty(pop,lanti,I,popsize,m,n,number); A= SHonTT (POP); % Calculate the antibody -- antibody similarity f=fit(A,fitness); Pop =select(POP,f); % % to choose operation end fitness calculation function [fitness, b, number] = fitnessty (pop, lanti, I, popsize, m, n, number) num = m * n;for i=1:popsize
     number=number+1;
        anti=pop(i,:);            
        lowsum=0; % Sum of gray values lower than the threshold lownum=0; % Number of pixels below threshold highsum=0; % Sum of gray values higher than the threshold highnum=0; % Number of pixels above the threshold a=0;                 
        for j=1:lanti
            a=a+anti(1,j)*(2^(j- 1)); % weighted sumend
        b(1,i)=a*255/ (2^lanti- 1);     
        for x=1:m
            for y=1:n
                if I(x,y)<b(1,i)
                    lowsum=lowsum+double(I(x,y));
                    lownum=lownum+1;
                else  
                    highsum=highsum+double(I(x,y));
                    highnum=highnum+1;
                end
            end
        end
        u=(lowsum+highsum)/num;
        if lownum~=0
            u0=lowsum/lownum;
        else 
            u0=0;
        end
        if highnum~=0
            u1=highsum/highnum;
        else 
            u1=0;
        end
        w0=lownum/(num);
        w1=highnum/(num);
        fitness(1,i)=w0*(u0-u)^2+w1*(u1-u)^2;   
 end
 
Copy the code

3. Operation results

Fourth, note

Version: 2014 a