150 likes | 282 Views
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 Wong @ PSU ECE. Syllabus. Generic Algorithm C C C c. Genetic Algorithms
E N D
ECE 103 Engineering ProgrammingChapter 52Generic Algorithm Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE
Syllabus • Generic Algorithm • C • C • C • c
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. 3
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. 4
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. 5
Typical reproduction methods: Crossover - potentially copies good (or bad) traits: Mutation (helps introduce genetic variety): 6
Expressed in terms of arrays: Create initial population Pcurrent from N randomized bit strings (arrays) Create blank population Pnext to hold N bit strings (arrays) FOR up to G generations Evaluate population Pcurrent for fitness Initialize roulette wheel using fitness results Select parents from Pcurrent using roulette wheel probabilities Create population Pnext by generating N offspring using genetic operators Copy Pnext to Pcurrent END FOR 7
Depending on N, L, and # of generations to run, the array copy operation can be expensive. Why not use pointers to arrays instead? Pcurrent N bit-strings of length L (NL array) Evaluate fitness Pnext N bit-strings of length L (NL array) Initialize roulette wheel Generate offspring Roulette wheel selects parents Copy the contents of array Pnext to array Pcurrentone element at a time. In other words, the next generation becomes the current generation. 8
Expressed in terms of pointers: Create initial population PA from N randomized bit strings (arrays) Create blank population PB to hold N bit strings (arrays) Assign pointer Pcurrent→ PA and pointer Pnext→ PB FOR up to G generations Evaluate population Pcurrent for fitness Initialize roulette wheel using fitness results Select parents from Pcurrent using roulette wheel probabilities Create population Pnext by generating N offspring using genetic operators Swap pointers Pcurrent and Pnext END FOR 9
Evaluate fitness Evaluate fitness Pcurrent PA N bit-strings of length L (NL array) Pcurrent PB N bit-strings of length L (NL array) Gen k PB N bit-strings of length L (NL array) PA N bit-strings of length L (NL array) Pnext Pnext Initialize roulette wheel Initialize roulette wheel Generate offspring Generate offspring Roulette wheel selects parents Roulette wheel selects parents Swap the pointers Pcurrent and Pnext. Swap the pointers Pcurrent and Pnext. Gen k+1 10
Example: Find the minimum of the following equation: f (x, y) = 4x2 – 2.1x4 + (1/3)x6 + xy – 4y2 + 4y4 over the range –5 x, y 5 Using Mathcad, the global minimum value forf (x, y) on the defined interval is –1.0316285. This occurs at: (x0, y0) = (– 0.089842, +0.7126564) (x1, y1) = ( +0.089842, –0.7126564) 11
Run a genetic algorithm simulation using these reproduction methods: (GA-1) M1 = 1-point crossover and M2 = complement randomly chosen bit position. Probabilities are p1 = 0.97 and p2 = 0.03. The GA is not elitist. (GA-2) Identical to GA-1 except that M1 = 2-point crossover. (GA-3) M1 = 1-point crossover with p1 = 1.0. No M2 is defined. Each bit in each member of the offspring population is complemented with a probability of 10-5. The GA is not elitist. (GA-4) Identical to GA-3 except that the GA is elitist. 12
Simulation results: Comparison to Mathcad locations for minimum: (x0, y0) = (– 0.089842, +0.7126564) (x1, y1) = ( +0.089842, –0.7126564) 13
0 14
Example: NASA experiment to design an X-band antenna (8 to 12 GHz range for satellite communications): Result: improved performance and efficiency 15