110 likes | 204 Views
7-13-05- CS8625. Genetic algorithms. CS8625 High Performance and Parallel Computing Dr. Ken Hoganson. Class Will Start Momentarily…. Genetic Programming.
E N D
7-13-05- CS8625 Genetic algorithms CS8625 High Performance and Parallel ComputingDr. Ken Hoganson • Class • Will • Start • Momentarily…
Genetic Programming Concept: For problems with very large number of possible solutions, and no direct computational mechanism to obtain solution, genetic programming can be used to search for a solution. • Example problem: Maximize f(w,x,y,x)= -w2+100w-x2-40x-y2+80y-z2-200z For values (w,x,y,z) from [–4999 +5000] • How many possible solutions? • 10,000 values for each variable • 4 variables 10,0004 = (104)4 =1016 • 10,000,000,000,000,000 possible combinations to search!
Genetic Algorithm • 10,000,000,000,000,000 possible combinations to search! • Say 10gigahertz machine • Assume 1 operation per cycle • Each operation takes 1/10billionth of a second • 1/10,000,000,000 = 1/1010 = 10-10 second • Assume evaluating the function takes 100 operations (102) • One evaluation takes 102 * 10-10 = 10-8 seconds • 100,000,000 (108 )evaluations per second • 1016 / 108 = 108 seconds = 100,000,000 seconds • (31,536,000 seconds in a year) • 3 years to check every solution!
Rather than check every combination of variables by evaluating function for that combination, Use genetic algorithm instead. • SubSet of (random) initial combinations of w,x,y,z • Combine the subset wxyz-combinations in a way that favors the solution interested in (crossover). • (natural selection favors reproduction of the most “fit” parents, producing more “fit” offspring) • Repeat for multiple generations, which should tend toward an optimal solution. • Can also allow for random mutations (the random subset of wxyz combinations may include values close to the optimal)
Implementation Values for w,x,y,z: lets restrict to values from –4095 to +4096 • two’s complement or sign-magnitude in 13 bits • So, have 4 variables of 13 bits each = 52 bits total • Crossover: children are combinations of variables from two parents, • ie a child of A and B could have w from A, x from B, y from A, z from B
Implemenation • Start with 64 random combinations of (w,x,y,z) • Organized in 8 subsets of 8 combinations • Each iteration, the best 4 (w,x,y,z) in each set combine with a best (w,x,y,z) from other sets to produce: • A new “generation” of 64 children • The “worst’ 4 (w,x,y,z) in each set do not reproduce, and ‘die’ and are eliminated from the subset, and replaced by offspring from the successful and reproducing combinations. • The reproducing parents are also eliminated, replaced by the “new offspring”
Implementation • To allow for random mutations: • In each iteration, allow random mutations, which we will model as a bit “flip” (reversal, complementation) • Eight mutations per generation offspring (8 out of the new 64 child combinations of w,x,y,z)
Design guidance • Just a command line kind of interface, but show something of the changing w,x,y,z each generation as they converge toward the maximum. • Use Java threads, one per subset (8 threads) to do the evaluations of the best combinations, and exchange “DNA” with other threads.
Convergence? • What is the solution? This example chosen because we can find a solution. • Example problem: Maximize f(w,x,y,x)= -w2+100w-x2-40x-y2+80y-z2-200z For values (w,x,y,z) from [–4999 +5000] • Algebra – completing the square for each variable yields: 14500-(w-50)2-(x+20)2-(y-40)2-(z+100)2 • Since all squared terms subtract from the 14500, the maximum is where each variable term is zero: W=50, x=-20, y=40, z=-100
Final Exam Project • This project will be your final exam! Turn in: • a description of your software design • source code • and your experimental results from running your algorithm. • Due date not set, but probably first day of finals. • Class time will be given for this project. • Perhaps only a couple more lectures this semester.
End of Lecture End Of Today’s Lecture.