Turn strongly recommended genetic Algorithm primer example

Source: Internet
Author: User

The manual simulation of genetic algorithm is an example to better understand the genetic algorithm of the operation process, the following manual calculation to simply simulate the genetic algorithm of the main implementation steps.

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

(1) Individual code

The arithmetic object of the genetic algorithm is the symbol string of the individual, so the variable x1 must be encoded as a symbol string x2. In the subject, it is represented by an unsigned binary integer. Because of X1, X2 is an integer between 0 and 7, so 3-bit unsigned binary integers are used to represent them, and the 6-bit unsigned binary numbers that are concatenated together form the individual genotype, representing a viable 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) generation of initial groups

Genetic algorithm is a kind of evolutionary operation to the population, it needs to be prepared some initial group data representing the starting search point. In this case, the size of the population is 4, that is, the group consists of 4 individuals, each of which can be produced by a random method.

such as: 011101,101011,011100,111001

(3) Fitness juice calculation

   in the genetic algorithm, the size of individual adaptability is used to evaluate the degree of each individual, thus determining the size of its genetic opportunity. In this case, the objective function takes a non-negative value and is the optimal target for the maximum function, so it can use the target function value as the individual's adaptability directly.

(4) Select operation

The selection operation (or the replication operation) of the current population in the high degree of adaptability to a certain rule or model to the next generation of population. 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. Its specific operation is:

• The sum of the fitness of all individuals in the population is calculated first ∑fi (i=1.2,..., M);

• Second, calculate the relative fitness size of each individual fi/∑fi, which is the probability that each individual is inherited to the next generation,

• Each probability value consists of a region, and the sum of all probability values is 1;

• Finally, a random number between 0 and 1 is generated, which determines the number of times each individual is selected, depending on which probability region the random number appears in.

(5) Crossover operation

Cross-operation is the main process of generating new individuals in genetic algorithms, which exchange some two individual chromosomes with a certain probability. 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 operation is to change the genetic value of one or some loci of an individual by a smaller probability, and it is also an operation method to produce 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, the following table shows the location of the randomly generated mutation point, where the number indicates 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, the maximum degree of fitness, the average value has been significantly improved. 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 deliberately selected some good values to get better results, and in the actual operation process may require a certain number of cycles in order to achieve this optimal result.

Turn strongly recommended genetic Algorithm primer example

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.