460 likes | 802 Views
Genetic Algorithms. Introduction Genetic algorithms step by step Common questions Improving performance When to use it? Some famous applications. Genetic algorithms.
E N D
Genetic Algorithms • Introduction • Genetic algorithms step by step • Common questions • Improving performance • When to use it? • Some famous applications
Genetic algorithms Genetic algorithms are based on a biological metaphor and the search for the optimal solution is viewed as a competition amongst the population of evolving candidate problem solutions. + =>
Evolution Theory All living things have changed in response to environmental conditions by the natural selection of randomly occurring mutations, developing from the simplest forms to complex forms which are more prolific and stronger, due to their better adaptation to their environment. Webster’s Dictionary
Creation of a new population Selection Reproduction Genetic algorithms New population Initial population
Genetic Algorithms Genetic algorithms are based on a biological metaphor and the search for the optimal solution is viewed as a competition amongst the population of evolving candidate problem solutions.
Genetic Algorithms - Elementary Problems • How to define individuals? • Fitter individuals should have better chance to survive and to give a rise to the next population of individuals • How to simulate reproduction cycle? • Will it work (i.e. inheritance + random mutations = better offspring’s characteristics)?
Genetic Algorithms - General Definition 1. Set up the generation number counter ( N = 0 ) 2. Create the initial randomly generated population P(0) 3. Evaluate fitness of each member of the population P(N) 4. Select pairs of the members from the population P(N) and produce an offspring of these parental pairs using genetic operators 5. Set the new population P(N+1) to the just created offspring 6. Increase the generation number counter by one ( N = N + 1 ) 7. If N is equal to the maximal number of generations allowed then terminate the algorithm, else go to step number 3
Step by Step - Individuals • each individual will be encoded into a chromosome (with the fixed length and the fixed order of genes) • for example let’s have the following individuals: Individual No. Chromosome 1 [ 1, 0, 1, 0, 1, 1, 0, 0] 2 [ 0, 1, 1, 1, 1, 0, 1, 1] 3 [ 0, 0, 0, 1, 0, 0, 0, 1] 4 [ 1, 1, 0, 0, 1, 1, 0, 0]
Step by Step - Fitness • related to the relevant problem we want to solve Individual No. ChromosomeFitness 1 [ 1, 0, 1, 0, 1, 1, 0, 0] 4 2 [ 0, 1, 1, 1, 1, 0, 1, 1] 6 3 [ 0, 0, 0, 1, 0, 0, 0, 1] 2 4 [ 1, 1, 0, 0, 1, 1, 0, 0] 4
Step by Step - Reproduction • select the pairs of individuals (i.e. their chromosomes) from the current population for mating Ind. No. Chromosome Fitness Share 1 [ 1, 0, 1, 0, 1, 1, 0, 0] 4 25,0% 2 [ 0, 1, 1, 1, 1, 0, 1, 1] 6 37,5% 3 [ 0, 0, 0, 1, 0, 0, 0, 1] 2 12,5% 4 [ 1, 1, 0, 0, 1, 1, 0, 0] 4 25,0% 16 100%
Step by Step - Fitness Proportionate Selection Ind. No. Share 1 25,0% 2 37,5% 3 12,5% 4 25,0%
Step by Step - Reproduction • we played our biased roulette four times and the following chromosomes were selected: Ind. No. Chromosome 1st pair 2 [ 0, 1, 1, 1, 1, 0, 1, 1] 4 [ 1, 1, 0, 0, 1, 1, 0, 0] 2nd pair 3 [ 0, 0, 0, 1, 0, 0, 0, 1] 2 [ 0, 1, 1, 1, 1, 0, 1, 1]
Basic Genetic Operators • crossover operator is based on partial chromosome exchanges XXXXXX XXXXYY YYYYYY YYYYXX • mutation operator performs occasional random changes of the value of genes ZZZZZZ ZZWZZZ
Step by Step - Crossover • Let us suppose that we have randomly generated the second gene as the crossover point for the first pair and the fourth gene for the second. Chromosome Offspring [0,1, | 1,1,1,0,1,1] [0,1, | 0,0,1,1,0,0] [1,1, | 0,0,1,1,0,0] [1,1, | 1,1,1,0,1,1] [0,0,0,1, | 0,0,0,1] [0,0,0,1, | 1,0,1,1] [0,1,1,1, | 1,0,1,1] [0,1,1,1, | 0,0,0,1]
Step by Step - Mutation • Let us suppose that mutation operator causes the following changes on the just created offspring (mutated genes are enhanced): Offspring before mutation Offspring after mutation [0,1,0,0,1,1,0,0] [0,1,0,1,1,1,0,0] [1,1,1,1,1,0,1,1] [1,1,1,1,1,0,1,1] [0,0,0,1,1,0,1,1] [0,0,0,1,1,0,1,1] [0,1,1,1,0,0,0,1] [0,1,1,1,0,0,0,0]
Step by Step - New Generation • set the new population to the just created offspring Individual No. ChromosomeFitness 1 [0, 1, 0, 1, 1, 1, 0, 0] 4 2 [1, 1, 1, 1, 1, 0, 1, 1] 7 3 [0, 0, 0, 1, 1, 0, 1, 1] 4 4 [0, 1, 1, 1, 0, 0, 0, 0] 3
Step by Step - Results Initial PopulationNew Population overall fitness 16 18 weakest individual 2 3 strongest individual 6 7 Important fact: • new population has better characteristics than the previous one
It Works !!! (...usually) • by repeating the evolution cycle many times we will finally get the population with several more fit individuals, which could be a reasonable (or even an optimal) solution to the given problem • due to randomness incorporated in the process of selection and reproduction, we have to expect that in each run the algorithm can evolve in a different way
Common questions • Can a GA converge to a poor solution? Yes, of course • Is there any relationship between genetic algorithms and neural networks? GA imitates evolution process NN imitates brain structure and its functioning
Common questions • How do we know whether the GA solution is optimal or near optimal? If we knew how to find the optimal solution, we would not need to utilise a GA. There is no guarantee that an optimal solution will be found. We only know, that we can get a good solution that is better than others. • Is it as easy as it was presented here? No.
On the Origin of Species by means of Natural Selection ”The most vigorous males or those which have most successfully struggled with their conditions of life, will generally leave most progeny. But success will often depend on the males having special weapons, or means of defence, or charms; and the slightest advantage will lead to victory.” Charles Darwin [1859]
Improving Performance Encoding • binary - simple, probably most common, but not suitable for everything • multiple character - [a1, math1, no, psy, psy, eng1, eng1] • real-valued - [1.85, 97.5, 35, 25 360]
Improving Performance Selection mechanism • fitness proportionate - biased roulette • stochastic universal sampling - instead of spinning the roulette wheel k times to select k individuals, we can spin the wheel just once and select them all, assuming that we have k equally spaced pointers
Improving Performance Selection pressure is too low
Improving Performance Selection pressure is too high
Improving Performance Selection mechanism • rank selection - individuals are ranked according to their fitness and then the probability of each individual to be selected for mating depends on its rank • tournament selection - k individuals have to fight each other to be selected for reproduction
Improving Performance Rank selection
Improving Performance Tournament selection • Select randomly k>=2individuals and let them fight amongst themselves
Improving Performance Reproduction process • generational - whole population consists entirely of the offspring formed by directly preceding population • elitism - some number of the best individuals (“elite”)is retained for next population • steady-state - only a few of the least fit individuals are replaced in each generation
Improving Performance Genetic operators • multiple-point crossover - break down the chromosomes to k+1 pieces and exchange the relevant pieces Chromosome Offspring XXXX | XX | XX XXXX| YY| XX YYYY| YY| YY YYYY| XX| YY
Improving Performance Genetic operators • uniform crossover - each gene of the offspring is selected randomly fro the corresponding genes of the parents Chromosome Offspring X X X X X X X X X Y X X YYX Y Y Y Y Y Y Y Y Y Y X Y Y XXY X
Typical applications: machine learning timetabling, scheduling data mining robot trajectory etc. optimisation problems designing neural networks strategy planning evolving programs When to use it?
Timetabling • Each chromosome represents a timetable • A random population of feasible • timetables is created • Each timetable is evaluated according to chosen criteria • Timetables are selected for reproduction • Crossover and mutation operators are used to produce offspring • The population increasingly consists of “good” timetables
Evolution of Strategies - Game Playing • Each chromosome represents different strategies for playing the game • Initial population is generated randomly • During the selection process each strategy is required to play a certain number of games against other strategies • The strategies with the most wins are selected for reproduction • The population increasingly consists of “good” strategies
Rule Discovery • SAMUEL system discovers rules by which a slower but more manoeuvrable aircraft can evade a faster but less agile missile until the missile runs out of fuel • The aircraft can sense the range, speed, heading and bearing of the missile • Rules are of a fairly uniform sort, such as to turn left by 90 degrees if the missile parameters are lie within certain intervals
Rule Discovery • Chromosomes are ordered sets of possible rules (if situation x occurs do action encoded within x-th gene) • Fitness evaluation is by simulation (it is examined for how long the aircraft can evade the missile using particular set of rules) • It takes hours to evaluate initial population !
Criminal suspect recognition • It is easy to identify a criminal from photo but hard to describe his or her features • It is difficult to generate even from computer library of visual features • Idea to use genetic algorithms to help witnesses in the identification of criminal suspects
Criminal suspect recognition Faceprints • randomly generates 20 faces on a computer screen • witness evaluates each face on a 10 point scale • GA generates additional faces from 5 building blocks: eyes, mouth, nose, hair and chin (7-bit string each) • Chromosome is a 35-bit binary string (34 billion faces) • Witness rates successive generations with 10 point scale • Convergence often occurs after 20 generations
Boeing 777 • The engines were designed by classical techniques with the emphasis on efficient fuel consumption • Genetic algorithms were used to fine-tuning of some parameters of the already designed engines • Due to their utilization at this stage the consumption of fuel has been reduced by 2,5% • (operating cost savings cca 2 mil USD at one plane per year)