introduction to Genetic Algorithms Yonatan Shichel
Genetic Algorithms Bio-Inspired Bio-Inspired artificial intelligence class of probabilistic optimization algorithms §Well-suited for nonlinear/hard problems with a large search space §Developed by John Holland §Influenced by Darwin’s Origin of species What are Genetic Algorithms?
Evolution Variety Variety of species individuals within the population Competition Competition for limited resources Overproduction Overproduction of offspring generation §Survival of the fittest Origin of Species, 1859 Darwin’s principles
Evolution §Initial population Variety of shapes, colors, behaviors Each individual fits differently to the environment How does it work?
Evolution §Initial population §Reproduction Offspring combines both parents properties Siblings may differ in properties Mutations may occur How does it work?
Evolution §Initial population §Reproduction §Limited environmental resources Only a portion of the individuals survive Survival chances – according to fitness measure usually. How does it work?
Evolution Observations §Changes in the population content “good” properties are kept, “bad” are distinct evolutionary pressure
Genetic Algorithms The computational model produce an initial population of individuals while (termination condition not met) do evaluate the fitness of all individuals select fitter individuals for reproduction recombine between individuals mutate individuals
Genetic Algorithms The computational model initial population produce an initial population of individuals termination condition while ( termination condition not met) do evaluate evaluate the fitness of all individuals select select fitter individuals for reproduction recombine recombine between individuals mutate mutate individuals
Genetic Algorithms The computational model GnGnGnGn G n+1 = crossover mutation fitness
GA in action The Knapsack problem (NP) §There are N items: Each item i has a weight w i Each item i has a value v i §The knapsack has a limited capacity of W units. §The problem description: Maximize While
GA in action The Knapsack problem (NP) §For example: §Knapsack capacity = 100 JIHGFEDCBA
GA in action Before we begin… genome encoding 1.Define the genome encoding fitness function 2.Define the fitness function
GA in action Genome Encoding Bit array: 0 = don’t take the item 1 = take the item (items taken: A, B, E) E--BA
GA in action Genome Encoding Bit array: 0 = don’t take the item 1 = take the item (items taken: A, B, C, D, E, F, G, I) I-GFEDCBA
GA in action Fitness Function JIHGFEDCBA
GA in action Fitness Function JIHGFEDCBA
Genetic Algorithms Fitness Evaluation produce an initial population of individuals while (termination condition not met) do evaluate evaluate the fitness of all individuals select fitter individuals for reproduction recombine between individuals mutate individuals
Genetic Algorithms Fitness Evaluation For each individual, calculate the fitness value:
Genetic Algorithms Selection produce an initial population of individuals while (termination condition not met) do evaluate the fitness of all individuals select select fitter individuals for reproduction recombine between individuals mutate individuals
Genetic Algorithms Selection §Fitness-proportionate (roulette wheel) §Rank Selection (scaling) §Tournament Selection §…
Genetic Algorithms Crossover produce an initial population of individuals while (termination condition not met) do evaluate the fitness of all individuals select fitter individuals for reproduction recombine recombine between individuals mutate individuals
Genetic Algorithms Crossover Using a crossover probability P C per individual: §Single point crossover §Two/multi points crossover §Uniform / weighted crossover §…
Genetic Algorithms Mutation produce an initial population of individuals while (termination condition not met) do evaluate the fitness of all individuals select fitter individuals for reproduction recombine between individuals mutate mutate individuals
Genetic Algorithms Mutation Using a crossover probability P M per bit: §Bit flip mutation §Bit switch mutation §…
Genetic Algorithms Crossover & Mutation examples
Genetic Algorithms Initial Population initial population produce an initial population of individuals while (termination condition not met) do evaluate the fitness of all individuals select fitter individuals for reproduction recombine between individuals mutate individuals
Genetic Algorithms Initial Population Create a fixed size population using: §Random generated individuals §Individuals resulted from previous evolutionary runs
GA in action Initial Population Example of random population:
Genetic Algorithms Termination Condition produce an initial population of individuals termination condition while ( termination condition not met) do evaluate the fitness of all individuals select fitter individuals for reproduction recombine between individuals mutate individuals
Genetic Algorithms Termination Condition §When an optimal solution is found §When the results converge to constant value §After a predetermined number of generations
Genetic Algorithms Sample Evolutionary Run §Population size: 100 individuals §Crossover: Single pt., P C =0.9 §Mutation: Bit flip, P M =0.01 §Selection: tournament, groups of 2 §Termination condition: after 100 generations
Genetic Algorithms Sample Evolutionary Run
Genetic Algorithms Conclusions §GA is nondeterministic – two runs may end with different results §There’s no indication whether best individual is optimal §Fitness tends to converge during time
Genetic Algorithms GA variations §Coevolution Cooperative Competitive §Parallel GA §Hybrid GA