Very good example of genetic algorithm __ algorithm

Source: Internet
Author: User
Tags manual example of manual

An example of manual simulation calculation of genetic algorithms

To better understand the genetic algorithm of the operation process, the following manual calculation to simply simulate the genetic algorithm of the various
The main steps of execution.

Example: To find the maximum value of the following two-tuple function:

(1) Individual code
The operator of the genetic algorithm is a symbolic string representing the individual, so the variable x1 must be encoded as a x2
Symbol String. In the subject, it is represented by an unsigned binary integer.
Because of X1, X2 is an integer between 0 and 7, so it is represented by a 3-bit unsigned binary integer, which
The 6-bit unsigned binary numbers that are connected together form the individual genotype, which represents a
Line solution.
For example, the phenotype of genotype x=101110 is: x=[5,6].
Individual phenotype x and genotype x can be converted to each other by encoding and decoding programs.

(2) Initial population generation
          genetic algorithm is the evolutionary operation of the population, it is necessary to prepare some initial
for the starting search point.       Group data.
         In this case, the size of the population is 4, that is, the group consists of 4 individuals, each individual can be randomly
      Method Generation.
          such as: 011101,101011,011100,111001
          
  (3) Fitness juice calculation
         In   genetic algorithm, the size of individual adaptability is used to evaluate the degree of each individual, thus determining the size of genetic
       opportunity.
          In this example, the target function takes a non-negative value and is intended for the maximum function to be optimized, so it can be directly
        uses the value of the objective function as the fitness of the individual.

  (4)   Select operation
          Select operation (or copy operation) The individuals with higher degree of adaptability in the current population are genetically inherited into the next generation group according to some rules or models. Generally, individuals with higher fitness levels will have more opportunities to inherit from the next generation of
      groups.                     
In this example, we use a probability proportional to the degree of fitness to determine the number of individual individuals replicating to the next generation of groups
    . The procedure is as follows:
        ·  calculates the sum of the fitness of all individuals in a group  fi  (i=1.2,..., M);
        ·  Next calculates the relative fitness size of each individual fi/fi, which is inherited for each individual
   Probability of            to the next generation of groups,
         ·  each probability value constitutes an area, and the sum of all probability values is 1;
        ·  The result is a random number from 0 to 1, which appears in the probability area above according to the random number
             field to determine the number of times each individual is selected.

Roulette: Is the accumulation of probability to achieve, usually a large degree of adaptability to the choice of higher probability.

If: Fit for the appropriate degree group, a total of M
For I=1 to M ' Sum first
Sum=sum+fit (i)
Next I
For i = 1 to n ' n is the number of individuals to be generated
Temp = temp + fit (i)
If Rnd <= Temp/sum Then
Output I is the result
Exit Function
End If
Next I
There are two issues that need to be addressed:
1. In the case of a small difference in fitness, and random selection of a no difference, not conducive to the control of evolutionary speed and direction
2. This stuff, there is a choice to put back, in some engineering applications, sometimes there is no choice to put back
Another: such as the control of children without duplication, etc., also need to be considered. In fact, understand the truth, their own design a targeted operator more practical significance, do not be afraid of trouble.

(5) Crossover operation
The crossover operation is the main process of generating a new individual in a genetic algorithm, which exchanges a certain probability with one another.
A partial chromosome between two individuals.
This example uses a single-point crossover method, the specific operation process is:
• Random pairing of groups first;
• Next, randomly set the intersection point position;
• Finally, they are exchanged with each other to match some genes between chromosomes.

(6) Mutation operation
Mutation is the genetic value of one or some of the genes in an individual, in a smaller probability.
Change, it is also a way to create a new individual.
In this example, we use the basic bit mutation method to do the mutation operation, the specific operation process is:
• First determine the location of each individual's genetic mutation, as shown in the table below, the randomly generated mutation point location,
The numbers indicate that the mutation point is set at the gene Block;
• The original genetic value of the mutation point is then reversed according to a probability.

A new generation of group P (t+1) can be obtained after a round of selection, crossover and mutation operation on group P (t).

As can be seen from the above table, after a generation of evolution of the population, the maximum fitness, the average value will be
To a noticeable improvement. In fact, the best individual "111111" has been found here.
Note
It is necessary to note that some of the columns in the table data are randomly generated. Here in order to better illustrate the problem,
We have deliberately chosen some good values to get better results, and in the actual operation process
It is possible to have a certain number of cycles to achieve this optimal result.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.