Crossovers and Mutation Richard P Simpson Genotype vs

  • Slides: 39
Download presentation
Crossovers and Mutation Richard P. Simpson

Crossovers and Mutation Richard P. Simpson

Genotype vs. Phenotype The genotype of a chromosome is just the basic data structure

Genotype vs. Phenotype The genotype of a chromosome is just the basic data structure (it bits in a binary chromosome) The Phenotype is the object that the chromosome represents. For example the bit pattern 1011011101 could be used to represent a particular polygon such as The polygon is the phenotype and the binary pattern is the genotype. (think in terms of yourself).

Crossover and Mutations 1011011101 mutate 10101011011

Crossover and Mutations 1011011101 mutate 10101011011

1 Point Binary Crossover n Choose a random point on the two parents n

1 Point Binary Crossover n Choose a random point on the two parents n Split parents at this crossover point n Create children by exchanging tails n Pc typically in range (0. 6, 0. 9)

Performance with 1 point binary crossover n more likely to keep together genes that

Performance with 1 point binary crossover n more likely to keep together genes that are near each other n Can never keep together genes from opposite ends of string n This is known as Positional Bias n Can be exploited if we know about the structure of our problem, but this is not usually the case

n-point binary crossover n Choose n random crossover points n Split along those points

n-point binary crossover n Choose n random crossover points n Split along those points n Glue parts, alternating between parents n Generalisation of 1 point (still some positional bias)

Uniform Binary Crossover n Assign 'heads' to one parent, 'tails' to the other n

Uniform Binary Crossover n Assign 'heads' to one parent, 'tails' to the other n Flip a coin for each gene of the first child n Make an inverse copy of the gene for the second child n Inheritance is independent of position

Binary Mutation n Alter each gene independently with a probability pm n pm is

Binary Mutation n Alter each gene independently with a probability pm n pm is called the mutation rate n Typically a small number between 1/pop_size and 1/ chromosome_length.

Crossover OR mutation? n What effect does each of these have on the evolution

Crossover OR mutation? n What effect does each of these have on the evolution process. n See paper Crossover or Mutation by William M. Spears n See Genetic Algorithms: The crossovermutation Debate by Nuwan Senaratna, 2005 n GA operator roles: disruption and construction. n Generally mutation causes more disruption and crossover causes more construction.

Disruption vs. Construction on a landscape Disruption (exploration) is individual Construction (exploitation) climbs the

Disruption vs. Construction on a landscape Disruption (exploration) is individual Construction (exploitation) climbs the hills! Of course what actually happens depends on the problem and its method of chromosome coding. IE Use both.

Crossover or Mutation n Only crossover can combine information from two parents n Only

Crossover or Mutation n Only crossover can combine information from two parents n Only mutation can introduce new information (alleles) n Crossover does not change the allele frequencies of the population (thought experiment: 50% 0’s on first bit in the population, ? % after performing n crossovers) n To hit the optimum you often need a ‘lucky’ mutation

Representations other than binary n Gray coding of integers (still binary chromosomes) n Gray

Representations other than binary n Gray coding of integers (still binary chromosomes) n Gray coding is a mapping that means that small changes in the genotype cause small changes in the phenotype (unlike binary coding). “Smoother” genotype-phenotype mapping makes life easier for the GA Nowadays it is generally accepted that it is better to encode numerical variables directly as n Integers n Floating point variables

Gray Codes n When you count up or down in binary, the number of

Gray Codes n When you count up or down in binary, the number of bit that change with each digit change varies. From 0 to 1 just have a single but n From 1 to 2 have 2 bits, a 1 to 0 transition and a 0 to 1 transition n From 7 to 8 have 3 bits changing back to 0 and 1 bit changing to a 1 n n For some applications multiple bit changes cause significant problems.

Gray Code n Contrast of bit changes n n n n n Val 0

Gray Code n Contrast of bit changes n n n n n Val 0 1 2 3 4 5 6 7 0 Bin 000 001 010 011 100 101 110 111 000 Chg 1 2 1 3 Gray 000 001 010 111 100 000 Chg 1 1 1 1

Integer representations n Some problems naturally have integer variables, e. g. image processing parameters

