370 likes | 596 Views
Email: K.Li@qub.ac.uk. Genetic algorithms Prof Kang Li. Last lecture RBF. This Lecture Genetic algorithm Basic GA operations. Content. What is Genetic Algorithm? How to implement GA? Encoding Selection Crossover Mutation A example Matlab demo Differential evolution.
E N D
Email: K.Li@qub.ac.uk Genetic algorithms Prof Kang Li
Last lecture • RBF This Lecture • Genetic algorithm • Basic GA operations
Content • What is Genetic Algorithm? • How to implement GA? • Encoding • Selection • Crossover • Mutation • A example • Matlab demo • Differential evolution
What is Genetic Algorithm? Bio-Inspiredartificial intelligence class of probabilistic optimization algorithms Well-suited for nonlinear/hard problems with a large search space Influenced by Darwin’s Origin of species Developed by John Holland,Adaptation in Natural and Artificial Systems, U of Michigan Press, 1975
Natural Selection (Darwin’s theory) • Genetic contents -> survival capacity -> features • Reproduction • recombination (or crossover) first occurs. Genes from parents combine to form a whole new chromosome. • Newly created offspring mutated, elements of DNA are changed. Diversity • Survival of the fittest • Gene of the fittest survive, gene of weaker die out • Elitism • Evolution - change of species’ feature to fit environment
Main idea Produce a population of candidate solutions for a given problem Use operators inspired by the mechanisms of natural genetic variation Apply selective pressure toward certain properties Evolve to a more fit solution
Simple Genetic Algorithm Simple_Genetic_Algorithm() { Initialize the Population; Calculate Fitness Function;While(the number of generation > maximum number) { Selection;//Natural Selection, Survival Of Fittest Crossover;//Reproduction, Propagate favorable characteristics Mutation;//Mutation Calculate Fitness Function; } }
A B C D 1 1 1 0 1 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 population 1 0 0 1 1 selection 0 1 1 1 0 Fitness evaluation 1 0 0 1 1 0 1 1 1 0 Structure of Genetic Algorithm crossover Search space mutation reproduction Substitution
Genetic Algorithm Process Initial population 5th generation 10th generation
Applications of GA • Difficult Problems such as NP-class • Nonlinear dynamical systems - predicting, data analysis • Designing neural networks, both architecture and weights • Robot Trajectory Planning • Evolving LISP programs (genetic programming) • Strategy planning • Finding shape of protein molecules • TSP and sequence scheduling • Functions for creating images • VLSI layout planning • …
Encoding Selection Crossover GA Process Mutation
Encoding The process of representing the solution in the form of a string that conveys the necessary information. Just as in a chromosome, each gene controls a particular characteristics of the individual, and each bit in the string represents a characteristics of the solution.
Chromosome A 10110010110011100101 Chromosome B 11111110000000011111 Encoding Methods Binary Encoding Most common method of encoding. Chromosomes are strings of 1s and 0s and a gene of chromosomes represents the a particular characteristics of the problem.
Chromosome A 1 5 3 2 6 4 7 9 8 Chromosome B 8 5 6 7 2 3 1 4 9 Encoding Methods (contd.) Permutation Encoding Useful in ordering problems such as the Traveling Salesman Problem (TSP). Example. In TSP, every chromosome is a string of numbers, each of which represents a city to be visited.
Chromosome A 1.235 5.323 0.454 2.321 2.454 Chromosome B (left), (back), (left), (right), (forward) Encoding Methods (contd.) Value Encoding Used in problems where complicated values, such as real numbers, are used and where binary encoding would not suffice. Good for some problems, but often necessary to develop some specific crossover and mutation techniques for these chromosomes.
B C Selection A • Based on fitness function: • Determines how ‘good’ an individual is (fitness) • Better fitness, higher probability of survival • Selection of individuals for differential reproduction of offspring in next generation • Favors better solutions • Decreases diversity in population
Individual i will have a probability to be chosen Selection – Roulette Wheel Each solution gets a region on a roulette wheel according to its fitness Spin wheel, select solution marked by roulette-wheel pointer stochastic selection (better fitness = higher chance of reproduction)
q=6 selection Selection - Tournament • randomly selectq individuals from current population • Winner: individual(s) with best fitness among these q individuals • Example: select the best two individuals as parents for recombination
Crossover Chromosome A … … … … Chromosome B … Chromosome A* … … … Chromosome B* Crossover is a critical feature of genetic algorithms: Crossover process simulates the exchange of genetic material that occurs during biological reproduction In this process pairs in the breeding population are mated randomly with a crossover rate, Pc Typical crossover properties include that an offspring inherits the common feature from the parents along with the ability of the offspring to inherit two completely different features Popular crossover techniques: one point, two point and uniform crossover
11001011+11011111 = 11001111+11011011 11001011 + 11011110 = 11011111+11001010 Example-Bit string Crossover Single point crossover Two point Crossover
11001011 + 11011101 = 11011111 Bit string Crossover Uniform crossover : bits are randomly copied from the parents if random-number > Crossover-rate then Crossover otherwise remain unaltered
Mutation 42 58 Mutation consists of making small alterations to the values of one or more genes in a chromosome Mutation randomly perturbs the population’s characteristics, and prevents evolutionary dead ends Most mutations are damaging rather than beneficial and hence mutation rate must be low to avoid the destruction of species It works by randomly selecting a bit with a certain mutation rate in the string and reversing its value
Fitness Function • A measure of how successful an individual is in the environment • Problem dependent • Given chromosome, the fitness function returns a number • f : S R • Smooth and regular • Similar chromosomes produce close fitness values • Not have too many local extremes and isolated global extreme
Example(1) • Finding the maximum of a function: • f(x) = x² • Range [0, 31] Goal: find max (31² = 961) • Binary representation: string length 5 = 32 numbers (0-31) = f(x)
binary value fitness String 1 00110 6 36 String 2 00011 3 9 String 3 01010 10 100 String 4 10101 21 441 String 5 00001 1 1 Start Population • Typical parameter values • population size : 30 -100 • crossover rate : 0.7 -1 • mutation rate : 0.01 - 0.2
binary value fitness String 1 00110 6 36 String 2 00011 3 9 String 3 01010 10 100 String 4 10101 21 441 String 5 00001 1 1 Selection 6.13% 1.53% 17.04% 75.13% 0.17% • Worst one removed
binary value fitness String 1 00110 6 36 String 2 00011 3 9 String 3 01010 10 100 String 4 10101 21 441 String 5 00001 1 1 Selection Best individual: reproduces twice keep population size constant
binary value fitness String 1 00110 6 36 String 2 00011 3 9 String 3 01010 10 100 String 4 10101 21 441 String 5 10101 21 441 Selection • All others are reproduced once
partner x-position String 1 String 2 4 String 3 String 4 2 Crossover Parents and x-position randomly selected 0 0 1 1 1 0 0 1 1 0 7 6 String 1: 0 0 0 1 0 0 0 0 1 1 23 3 String 2: 0 1 1 0 1 0 1 0 1 0 21 10 String 3: 1 0 0 1 0 1 0 1 0 1 17 String 4: 21
Mutation • bit-flip • Offspring -String 1: 00111 (7) 10111 (23) • Offspring -String 3: 10101 (21) 10001 (17)
New population binary value fitness String 1 00111 7 49 String 2 10111 23 529 String 3 10101 21 441 String 4 10001 17 289 10101 21 String 5 441 • All individuals in the parent population are replaced by offspring in the new generation • (generations are discrete!) • New population (Offspring):
End • Iterate until termination condition reached, e.g.: • Number of generations • Best fitness • Process time • No improvements after a number of generations • Result after one generation: • Best individual: 10111 (23) – fitness 529 • Best solution after 100 generation: • Best solution: 11111 (31) – fitness 961
When to Use a GA • Alternate solutions are too slow or overly complicated • Need an exploratory tool to examine new approaches • Problem is similar to one that has already been successfully solved by using a GA • Want to hybridize with an existing solution • Benefits of the GA technology meet key problem requirements
Summary • Introduction to GA • Basic GA operations