1.03k likes | 1.23k Views
Genetic Algorithms. Yohai Trabelsi. Outline. Evolution in the nature Genetic Algorithms and Genetic Programming A simple example for Genetic Algorithms An example for Genetic programming. Evolution in the nature Genetic Algorithms and Genetic Programming
E N D
Genetic Algorithms YohaiTrabelsi
Outline • Evolution in the nature • Genetic Algorithms and Genetic Programming • A simple example for Genetic Algorithms • An example for Genetic programming
Evolution in the nature • Genetic Algorithms and Genetic Programming • A simple example for Genetic Algorithms • An example for Genetic programming
Evolution in the nature • A Chromosome: • A string of DNA. • Each living cell has some. • Image by Magnus Manske
Each chromosome contains a set of genes. • A gene is a block of DNA. • Each gene determines some aspect of the organism (e.g., eye colour).
Reproduction in the nature • Reproduction involves: 1. Recombination of genes from parents. 2. Small amounts of mutation (errors) in copying. • One type of recombination is crossover.
Reproduction involves: 1. Recombination of genes from parents. 2. Small amounts of mutation (errors) in copying. • Right image by Jerry Friedman.
In the nature, fitnessdescribes the ability to survive and reproduce. Images by ShwSie
The evolution cycle Parent selection Initialization Survivor selection Recombination Mutation Upper left image by 慕尼黑啤酒
Evolution in the nature • Genetic Algorithms and Genetic Programming • A simple example for Genetic Algorithms • An example for Genetic programming
Some history • First work of computer simulation of evolution- Nils AallBarricelli(1954) • In the 1950s and 1960s several researchers began independently studying evolutionary systems. • The field has experienced impressive growth over the past two decades.
Genetic Algorithms • The research on Genetic Algorithms focuses on imitating the evolution cycle in Algorithms. • That method is applicable for many hard search and optimization problems.
Initialization • Initialization is the process of making the first generation. • During the algorithm our goal will be to improve them by imitating the nature.
Termination. • In the nature we don’t have (yet) a point that the process stops. • In many cases an algorithm that runs forever is useless. • We should try to find the correct time for terminating the whole process. • That time may be after the results are good and/or before the running time is too long.
The modified evolution cycle Parent selection Initialization Survivor selection Recombination Mutation termination Upper left image by 慕尼黑啤酒
GA-Some definitions • In any generation there is a group of individuals that belongs to that generation. We call that group population. • Fitness will be a function fromindividuals to real numbers. • The product of the recombination process is an offspring.
Genetic Programming • Genetic Programming is Genetic Algorithm wherein the population contains programs rather than bitstrings.
Evolution in the nature • Genetic Algorithms and Genetic Programming • A simple example for Genetic Algorithms • An example for Genetic programming
A simple example • Problem: “Find” the binary number 11010010.
Initialization • We start with 5 random binary numbers with 8 digits each. • 01001010 • 10011011 • 01100001 • 10100110 • 01010011
The fitness function • We define the fitness of a number to be the sum of the distances of its digits from these in the target, with the sign minus. • The target: 11010010 • fitness(01001010)=
The target: 11010010 • fitness(01001010)=-3 • fitness(10011011)=-3 • fitness(01100001)=-5 • fitness(10100110)=-4 • fitness(01010011)=-2
Parent Selection • In each generation, some constant number of parents, say, 4 are chosen. Higher is the fitness, greater is the probability of choosing the individual.
{-3,-3, -5,-4,-2} • Assume we select , . • fitness() > fitness() selected. … • We get {}
Recombination • Two selected parents will be coupled with probability 0.5. • () , (, ), () • 3 is selected as a random number from 1…8 • Then we do a crossover: From () we get () • We repeat that for each selected couple.
Mutation • For each digit in each of the offsprings , we make the bit flip with probability 0.05. • For we have .
The process and it’s termination • We repeat the cycle until one of the numbers that we get would have fitness 0 (that is would be identical to the desired one). • We expect that it will not be too long in comparison to checking the fitness of all the numbers in the range. • Our hope is based on choosing parents with higher fitness and on producing next generations similarly to the nature.
Some Results • Similar example, where the target was “Hello world” achieved the score in generation 65. (population size=40 options) • In our simple case there are options in total.
Evolution in the nature • Genetic Algorithms and Genetic Programming • A simple example for Genetic Algorithms • An example for Genetic programming
American Checkers • Michel32Nl
Lose Checkers • The rules are the same as in the original game. • The goal is opposite to the goal in the original game:Each player tries to lose all of his pieces. • Player wins if he doesn’t have any pieces or if he can’t do any move.
The complexity • There are roughly legal positions. • In chess there are .
Previous work • There are few recent results on Lose checkers. • They concentrate either on search or on finding a good evaluation function. • They can help to improve good players but they can’t produce good players. • Improvements on a random player don’t worth much.
The algorithm • The individuals will be trees. • Each tree will behave like evaluation function for the board states (more details later). • A tree represents a chromosome. • Each tree contains nodes. • A node represents a gene. • There are three kinds of nodes: • Basic Terminal Nodes. • Basic Function Nodes. • Domain-Specific Terminal Nodes.
The algorithm • Make initial population • While the termination condition didn’t reached: • Select the best candidates for being parents. • Make the new generation by crossover and mutation • Evaluate the fitness of the new generation.
Make initial population • While the termination condition didn’t reached: • Select the best candidates for being parents. • Make the new generation by crossover and mutation • Evaluate the fitness of the new generation.
The initial population • The size of the population is one of the running parameters. • We select the trees randomly. • Their maximum allowed depth is also a running parameter. • We omit the details of the random selection.
Make initial population • While the termination condition didn’t reached: • Select the best candidates for being parents. • Make the new generation by crossover and mutation • Evaluate the fitness of the new generation.
Fitness evaluation • We define GuideArr to be an array of guide players. • Some of them are random players which are useful for evaluating initial runs. • Others, alpha-beta players, are based on search up to some level and random behavior since that level. • CoPlayNum is the number of players which are selected randomly from the current population for playing with the individual under evaluation. Image by Jon Sullivan
Fitness evaluation • back
Make initial population • While the termination condition didn’t reached: • Select the best candidates for being parents. • Make the new generation by crossover and mutation • Check whether the termination condition reached
Crossover • Randomly choose two different previously unselected individuals from the population. • If then • Perform one-way crossover with I1 as donor and I2 as receiver • Else • Perform two-way crossover with I1 and I2 • End if.
Two way crossover • Randomly select an internal node in each of the two individuals. • Swap the subtrees rooted at these nodes.
One way crossover • Randomly select an internal node in each of the two individuals as a root of selected subtree. • One individual (donor) inserts a copy of its selected sub-tree into another individual(receiver), in place of its selected sub-tree, while the donor itself remains unchanged. Similar to gene transfer in bacteria, image by Y tambe