Word caused me to rewrite =_= and rearrange my thoughts.
Background: The use of genetic algorithms in writing papers has taken nearly a week to understand the algorithm and the ability to implement the underlying programming (to remain humble).
Description: The specific implementation did not dare to say, the main principle is the introduction of the method (not on the explanation).
First of all, the algorithm to learn , the personal feel that the first need to understand the algorithm is to do what, and then learn its theoretical principles, more to understand a few times is always good, the actual example, and then the algorithm of each together to study clearly, the whole understanding, and try to implement the program, so learn to feel good.
On the principle of genetic algorithm: simulating the evolutionary phenomenon of the natural fittest, the search space (the constituent space of the problem solution) is mapped to the genetic space, the possible solution is encoded into a vector-chromosome, each element of the vector is called the gene. By constantly calculating the adaptive values of each chromosome, the best chromosome is selected and the optimal solution is obtained.
Simply put, is to give you a bunch of people (and population), let you choose a part of the gene fine (the solution of higher fitness, such as greater value) of the people come out, let them have children to form offspring (choose crossover and mutation), these descendants and previously selected parents, then compare the gene fine, then choose, then inherit, so cycle, Finally find a super Hero (the best solution) to achieve the goal.
This is similar to a non-purposeful search for the best, but the genetic algorithm is more efficient.
On the principle, there are some popular interesting articles to look at: https://www.zhihu.com/question/23293449
About the algorithm steps: from the principle can also be summed up, the main steps include, fitness function design, coding, selection, crossover, mutation.
That is to say, we can mainly use code to achieve these operations, an algorithm can be basically implemented. This is also an object-oriented programming . Give a flowchart:
The picture is a little big
This flowchart after reading the whole text in return to see again. (insisted, read d=== ( ̄▽ ̄*) b)
About algorithmic terminology (lazy):
Source of an unknown source courseware, the university resources are many
Starting from the individual, I am always willing to understand the individual and the chromosomes together, because the chromosome is the individual after the code, the two are essentially the same, just behave differently. An individual is a solution to an algorithm, such as a function within a certain interval, with countless solutions. And chromosomes, is to allow the algorithm to better understand and manipulate our individual, the results of the coding. The code here is a conversion operation.
To raise a chestnut, for the maximum of a function interval, I will a solution with a value of 13, according to the 6-bit long binary code, converted to: 001101, here 13 is an individual, 001101 is the chromosome, 0 and 1 is the gene. In this way, the algorithm operates these binary sets much more easily than real numbers.
Then, a whole bunch of individuals, what we need to do is pick out the good individuals (chromosomes) from the population, cross-mutate, generate the next generation, and form a new population.
The criterion for evaluating an individual's suitability is the fitness function, such as finding the value of the Extremum function which is larger or smaller. The fitness function gives each individual a value, and then, based on the valuation, we elect a portion-such as the 20%--of the population number as the good parent, by crossing the mutation, allowing them to produce offspring, forming a new population, and then calculating the fitness and circulation.
Crossover and mutation are genetic manipulations. Crossover is the exchange of genes in chromosomes, for example. The father's fine genes are combined with the mother's fine genes to produce the next generation,
We cross the left two chromosomes and produce the new two chromosomes on the right. This time with the code is very good understanding, each chromosome is a binary string,
This crossover is easier to achieve than a real number.
The mutation, then, is the genetic variation within the chromosome, such as altering a gene in a binary string to produce a mutation.
001101?011101, the second gene variant, produced a new chromosome (solution), that is, 13 produced 29.
Understanding the terminology and steps, the next step is implementation . Concrete implementation, I combine the internet to find a very practical example, the source should be "Genetic algorithm toolbox" this kind of books.
Environment: MATLAB and Genetic Algorithm toolkit.
First of all, the Toolbox, which is a toolbox compiled by foreign gods, contains functions that correspond to the various operations of the genetic algorithm. These functions are also important because the genetic algorithm (or most of the algorithms) is chunked, and each block is an operation, and each operation is expressed and carried out in the form of a function.
So the concrete implementation is the function of each operation. The code comes from the Toolbox group book, just the main part:
?
The first 4 behavior algorithm conventions or constraints. Shows that we have 40 individuals (chromosomes) in each of our populations. It will inherit up to 25 generations, and cycle 25 times or generate 25 species. Then the length of the encoding-that is, the length of the chromosome is 20 bits (using the binary encoding). The generation gap is the chosen proportion, that is, each population, we elect 40*0.1=4 an excellent individual.
Next is the design of the loop, in the loop, there is a function: "Calculate the target function value", here is the fitness function. Most of the time, the fitness function is using the original function.
The two-decimal conversion function BS2RV is to allow the encoded individual to recover the real form and to calculate the fitness.
The selection, reorganization, and variation inside are done through a function: Select,recombin,mut. The choice here is to choose a good chromosome to produce the next generation. Recombination is a cross; Variation.
So you see, every operation with a function can be done, but you know, here is a function only corresponds to a mode of operation, two each operation has a lot of patterns, such as coding has binary encoding, real code, etc. Options include wheel selection and tournament selection. Cross with a single point of intersection, multi-point intersection and so on. The variation has the basic bit variation, the uniform variation and so on.
Of course , each pattern, or method has a corresponding principle and function , this will find learning by itself.
So it seems that the genetic algorithm is not so difficult to figure out each operation, find or write the corresponding function, and then call it.
However, this is only a basic genetic operation, now more concerned about the improvement and optimization of genetic algorithms, and these improvements and optimizations are aimed at the above operating mode of the shortcomings of the optimization, but also fun.
Probably here, finally recommend a book, Reinge, teacher and Zhang Shanwen teacher Editor "matlab Genetic algorithm Toolbox and application", really practical, practical operation also has, optimization also has.
Genetic algorithm Summary (#看了就能懂和用系列 #)