ece 103 engineering programming chapter 52 generic algorithm herbert g. mayer, psu cs status...
TRANSCRIPT
ECE 103 Engineering ProgrammingChapter 52
Generic Algorithm
Herbert G. Mayer, PSU CSStatus 6/4/2014
Initial content copied verbatim fromECE 103 material developed by
Professor Phillip Wong @ PSU ECE
Syllabus Generic Algorithm C C 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 1
1011010 010100110
Parent 2
0011010 110110101
Child 1
1011010 110110101
Child 2
0011010 010100110
Before 1101101001101110
After 1101100001101110
7
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
8
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-stringsof length L
(NL array)
Evaluatefitness
Initialize roulette wheel
Roulette wheelselects parents
Generate offspring
Pnext
N bit-stringsof length L
(NL array)
Copy the contents of array Pnext to array Pcurrent one element at a time.
In other words, the next generation becomes the current generation.
9
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
10
Gen k
Pcurrent PA
N bit-stringsof length L
(NL array)
Evaluatefitness
Initialize roulette wheel
Roulette wheelselects parents
Generate offspring
PB
N bit-stringsof length L
(NL array)
Pnext
Swap the pointers Pcurrent and Pnext.
Gen k+1
Pcurrent PB
N bit-stringsof length L
(NL array)
Evaluatefitness
Initialize roulette wheel
Roulette wheelselects parents
Generate offspring
PA
N bit-stringsof length L
(NL array)
Pnext
Swap the pointers Pcurrent and Pnext.
11
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)
12
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.
13
Simulation results:%Relative Error in Minimum Value & (x, y) for Best and Worst Runs
@ 200th Generation (N=50, L=28, Runs=25)Best Run Worst Run
RelErr% x y RelErr% x yGA-1 0.000 -0.090643 0.712629 6.864 -0.086980 0.612525GA-2 0.000 -0.089422 0.713239 7.773 -0.002747 -0.625954GA-3 0.013 -0.086980 0.708967 13.659 -0.098578 -0.713239GA-4 0.075 -0.089422 0.702863 15.357 -0.000916 -0.823109
Comparison to Mathcad locations for minimum:(x0, y0) = (– 0.089842, +0.7126564)(x1, y1) = ( +0.089842, –0.7126564)
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