RandomExhaustive Search 2 Generate and Test Generate a

  • Slides: 23
Download presentation
Random/Exhaustive Search 2. Generate and Test Generate a candidate solution and test to see

Random/Exhaustive Search 2. Generate and Test Generate a candidate solution and test to see if it solves the problem Repeat l Information used by this algorithm l 1. • Computer Science You know when you have found the solution Genetic Algorithms Slide 1

Hill Climbing 1. 2. 3. l l Generate a candidate solution by modifying the

Hill Climbing 1. 2. 3. l l Generate a candidate solution by modifying the last solution, S If the new solution, N, is “better” than S then S : = N Repeat Local Search Information used by this algorithm • Computer Science Compare two candidate solutions and tell which is better Genetic Algorithms Slide 2

Population of Hill Climbers l Randomly generate initial population of hill climbers (Randomly generate

Population of Hill Climbers l Randomly generate initial population of hill climbers (Randomly generate initial candidate solutions) Do hill climbing in parallel After time t, choose best solution in population l Information used by this algorithm l l • Computer Science Same as hill climbing Genetic Algorithms Slide 3

Genetic Algorithms l l l Population of information exchanging hill climbers Concentrates resources in

Genetic Algorithms l l l Population of information exchanging hill climbers Concentrates resources in promising areas of the search space Information used: • Computer Science Same as hillclimbing Genetic Algorithms Slide 4

Hard problems l Computational complexity, problem size = n • • Computer Science Binary

Hard problems l Computational complexity, problem size = n • • Computer Science Binary Search O(log(n)) Linear Search O(n) Bubble Sort O(n^2) Scheduling NP-complete (at least exponential == O(a^n) Genetic Algorithms Slide 5

Hard problems l Poorly defined Robotics How do we catch a ball, navigate, play

Hard problems l Poorly defined Robotics How do we catch a ball, navigate, play basketball User Interfaces Predict next command, adapt to individual user Medicine Protein structure prediction, Is this tumor benign, design drugs Design bridge, jet engines, Circuits, wings Design Control Computer Science Nonlinear controllers Genetic Algorithms Slide 6

Search as a solution to hard problems l l l Strategy: generate a potential

Search as a solution to hard problems l l l Strategy: generate a potential solution and see if it solves the problem Make use of information available to guide the generation of potential solutions How much information is available? • • • Computer Science Very little: We know the solution when we find it Lots: linear, continuous, … Modicum: Compare two solutions and tell which is “better” Genetic Algorithms Slide 7

Search tradeoff l l l Very little information for search implies we have no

Search tradeoff l l l Very little information for search implies we have no algorithm other than RES. We have to explore the space thoroughly since there is no other information to exploit Lots of information (linear, continuous, …) means that we can exploit this information to arrive directly at a solution, without any exploration Modicum of information (compare two solutions) implies that we need to use this information to tradeoff exploration of the search space versus exploiting the information to concentrate search in promising areas Computer Science Genetic Algorithms Slide 8

Exploration vs Exploitation l More exploration means • • l Better chance of finding

Exploration vs Exploitation l More exploration means • • l Better chance of finding solution (more robust) Takes longer More exploitation means • • Computer Science Less chance of finding solution, better chance of getting stuck in a local optimum Takes less time Genetic Algorithms Slide 9

Choosing a search algorithm l l l The amount of information available about a

Choosing a search algorithm l l l The amount of information available about a problem influences our choice of search algorithm and how we tune this algorithm How does a search algorithm balance exploration of a search space against exploitation of (possibly misleading) information about the search space? What assumptions is the algorithm making? Computer Science Genetic Algorithms Slide 10

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (not converged) do •

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (not converged) do • • l Select pop(T+1) from pop(T) Recombine pop(T+1) Evaluate pop(T+1) T=T+1 Done Computer Science Genetic Algorithms Slide 11

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (not converged) do •

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (not converged) do • • l Select pop(T+1) from pop(T) Recombine pop(T+1) Evaluate pop(T+1) T=T+1 Done Computer Science Genetic Algorithms Slide 12

Generate pop(0) Initialize population with randomly generated strings of 1’s and 0’s for(i =

Generate pop(0) Initialize population with randomly generated strings of 1’s and 0’s for(i = 0 ; i < pop. Size; i++){ for(j = 0; j < chrom. Len; j++){ Pop[i]. chrom[j] = flip(0. 5); } } Computer Science Genetic Algorithms Slide 13

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (not converged) do •

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (not converged) do • • l Select pop(T+1) from pop(T) Recombine pop(T+1) Evaluate pop(T+1) T=T+1 Done Computer Science Genetic Algorithms Slide 14

Evaluate pop(0) Decoded individual Evaluate Fitness Application dependent fitness function Computer Science Genetic Algorithms

Evaluate pop(0) Decoded individual Evaluate Fitness Application dependent fitness function Computer Science Genetic Algorithms Slide 15

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (T < max. Gen)

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (T < max. Gen) do • • l Select pop(T+1) from pop(T) Recombine pop(T+1) Evaluate pop(T+1) T=T+1 Done Computer Science Genetic Algorithms Slide 16

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (T < max. Gen)

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (T < max. Gen) do • • l Select pop(T+1) from pop(T) Recombine pop(T+1) Evaluate pop(T+1) T=T+1 Done Computer Science Genetic Algorithms Slide 17

Selection l l l Each member of the population gets a share of the

Selection l l l Each member of the population gets a share of the pie proportional to fitness relative to other members of the population Spin the roulette wheel pie and pick the individual that the ball lands on Focuses search in promising areas Computer Science Genetic Algorithms Slide 18

Code int roulette(IPTR pop, double sum. Fitness, int popsize) { /* select a single

Code int roulette(IPTR pop, double sum. Fitness, int popsize) { /* select a single individual by roulette wheel selection */ double rand, partsum; int i; partsum = 0. 0; i = 0; rand = f_random() * sum. Fitness; i = -1; do{ i++; partsum += pop[i]. fitness; } while (partsum < rand && i < popsize - 1) ; return i; } Computer Science Genetic Algorithms Slide 19

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (T < max. Gen)

Genetic Algorithm l l Generate pop(0) Evaluate pop(0) T=0 While (T < max. Gen) do • • l Select pop(T+1) from pop(T) Recombine pop(T+1) Evaluate pop(T+1) T=T+1 Done Computer Science Genetic Algorithms Slide 20

Crossover and mutation Mutation Probability = 0. 001 Insurance Xover Probability = 0. 7

Crossover and mutation Mutation Probability = 0. 001 Insurance Xover Probability = 0. 7 Exploration operator Computer Science Genetic Algorithms Slide 21

Crossover code void crossover(POPULATION *p, IPTR p 1, IPTR p 2, IPTR c 1,

Crossover code void crossover(POPULATION *p, IPTR p 1, IPTR p 2, IPTR c 1, IPTR c 2) { /* p 1, p 2, c 1, c 2, m 1, m 2, mc 1, mc 2 */ int *pi 1, *pi 2, *ci 1, *ci 2; int xp, i; pi 1 pi 2 ci 1 ci 2 = = p 1 ->chrom; p 2 ->chrom; c 1 ->chrom; c 2 ->chrom; if(flip(p->p. Cross)){ xp = rnd(0, p->lchrom - 1); for(i = 0; i < xp; i++){ ci 1[i] = mute. X(p, pi 1[i]); ci 2[i] = mute. X(p, pi 2[i]); } for(i = xp; i < p->lchrom; i++){ ci 1[i] = mute. X(p, pi 2[i]); ci 2[i] = mute. X(p, pi 1[i]); } } else { for(i = 0; i < p->lchrom; i++){ ci 1[i] = mute. X(p, pi 1[i]); ci 2[i] = mute. X(p, pi 2[i]); } } Computer Science Genetic Algorithms } Slide 22

Mutation code int mute. X(POPULATION *p, int pa) { return (flip(p->p. Mut) ? 1

Mutation code int mute. X(POPULATION *p, int pa) { return (flip(p->p. Mut) ? 1 - pa } Computer Science Genetic Algorithms : pa); Slide 23