Evolutionary strategy (Evolution strategy)

Source: Internet
Author: User
Evolutionary strategy (Evolution strategy)

It is recommended that before understanding ES to ensure that the idea of genetic algorithm has a certain understanding, in the comparison of learning more efficient, paste a previously written genetic algorithm to introduce the same as the genetic algorithm:

are optimized by evolutionary theory, that is, genetic information is used to inherit and mutate the survival of the fittest, thus obtaining the optimal solution. different from the genetic algorithm: 1.DNA sequences are encoded in real numbers, not 0-1 binary codes 2. The mutation can not be a simple 0-1 interchange, think: real value how to change. Random.

Variant idea: Add variation intensity for each real value on the DNA sequence. According to this variation, the actual value of the DNA sequence is determined to be 3. Code:

From the 2nd, it is known that the evolution strategy should not only have a real-coded chain A1 that represents the solution, but also a chain A2 (that is, two kinds of information that is left to the offspring), which is the corresponding variation intensity value of each value . 4. Cross:

Two chain must cross, namely A1 and B1 cross form the C1 chain that represents the descendant solution, A2 and B2 cross to form the C1 chain (parent: A, mother: B, Child: C) The variation of the value of the C2 chain:

The value on the C1 chain is regarded as the mean value μ of normal distribution;
The variation strength value of the C2 chain is regarded as standard deviation σ;
Using a normal distribution to produce a number similar to the selected position on the C1 chain, to replace; variation of values on the 6.C2 chain:

Because with the continuous genetic iteration, the value of the individual number 1th chain in the population is approaching the optimal solution, and the intensity of variation should be reduced continuously. Therefore, we also need to customize the mutation method of chain 2nd according to the requirement. 7. Choose:

The resulting child is added to the parent to form a population of two generations of DNA u;
The 1th chain (presentation solution) for each DNA sequence in the U population is calculated (fitness), and is arranged according to the score from large to small (using U ' to denote the mixed population after arrangement);
Intercept u ' in the high score of the first n bit (n represents the number of individuals in a generation of population) to form a new population; Python Implementation

The above 3-7 points have been regarded as the evolutionary strategy of the algorithm described, the specific code I have not yet knocked out just look at, here is not sticky directly on the source of Mo -1+1-es and Evolution Strategy (es) of the same:

The idea of essential algorithms is the difference between ES and evolutionary strategy (es):

1. (1+1)-es is a special form of ES that considers only one descendant and one parent, not all individuals in the population. Left 1 represents: A parent individual, right 1 represents: a descendant, + represents: In the form of a mixture of the parent and the descendant selection, view the "(1+1)" Detailed explanation

2. From 1, in (1+1)-es, only two individuals (a parent and a child) to the survival of the fittest choice, the better one left, poor elimination

3. Because there is only one parent a so do not need to cross, directly according to the variation of the intensity of mutation to produce children C

4. The information industry that is passed on to future generations is rich in two parts, but not two chains, but rather a chain a and a value a indicates that all values in a correspond to the same defined variation intensity value a

4. The use of fitness to A and C to calculate scores, high scores left, low elimination

5. Define the specific variation intensity of the change rule formula for more details here (I do not understand) Python implementation

The code is simple. I'm just sticking this up. Source:

Import NumPy as NP import Matplotlib.pyplot as Plt dna_size = 1 # DNA (real number) Dna_bound = [0, 5]        # solution upper and lower bounds n_generations = 5.  # Uniform definition of variance intensity def F (x): Return Np.sin (10*x) *x + np.cos (2*x) *x # to find the maximum of this function # find Non-zero Fitness for selection def get_fitness (pred): Return Pred.flatten () def make_kid (parent): # no crossover only mutation k = parent + Mut_strength * NP.RANDOM.RANDN (dna_size) #根据父代基因信息以及变异强度进行变异 k = Np.clip (k, *dna_bound) #控制范围 return k def K Ill_bad (Parent, kid): global mut_strength fp = Get_fitness (f (parent)) [0] #计算得分 FK = Get_fitness (f (Kid)) [0 ] P_target = 1/5 #变异强度的变异规则所定 if fp < fk: # Kid better than parent parent = Ki     D PS = 1.
    # kid Win-> PS = 1 (successful offspring) Else:ps = 0. # adjust global mutation strength Mut_strength *= np.exp (1/NP.SQRT) * (PS-P_target)/(1-p_target)) #变异强度的变异规则 return Parent parent = 5 * Np.random.rand (dna_size) # parent DNA Plt.ion ( # something about plotting x = Np.linspace (*dna_bound) for _ in range (n_generations): # ES Part Kid  = Make_kid (parent) #生孩子 py, KY = f (parent), F (kid) Parent = Kill_bad (parent, kid) #淘汰不好的 #  Something about plotting Plt.cla () plt.scatter (parent, py, s=200, lw=0, c= ' Red ', alpha=0.5,) Plt.scatter (Kid,  KY, s=200, lw=0, c= ' Blue ', alpha=0.5) plt.text (0,-7, ' Mutation strength=%.2f '% mut_strength) plt.plot (x, F (x)); Plt.pause (0.05) Plt.ioff (); Plt.show ()

Reference: Mo-Bug Evolutionary theory series video

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.