Integer representations n Some problems naturally have integer variables, e. g. image processing parameters n Others take categorical values from a fixed set e. g. {blue, green, yellow, pink} n N-point / uniform crossover operators work n Extend bit-flipping mutation to make n n n “creep” i. e. more likely to move to similar value Random choice (esp. categorical variables) For ordinal problems, it is hard to know correct range for creep, so often use two mutation operators in tandem

Integer example n There is a well known class of math problems called Diophantine

Integer example n There is a well known class of math problems called Diophantine equations. These are multivariate equations where the solutions are require to be integer. For example n Assume we want three integers x, y, z such that 0 = 2 x – 3 y 2 – 4 z OR we get as close as we can to zero! In a GA that searches for these guys we have chromosomes that look like X Y Z

0 = 2 x – 3 y 2 – 4 z n Possible Fitness

0 = 2 x – 3 y 2 – 4 z n Possible Fitness function n Fitness(x, y, z)=|2 x – 3 y 2 – 4 z| n Possible Crossover n one point crossover, between variables n Possible Mutator using random deviate d. n pick a random gene X, Y or Z and change it with low probability. Maybe vary it slightly n X = X +/- d for some d ? ! n What happens if d is small? Large?

Real Coded Genetic Algorithms n In this type of GA a chromosome is usually

Real Coded Genetic Algorithms n In this type of GA a chromosome is usually an array of floating point values. It is often applied to optimize some real valued function. n Mutations are probabilistically performed on a real value by adding a random deviate in some range from –d to +d. One can select this deviation from a Gaussian (normal) distribution or from a uniform distribution (see rand()).

Normal Distribution about 0 http: //www. cplus. com/reference/random/normal_distribution/

Normal Distribution about 0 http: //www. cplus. com/reference/random/normal_distribution/

De Jong’s classical test functions A lot of test functions can be found here

De Jong’s classical test functions A lot of test functions can be found here http: //www. sfu. ca/~ssurjano/optimization. html

Real Crossovers n There a lot of options here The obvious n point crossovers

Real Crossovers n There a lot of options here The obvious n point crossovers where each allele value in offspring z comes from one of its parents (x, y) with equal probability n Intermediate (a blending scheme) n n exploits idea of creating children “between” parents (hence a. k. a. arithmetic recombination) n n zi = xi + (1 - ) yi where : 0 1. The parameter can be: • constant: uniform arithmetical crossover • variable (e. g. depend on the age of the population) • picked at random every time

Do it for a single gene • Parents: x 1, …, xn and y

Do it for a single gene • Parents: x 1, …, xn and y 1, …, yn • Pick a single gene (k) at random, (or more!) • child 1 is: • reverse for other child. e. g. with = 0. 5

Simple arithmetic crossover • Parents: x 1, …, xn and y 1, …, yn

Simple arithmetic crossover • Parents: x 1, …, xn and y 1, …, yn • Pick random gene (k) after this point mix values. The child 1 is: • reverse for other child. e. g. with = 0. 5 What if =0 ?

