Classic example of genetic algorithm

The following is a simple simulation of
the .
  
     Example: Find the maximum value of the following binary function:

 (1) The operation object of the individual coding
           genetic algorithm is the symbol string representing the individual, so the variables x1 and x2 must be encoded as a
       symbol string. In this problem, it is represented by an unsigned binary integer.
           Since x1 and x2 are integers between 0 and 7, they are represented by 3-bit unsigned binary integers respectively,
       and the 6-bit unsigned binary number formed by connecting them together forms the genotype of an individual, representing a feasible
       solution.
           For example, the phenotype corresponding to genotype X=101110 is: x=[5,6].
           An individual's phenotype x and genotype X can be converted to each other through encoding and decoding programs.

(2) Generation of the initial population
          Genetic algorithm is an evolutionary operation on the population, which needs to be prepared with some initial
      population data representing the initial search point.
         In this example, the size of the group size is taken as 4, that is, the group consists of 4 individuals, and each individual can be
     generated by a random method.
          Such as: 011101, 101011, 011100, 111001
         
 (3) Fitness juice calculation
          In the genetic algorithm, the individual fitness is used to evaluate the pros and cons of each individual, thereby determining
       the size of its genetic chance.
          In this example, the objective function always takes a non-negative value, and the optimization objective is to find the maximum value of the function, so
       the objective function value can be directly used as the fitness of the individual.

 (4) Selection operation
          Selection operation (or duplication operation) inherits individuals with higher fitness in the current population to the next generation population according to certain rules or models. It is generally required that individuals with higher fitness will have more chances to inherit it into the next generation
      .                   
In this example, we use a probability proportional to fitness to determine the number of copies of each individual into the next generation of
     the population. The specific operation process is:
         • First calculate the sum of the fitness of all individuals in the group fi ( i=1.2,…,M );
         • Second, calculate the relative fitness of each individual fi / fi, which is That is, the probability of each individual being inherited
             into the next generation group,
         • Each probability value forms an area, and the sum of all probability values ​​is 1;
         • Finally, a random number between 0 and 1 is generated, according to the random number Which of the above probability
             regions determines the number of times each individual is selected.

(5) Crossover operation
        Crossover operation is the main operation process of generating new individuals in the genetic algorithm. It exchanges
    some chromosomes between two individuals with a certain probability.
       In this example, the method of single-point crossover is adopted, and the specific operation process is as follows:
       • First, perform random pairing on the population;
       • Second, randomly set the position of the crossover point;
       • Finally, exchange some genes between the paired chromosomes.

(6) Mutation operation
         Mutation operation is
     to , and it is also an operation method to generate a new individual.
        In this example, we use the method of basic bit mutation to perform mutation operation. The specific operation process is as follows:
        • First, determine the genetic mutation position of each individual. The following table shows the randomly generated mutation point positions,
          where the numbers represent the mutation. The point is set at the locus;
        • The original gene value of the mutation point is then inverted according to a certain probability.

A new generation of population p(t+1) can be obtained after a round of selection, crossover and mutation operations on the population P(t).

It can be seen from the above table that after the evolution of the population for one generation, the maximum value and average value of its fitness have
    been significantly improved. In fact, the best individual "111111" has been found here.       
[Note]      
      It should be noted that the data in some columns in the table are randomly generated. In order to better illustrate the problem,
 we deliberately choose some better values ​​to get better results, and in the actual operation process,
 it may take a certain number of cycles to achieve this optimal result.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326485045&siteId=291194637