Algorithm Series-"Genetic algorithm"

Source: Internet
Author: User

Genetic algorithm, the Internet a lot of information, but always said in the cloud to the fog, originally very simple algorithm, the original study time also got a long way to get started. Recently the company implemented KPI, each month need to post an article, a long time ago want to write a write algorithm class article, just happen to have this opportunity, write a series, first take genetic algorithm to the axe.

"Story background": God Made man, demanding to be as perfect as possible.

"Gene coding": assume that each person is a binary "byte", that is, 10101010 such a string, 0 for the disadvantage, 1 for the advantage, that is, "bytes" in every bit as a gene. That is, a person's genes are 10101010 such a string, a perfect person is expressed as: 11111111.

"Initial population": God made Adam (10101010) and Eve (01010101)

"Population size": Determine the size of the population, in order to facilitate the calculation, the population size is determined to 4, that is, four descendants of Adam as the species, respectively, ABCD.

a:10111000, b:00011001, c:10110111, d:00111111

"Fitness calculation": The more advantages of the individual, the higher the evaluation, (digression, such as the first 1 for money, the second 1 for handsome, they are basically the sum of all the above advantages, haha haha). According to the degree of fitness, the values of ABCD four individuals correspond:

a:10111000,184

b:00011001,25

c:10110111,183

d:00111111,63

"Survival of the fittest": the more advantages, the more you can reproduce the opportunity to select the probability of reproduction, to the population of all the advantages of the sum of the values of A,b,c,d sum is: 455. The probability that each individual is selected is

a:184/455=40.43%.

b:25/445=5.49%.

c:183/455=40.21%.

d:63/455=13.84%.

Then God began to roll the dice (producing a random number from 0 to 1, based on the random number, to choose the probability). The probability problem exists in this, the greater the advantage, the more the probability is chosen, not necessarily, there are great advantages, but not the individual selected. It is assumed that the individual selected by probability is: AACD, B is eliminated by society, and a with strong genes, the opportunity to reproduce two times.

"Gene Exchange" is the main process of producing new individuals, which exchange some two individual chromosomes with a certain probability, and the location of the intersection points is randomly determined. The group was randomly paired, followed by randomly setting the intersection location, and then exchanging the genes between the chromosomes to obtain new results as individuals.

AC:

10111* 000

10110 *111

The fifth digit (random) of the left is the exchange point, that is, the newly bred individuals are: 10111* 111, 10110 *000

AD:

101*10111

001*11111

The third digit (random) of the left number is the exchange point, that is, the new individuals are: 101*11111, 001*10111

"Individual mutation": a mutation is a change in the value of a gene on one or some of the individual loci by a smaller probability.

Reproduce the four individuals, re-number as ABCD. a:10111111, b:10110000, c:10111111, d:00110111. Four individuals, randomly find a bit to mutate, that is, take the post-operation.

Assuming that the random operation determines

A: Third place to take anti-10111111->10011111,

B: Second place to take anti-10110000->11110000,

C: The seventh place to take the anti-10111111->10111101,

D: The first place to take the anti-00110111->10110111

"Fitness evaluation" through the first iteration, the resulting new individuals are:

a:10011111,159

b:11110000,240

c:10111101,189

d:10110111,183

As can be seen from the population of ABCD four individuals, among them, the generation of new groups, the degree of fitness evaluation is higher than the previous generation, this algorithm in order to find eligible individuals, the final choice.

"Cycle": the new individuals, to the size set by the population, from the "Fitness calculation", "survival of the Fittest", "Gene exchange", "individual variation", "fitness evaluation" The key steps to repeat the cycle, looking for the perfect condition, if there is, to complete the task, If not, the next iteration is made.

"Summary": Genetic algorithm is a few points:

1. The encoding of the gene, that is, how to solve the problem into the form of a gene sequence, is not necessarily the 10101010 such a string used in this article

2. Fitness evaluation, that is, how to evaluate whether the individual meets the optimal individual, how to measure the specific value

3. In gene exchange, how to ensure that the exchange of individuals, but also belong to the solution of the problem.

4. Determine the size of the population and the number of iterations and determine the optimal conditions.

Algorithm Series-"Genetic algorithm"

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.