Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer ScienceGenetic Algorithms Slide 1 Random/Exhaustive Search l Generate and Test 1. Generate a candidate solution and test to see if it solves the.

Similar presentations


Presentation on theme: "Computer ScienceGenetic Algorithms Slide 1 Random/Exhaustive Search l Generate and Test 1. Generate a candidate solution and test to see if it solves the."— Presentation transcript:

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

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

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

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

5 Computer ScienceGenetic Algorithms Slide 5 Hard problems l Computational complexity, problem size = n Binary SearchO(log(n)) Linear SearchO(n) Bubble SortO(n^2) SchedulingNP-complete (at least exponential == O(a^n)

6 Computer ScienceGenetic Algorithms Slide 6 Hard problems l Poorly defined RoboticsHow do we catch a ball, navigate, play basketball User Interfaces Predict next command, adapt to individual user MedicineProtein structure prediction, Is this tumor benign, design drugs DesignDesign bridge, jet engines, Circuits, wings ControlNonlinear controllers

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

8 Computer ScienceGenetic Algorithms Slide 8 Search tradeoff 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 l Lots of information (linear, continuous, …) means that we can exploit this information to arrive directly at a solution, without any exploration l 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

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

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

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

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

13 Computer ScienceGenetic Algorithms Slide 13 Generate pop(0) for(i = 0 ; i < popSize; i++){ for(j = 0; j < chromLen; j++){ Pop[i].chrom[j] = flip(0.5); } Initialize population with randomly generated strings of 1’s and 0’s

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

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

16 Computer ScienceGenetic Algorithms Slide 16 Genetic Algorithm l Generate pop(0) l Evaluate pop(0) l T=0 l While (T < maxGen) do Select pop(T+1) from pop(T) Recombine pop(T+1) Evaluate pop(T+1) T = T + 1 l Done

17 Computer ScienceGenetic Algorithms Slide 17 Genetic Algorithm l Generate pop(0) l Evaluate pop(0) l T=0 l While (T < maxGen) do Select pop(T+1) from pop(T) Recombine pop(T+1) Evaluate pop(T+1) T = T + 1 l Done

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

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

20 Computer ScienceGenetic Algorithms Slide 20 Genetic Algorithm l Generate pop(0) l Evaluate pop(0) l T=0 l While (T < maxGen) do Select pop(T+1) from pop(T) Recombine pop(T+1) Evaluate pop(T+1) T = T + 1 l Done

21 Computer ScienceGenetic Algorithms Slide 21 Crossover and mutation Mutation Probability = 0.001 Insurance Xover Probability = 0.7 Exploration operator

22 Computer ScienceGenetic Algorithms Slide 22 Crossover code void crossover(POPULATION *p, IPTR p1, IPTR p2, IPTR c1, IPTR c2) { /* p1,p2,c1,c2,m1,m2,mc1,mc2 */ int *pi1,*pi2,*ci1,*ci2; int xp, i; pi1 = p1->chrom; pi2 = p2->chrom; ci1 = c1->chrom; ci2 = c2->chrom; if(flip(p->pCross)){ xp = rnd(0, p->lchrom - 1); for(i = 0; i < xp; i++){ ci1[i] = muteX(p, pi1[i]); ci2[i] = muteX(p, pi2[i]); } for(i = xp; i lchrom; i++){ ci1[i] = muteX(p, pi2[i]); ci2[i] = muteX(p, pi1[i]); } } else { for(i = 0; i lchrom; i++){ ci1[i] = muteX(p, pi1[i]); ci2[i] = muteX(p, pi2[i]); }

23 Computer ScienceGenetic Algorithms Slide 23 Mutation code int muteX(POPULATION *p, int pa) { return (flip(p->pMut) ? 1 - pa : pa); }


Download ppt "Computer ScienceGenetic Algorithms Slide 1 Random/Exhaustive Search l Generate and Test 1. Generate a candidate solution and test to see if it solves the."

Similar presentations


Ads by Google