Evolutionary Computation. Lecture 3. Evolutionary Computation. X 2 example: crossover. x 2 example: selection

Size: px
Start display at page:

Download "Evolutionary Computation. Lecture 3. Evolutionary Computation. X 2 example: crossover. x 2 example: selection"

Transcription

1 Evolutionary Computation Lecture 3 Evolutionary Computation CIS 412 Artificial Intelligence Umass, Dartmouth Stochastic search (or problem solving) techniques that mimic the metaphor of natural biological evolution. Metaphor of Natural Selection Offspring are similar to their parents The more fit are more likely to have children Occasionally random mutations occur EVOLUTION Individual Fitness Environment PROBLEM SOLVING Candidate Solution Quality Problem Problem Solving with GA An example after Goldberg 89 (1) Simple problem: max x 2 over {0,1,,31} GA approach: Representation: binary code, e.g Population size: 4 1-point xover, bitwise mutation Roulette wheel selection Random initialisation We show one generational cycle done by hand x 2 example: selection X 2 example: crossover 1

2 X 2 example: mutation Operators for Genetic Algorithms Initial Strings Crossover Mask Offspring Single-point cross ov er: Two-point crossover: Uniform crossover: Point mutation: Alternative Crossover Operators n-point crossover Performance with 1 Point Crossover depends on the order that variables occur in the representation more likely to keep together genes that are near each other Can never keep together genes from opposite ends of string This is known as Positional Bias Can be exploited if we know about the structure of our problem, but this is not usually the case Choose n random crossover points Split along those points Glue parts, alternating between parents Generalisation of 1 point (still some positional bias) Uniform crossover Crossover OR mutation? Assign 'heads' to one parent, 'tails' to the other Flip a coin for each gene of the first child Make an inverse copy of the gene for the second child Inheritance is independent of position Decade long debate: which one is better / necessary / main-background Answer (at least, rather wide agreement): it depends on the problem, but in general, it is good to have both both have another role mutation-only-ea is possible, xover-only-ea would not work 2

3 Crossover OR mutation? (cont d) Exploration: Discovering promising areas in the search space, i.e. gaining information on the problem Exploitation: Optimising within a promising area, i.e. using information There is co-operation AND competition between them Crossover is explorative, it makes a big jump to an area somewhere in between two (parent) areas Mutation is exploitative, it creates random small diversions, thereby staying near (in the area of ) the parent Crossover OR mutation? (cont d) Only crossover can combine information from two parents Only mutation can introduce new information (alleles) 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) To hit the optimum you often need a lucky mutation Other representations Integer representations Gray coding of integers (still binary chromosomes) 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 Integers Floating point variables Some problems naturally have integer variables, e.g. image processing parameters Others take categorical values from a fixed set e.g. {blue, green, yellow, pink} N-point / uniform crossover operators work Extend bit-flipping mutation to make 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 Selection Techniques Selection Techniques Proportional Fitness Selection: each individual is selected proportionally to their evaluation score even the worst individual has a chance to survive this helps prevent stagnation in the population Two approaches: rank selection: individual selected with a probability proportional to its rank in population sorted by fitness proportional selection: individual selected with a probability Fitness(individual) / sum Fitness for all individuals Proportional selection example: Given the following population and fitness: Sum the Fitness = 50 Determine probabilities Fitness(i) / 50 Individual A B C D E Fitness Prob. 10% 40% 22% 16% 12% 3

4 Selection Techniques Selection Techniques Tournament Selection: randomly select two individuals and the one with the highest rank goes on and reproduces cares only about the one with the higher rank, not the spread between the two fitness scores can be generalized to select best of n individuals Crowding: a potential problem associated with the selection occurs when the individuals that are most fit quickly reproduce so that a large percentage of the entire population looks very similar reduces diversity in the population may hinder the long-run progress of the algorithm Alteration: Producing new Individuals Alteration: Producing new Individuals 1-point crossover: pick a dividing point in the parents' vectors and swap the segments For Example given parents: and crossover point: after the 4th digit children produced are: and N-point crossover: generalization of 1-point crossover pick n dividing points in the parents' vectors and splice together alternating segments Uniform crossover: the value of each element of the vector is randomly chosen from the values in the corresponding elements of the two parents Genetic Algorithms (GA) as Search Geometric Analogy - Mathematical Landscape The problem of local maxima: individuals stuck at a pretty good but not optimal any small mutation gives worse fitness crossover can help them get out of a local maximum mutation is a random process, so it is possible that we may have a sudden large mutation to get these individuals out of this situation 4

5 Eight-Queen Problem How to represent the state of the board? What is the fitness function? How to perform selection? How to apply crossover and mutation? Traveling SalesPerson Problem How to represent TSP? Representations Binary bits: each city is represented as a 4-bit pattern: 0001, 0010,., 1001 Potential problem in crossover and mutation Give each city a numeric name: 1,2,,9 A path ( ) Mutation? Crossover? Order Crossover Mutation Randomly select cut points, and use them for both parents: P1=( ) P2=( ) The segment between the cut points is copied to the offspring: C1=(xxx 4657 xx) C2=(xxx 1876 xx) Start from the second cut points, the cities from the other parents are copied in the same order, omitted cities already exist. P2 =( ) C1=( ) P1 =( ) C2=( ) Select one piece within the path and invert it c1 =( ) ->( ) Randomly select a city from the path and insert it into a random place c1 =( ) ->( ) Take a subpath of three cities and put them in a new location. c1 =( ) ->( ) demo of TSP with 29 cities Online-demo 5

6 Genetic Algorithm 6