Permutations Chromosomes n Ordering/sequencing problems form a special type n Task is (or can

Permutations Chromosomes n Ordering/sequencing problems form a special type n Task is (or can be solved by) arranging some objects in a certain order n n Example: sort algorithm: important thing is which elements occur before others (order) Example: Travelling Salesman Problem (TSP) : important thing is which elements occur next to each other (adjacency) n These problems are generally expressed as a permutation: n if there are n variables then the representation is as a list of n integers, each of which occurs exactly once

Permutations n Mutations n if every chromosome is a permutation of a set, say

Permutations n Mutations n if every chromosome is a permutation of a set, say {1, 2, …, n} then a mutation must generate another mutation. n The mutation operator must be applied to the entire genome.

Two simple mutation schemes n Pick two allele values at random n Move the

Two simple mutation schemes n Pick two allele values at random n Move the second to follow the first, shifting the rest along to accommodate n Note that this preserves most of the order and the adjacency information n Pick two alleles at random and swap their positions n Preserves most of adjacency information (4 links broken), disrupts order more

Inversion and Scramble Mutations n (inversion) Pick two alleles at random and then invert

Inversion and Scramble Mutations n (inversion) Pick two alleles at random and then invert the substring between them. n Preserves most adjacency information (only breaks two links) but disruptive of order information n (scramble) Pick a subset of genes at random n Randomly rearrange the alleles in those positions

Crossover operators for Perms n Partially mapped crossover (PMX) n Order crossover (X) n

Crossover operators for Perms n Partially mapped crossover (PMX) n Order crossover (X) n Uniform order crossover n Edge recombination n There are many other that we will not discuss.

Partially Mapped Crossover n Given two parents s and t, PMX randomly picks two

Partially Mapped Crossover n Given two parents s and t, PMX randomly picks two crossover points. The child is constructed in the following way. Starting with a copy of s, the positions between the crossover points are, one by one, set to the values of t in these positions. This is performs by applying a swap to s. The swap is defined by the corresponding values in s and t within the selected region.

PMX example No change 6 2 3 4 1 7 5 6 2 3

PMX example No change 6 2 3 4 1 7 5 6 2 3 1 4 7 5 6 2 4 1 3 7 5 6 2 4 5 3 1 4 3 1 7 6 5 First offspring 6 2 4 3 1 7 5 For the second offspring just swap the parents and apply the same operation

Order Crossover n This crossover first determines to crossover points. It then copies the

Order Crossover n This crossover first determines to crossover points. It then copies the segment between them from one of the parents into the child. The remaining alleles are copied into the child (l to r) in the order that they occur in the other parents. n Switching the roles of the parents will generate the other child.

Order Crossover Example 1 2 3 4 5 6 7 8 9 4 5

Order Crossover Example 1 2 3 4 5 6 7 8 9 4 5 6 7 3 4 7 2 8 9 1 6 5 The remaining alleles are 1 2 3 8 9. Their order in the other parent is 3 2 8 9 1 3 4 7 2 8 9 1 6 5 3 2 8 4 5 6 7 9 1

Uniform Order Crossover n Here a randomly-generated binary mask is used to define the

Uniform Order Crossover n Here a randomly-generated binary mask is used to define the elements to be taken from that parent. n The only difference between this and order crossover is that these elements in order crossover are contiguous. 1 2 3 4 5 6 7 8 9 1 1 0 0 0 1 2 3 4 7 9 6 8 5 3 4 7 2 8 9 1 6 5 offspring

Edge Recombination n This operator was specially designed for the TSP problem. n This

Edge Recombination n This operator was specially designed for the TSP problem. n This scheme ensures that every edge (link) in the child was shared with one or other of its parents. n This has been shown to be very effective in TSP applications. n Constructs an edge map, which for each site lists the edges available to it from the two parents that involve that city. Mark edges that occur in both with a +.

Inversion Transformations n This scheme will allow normal crossover and mutation to operate as

Inversion Transformations n This scheme will allow normal crossover and mutation to operate as usual. n In order to accomplish this we map the permutation space to a set of contiguous vectors. n Given a permutation of the set {1, 2, 3, …, N} let aj denote the number of integers in the permutation which precede j but are greater than j. The sequence a 1, a 2, a 3, …, an is called the inversion sequence of the permutation. n The inversion sequence of 6 2 3 4 1 7 6 is 4111200 There are 4 integers greater than 1

Inversion of Permutations n The inversion sequence of a permutation is unique! Hence there

Inversion of Permutations n The inversion sequence of a permutation is unique! Hence there is a 1 -1 correspondence between permutations and their inversion sequence. Also the right most inv number is y 0 so dropped. 1 12 123 (0 0) 21 1 132 312 321 231 213 (0 1) (1 1) (2 0) (1 0) 0 0 1 2 x

Inversions Continued n What does a 4 digit permutation map to? 1234 -> (0

Inversions Continued n What does a 4 digit permutation map to? 1234 -> (0 0 0) 2134 -> (1 0 0) 4321 -> (3 2 1) 2413 -> (2 0 1) 1423 -> (0 1 1) etc Maps to a partial 3 D lattice structure

Converting Perm to Inv Input perm: array of permutation Output: inv: array holding inv

Converting Perm to Inv Input perm: array of permutation Output: inv: array holding inv sequence For (i=1; i<=N; i++){ inv[i]=0; m=1; while(perm[m]<>i){ if (perm[m]>i )then inv[i]++; m++; }

Convert inv to Perm Input: inv[] Output: perm[] For(i=1; i<=N; i++){ for(m=i+1; m<=N; m++)

Convert inv to Perm Input: inv[] Output: perm[] For(i=1; i<=N; i++){ for(m=i+1; m<=N; m++) if (pos[m]>=inv[i]+1)pos[m]++; pos[i]=omv[i]+1; } For(i=1; i<=N; i++) perm[i]=i;