A good understanding of the genetic algorithm example

Source: Internet
Author: User

Demonstration sample of manual simulation calculation of genetic algorithm

To better understand the computational process of genetic algorithms, the following manual calculations are used to simply simulate the genetic algorithm
Major operational steps.

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
       symbol string x2. In the subject, it is represented by an unsigned binary integer.
           because 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 number that the        joins together forms the individual genotype, which represents a
        Line solution.
           For example, genotype x=101110 the corresponding phenotype is: x=[5,6]. The
           individual's 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 group, which needs to be prepared for the initial 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 is generated.
such as: 011101,101011,011100,111001

(3) Fitness juice calculation
In the genetic algorithm, the degree of individual adaptability is evaluated to determine the individual's merits and demerits, and the genetic
The size of the opportunity.
In this case, the objective function takes a non-negative value, and it is to maximize the function to optimize the target, so it can directly
The target function value is used as the adaptability of the individual.

(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 a higher degree of adaptability will have many other opportunities to inherit from the next generation.
Group.
In this example, we use probabilities proportional to fitness to determine individual copies to the next generation of groups
The quantity. The detailed procedures are:
• First calculate the sum of the fitness of all individuals in a group? Fi (i=1.2,..., M);
• Second, calculate the relative fitness size of each individual fi/fi, which is inherited for each individual person
To the next generation of population,
• Each probability value consists of an area, and the sum of all probability values is 1;
• Finally generate a random number from 0 to 1, according to the random number of which probability area is now
field to determine the number of times each individual is selected.

(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 detailed 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 perform the mutation operation, the detailed operation process is:
• First determine the location of each individual's genetic mutation, as seen in the table below, randomly generated mutation point location,
The numbers indicate that the mutation point is set at the gene Block;
• Then reverse the original genetic value of the mutation point 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 so that we can get better results, and in the actual operation process
It is possible that a certain number of cycles will be required to achieve this optimal result.

A good understanding of the genetic algorithm 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.