ECE 103 Engineering Programming Chapter 52 Generic Algorithm Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip PSU ECE
Syllabus Generic Algorithm C c
3 Genetic Algorithms A genetic algorithm (GA) can solve certain classes of optimization problems in which: The details of the problem are not well known. The search space is large. Genetic algorithms are based on the biological principles of evolution and selection.
4 General Plan: An initial randomized population of candidate solutions is constructed. For each subsequent generation: The current generation is evaluated to determine its “fitness”. The most fit candidates are selected for “reproduction”. A new generation of offspring is created. This continues until a suitable solution is found or a fixed number of generations is reached.
5 Solutions are encoded as “bit strings”, e.g., a sequence of 1’s and 0’s stored in an array. Fitness is determined by how well a candidate solution meets a pre-defined criterion. Roulette wheel selection: An individual’s probability of being selected is directly proportional to its fitness. Only selected individuals are allowed to reproduce.
6 Typical reproduction methods: Crossover - potentially copies good (or bad) traits: Mutation (helps introduce genetic variety): Parent Parent Child Child Before After
7 Expressed in terms of arrays: Create initial population P current from N randomized bit strings (arrays) Create blank population P next to hold N bit strings (arrays) FOR up to G generations Evaluate population P current for fitness Initialize roulette wheel using fitness results Select parents from P current using roulette wheel probabilities Create population P next by generating N offspring using genetic operators Copy P next to P current END FOR
8 Depending on N, L, and # of generations to run, the array copy operation can be expensive. Why not use pointers to arrays instead? P current N bit-strings of length L (N L array) Evaluate fitness Initialize roulette wheel Roulette wheel selects parents Generate offspring P next N bit-strings of length L (N L array) Copy the contents of array P next to array P current one element at a time. In other words, the next generation becomes the current generation.
9 Expressed in terms of pointers: Create initial population P A from N randomized bit strings (arrays) Create blank population P B to hold N bit strings (arrays) Assign pointer P current → P A and pointer P next → P B FOR up to G generations Evaluate population P current for fitness Initialize roulette wheel using fitness results Select parents from P current using roulette wheel probabilities Create population P next by generating N offspring using genetic operators Swap pointers P current and P next END FOR
10 Gen k P current P A N bit-strings of length L (N L array) Evaluate fitness Initialize roulette wheel Roulette wheel selects parents Generate offspring P B N bit-strings of length L (N L array) P next Swap the pointers P current and P next. Gen k+1 P current P B N bit-strings of length L (N L array) Evaluate fitness Initialize roulette wheel Roulette wheel selects parents Generate offspring P A N bit-strings of length L (N L array) P next Swap the pointers P current and P next.
11 Example: Find the minimum of the following equation: f (x, y) = 4x 2 – 2.1x 4 + (1/3)x 6 + xy – 4y 2 + 4y 4 over the range –5 x, y 5 Using Mathcad, the global minimum value for f (x, y) on the defined interval is – This occurs at: (x 0, y 0 ) = (– , ) (x 1, y 1 ) = ( , – )
12 Run a genetic algorithm simulation using these reproduction methods: (GA-1) M 1 = 1-point crossover and M 2 = complement randomly chosen bit position. Probabilities are p 1 = 0.97 and p 2 = The GA is not elitist. (GA-2) Identical to GA-1 except that M 1 = 2-point crossover. (GA-3) M 1 = 1-point crossover with p 1 = 1.0. No M 2 is defined. Each bit in each member of the offspring population is complemented with a probability of The GA is not elitist. (GA-4) Identical to GA-3 except that the GA is elitist.
13 Simulation results: %Relative Error in Minimum Value & (x, y) for Best and Worst 200 th Generation (N=50, L=28, Runs=25) Best Run Worst Run RelErr%xy xy GA GA GA GA Comparison to Mathcad locations for minimum: (x 0, y 0 ) = (– , ) (x 1, y 1 ) = ( , – )
14 0
15 Example: NASA experiment to design an X-band antenna (8 to 12 GHz range for satellite communications): Result: improved performance and efficiency