genetic algorithms - nottinghampszgxk/aim/2009/slides/ga.pdf · 3/7/2010 2 genetic algorithms...
TRANSCRIPT
3/7/2010
1
Genetic Algorithms
G5BAIMArtificial Intelligence MethodsArtificial Intelligence Methods
Graham [email protected] ‐ http://www.cs.nott.ac.uk/~gxk
Acknowledgement: Some of these slides are based on those from Wendy Williams
Genetic Algorithms
G5BAIM Genetic AlgorithmsCharles Darwin 1809 - 1882
"A man who dares to waste an hour of life has not discovered the value of life"
3/7/2010
2
Genetic Algorithms
Classes of Search TechniquesClasses of Search Techniques
Direct methods Indirect methods
Calculus-based techniques
Evolutionary algorithms Simulated annealing
Guided random search techniques
Dynamic programming
Enumerative techniques
Search techniques
Finonacci Newton Evolutionary strategies
Centralized Distributed
Parallel
Steady-state Generational
Sequential
Genetic algorithms
Genetic Algorithms
An Abstract Example
Distribution of Individuals in Generation 0
Distribution of Individuals in Generation N
3/7/2010
3
Genetic Algorithms
Components of a GAA problem to solve, and ...
Encoding technique (gene, chromosome)
Initialization procedure (creation)
Evaluation function (environment)
Selection of parents (reproduction)
Genetic operators (mutation, recombination)
Parameter settings (practice and art)
Genetic Algorithms
Genetic Algorithms• Based on survival of the fittest
• Developed extensively by John Holland in mid 70’s
• Based on a population based approach
• Can be run on parallel machines
• Only the evaluation function has domain knowledge
• Can be implemented as three modules; the evaluation module, the population module and the reproduction module.
• Solutions (individuals) often coded as bit strings
• Algorithm uses terms from genetics; population, chromosome and gene
3/7/2010
4
Genetic Algorithms
The GA Cycle
reproduction
population evaluation
modification
parents
children
modifiedchildren
evaluated children
discard
deleted members
Genetic Algorithms
Populationl ti
Chromosome Representation
Bit strings (0101 ... 1100)
Real numbers (43.2 ‐33.1 ... 0.0 89.2)
Permutations of element (E11 E3 E7 ... E1 E15)
population
( )
Lists of rules (R1 R2 R3 ... R22 R23)
Program elements(genetic programming)
... any data structure ...
3/7/2010
5
Genetic Algorithms
Reproduction
reproduction
population
parents
children
Parents are selected at random with selection chances biased in relation to chromosome evaluations.
Genetic Algorithms
Chromosome Modification
modificationchildren
modified children
Modifications are stochastically triggeredOperators:
MutationCrossover (recombination)
3/7/2010
6
Genetic Algorithms
Evaluation
evaluation
evaluatedchildren
modifiedchildren
The evaluator decodes a chromosome and assigns it a fitness measureThe evaluator is the only link between a classical GA and the problem it is solving
Genetic Algorithms
Deletion
population
discard
discarded members
Generational GA: entire populations replacedGenerational GA: entire populations replaced with each iteration
Steady‐state GA: a few members replaced each generation
3/7/2010
7
Genetic Algorithms
A Simple Example
The Traveling Salesman Problem:
Find a tour of a given set of cities so that
•each city is visited only once•each city is visited only once
•the total distance traveled is minimized
Genetic Algorithms
Representation
Representation is an ordered list of city
numbers known as an order‐based GA.
1) London 3) Dunedin 5) Beijing 7) Tokyo
2) Venice 4) Singapore 6) Phoenix 8) Victoria
CityList1 (3 5 7 2 1 6 4 8)
CityList2 (2 5 7 6 8 1 3 4)
3/7/2010
8
Genetic Algorithms
Mutation
Mutation involves reordering of the list:
Before: (5 8 7 2 1 6 3 4)
After: (5 8 6 2 1 7 3 4)
Genetic Algorithms
120
TSP Example: 30 Cities
40
60
80
100
120
y
0
20
0 10 20 30 40 50 60 70 80 90 100
x
3/7/2010
9
Genetic Algorithms
120
TSP30 (Performance = 941)
Solution i (Distance = 941)
20
40
60
80
100
y
0
20
0 10 20 30 40 50 60 70 80 90 100
x
Genetic Algorithms44626967 120
TSP30 (Performance = 800)
Solution j(Distance = 800)7864625442504040382135
20
40
60
80
100
y
67606040425099
0
20
0 10 20 30 40 50 60 70 80 90 100
x
3/7/2010
10
Genetic Algorithms
120
TSP30 (Performance = 652)
Solution k(Distance = 652)
40
60
80
100
y
0
20
0 10 20 30 40 50 60 70 80 90 100
x
Genetic Algorithms42383526 120
TSP30 Solution (Performance = 420)
Best Solution (Distance = 420)2135327
38464458606976
20
40
60
80
100
y
78716967628494
0
20
0 10 20 30 40 50 60 70 80 90 100
x
3/7/2010
11
Genetic Algorithms
Issues for GA Practitionersh b lChoosing basic implementation issues:
representation
population size, mutation rate, ...
selection, deletion policies
crossover, mutation operators
T i i C i iTermination Criteria
Performance, scalability
Solution is only as good as the evaluation function (often hardest part)
Genetic Algorithms
Benefits of Genetic Algorithms
Concept is easy to understand
Modular, separate from application
Supports multi‐objective optimization
Good for “noisy” environments
Always an answer; answer gets better with time
Inherently parallel; easily distributed
3/7/2010
12
Genetic Algorithms
Benefits of Genetic Algorithms (cont.)
Many ways to speed up and improve a GA‐based application as knowledge about problem domain is gained
Easy to exploit previous or alternate solutions
Flexible building blocks for hybrid applications
Substantial history and range of use
Genetic Algorithms
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 solutionWant to hybridize with an existing solution
Benefits of the GA technology meet key problem requirements
3/7/2010
13
Genetic Algorithms
Some GA Application TypesDomain Application Typeso a pp cat o ypes
Control gas pipeline, pole balancing, missile evasion, pursuit
Design semiconductor layout, aircraft design, keyboardconfiguration, communication networks
Scheduling manufacturing, facility scheduling, resource allocation
Robotics trajectory planning
M hi L i d i i l t k i i l ifi tiMachine Learning designing neural networks, improving classificationalgorithms, classifier systems
Signal Processing filter design
Game Playing poker, checkers, prisoner’s dilemma
CombinatorialOptimization
set covering, travelling salesman, routing, bin packing,graph colouring and partitioning
Genetic Algorithms
GA AlgorithmI iti li l ti f h• Initialise a population of chromosomes
• Evaluate each chromosome (individual) in the population
• Create new chromosomes by mating chromosomes in the current population (using crossover and mutation)
• Delete members of the existing population to make way for the new members
• E al ate the ne members and insert them into the pop lation• Evaluate the new members and insert them into the population
• Repeat stage 2 until some termination condition is reached (normally based on time or number of populations produced)
• Return the best chromosome as the solution
3/7/2010
14
Genetic Algorithms
GA Algorithm1 I iti li ti1. Initialization
2. Evaluation
3. Selection
4. Recombination
5. Mutation
6. Replacement
7 Repeat steps 2–6 until a terminating condition is met7. Repeat steps 2 6 until a terminating condition is met.
Genetic Algorithms
GA Algorithm1. Initialization
1 I iti li ti
2. Evaluation
3. Selection
4. Recombination
5. Mutation
6. Replacement
7. Repeat steps 2–6 until a terminating condition is met.
1. Initialization
The initial population of candidate solutions is usually generated randomly across the search space. However, domain‐specific knowledge or other information can be easily incorporated.
3/7/2010
15
Genetic Algorithms
GA Algorithm1. Initialization
2 E l ti
2. Evaluation
3. Selection
4. Recombination
5. Mutation
6. Replacement
7. Repeat steps 2–6 until a terminating condition is met.
2. Evaluation
Once the population is initialized or an offspring population is created, the fitness values of the candidate solutions are evaluated.
Genetic Algorithms
GA Algorithm1. Initialization
3 S l ti
2. Evaluation
3. Selection
4. Recombination
5. Mutation
6. Replacement
7. Repeat steps 2–6 until a terminating condition is met.
3. Selection
Selection allocates more copies of those solutions with higher fitness values and thus imposes the survival‐of‐the‐fittest mechanism on the candidate solutions. The main idea of selection is to prefer better solutions to worse ones, and many selection procedures have been proposed to accomplish this idea, including roulette‐wheel selection, stochastic universal selection, ranking selection and tournament selection, some of which are described in the next section.
3/7/2010
16
Genetic Algorithms
GA Algorithm1. Initialization
4 R bi ti
2. Evaluation
3. Selection
4. Recombination
5. Mutation
6. Replacement
7. Repeat steps 2–6 until a terminating condition is met.
4. Recombination
Recombination combines parts of two or more parental solutions to create new, possibly better solutions (i.e. offspring). There are many ways of accomplishing this (some of which are discussed in the next section), and competent performance depends on a properly designed recombination mechanism. The offspring under recombination will not be identical to any particular parent and will instead combine parental traits in a novel manner.
Genetic Algorithms
GA Algorithm1. Initialization
5 M t ti
2. Evaluation
3. Selection
4. Recombination
5. Mutation
6. Replacement
7. Repeat steps 2–6 until a terminating condition is met.
5. Mutation
While recombination operates on two or more parental chromosomes, mutation locally but randomly modifies a solution. Again, there are many variations of mutation, but it usually involves one or more changes being made to an individual’s trait or traits. In other words, mutation performs a random walk in the vicinity of a candidate solution.
3/7/2010
17
Genetic Algorithms
GA Algorithm1. Initialization
6 R l t
2. Evaluation
3. Selection
4. Recombination
5. Mutation
6. Replacement
7. Repeat steps 2–6 until a terminating condition is met.
6. Replacement
The offspring population created by selection, recombination, and mutation replaces the original parental population. Many replacement techniques such as elitist replacement, generation‐wise replacement and steady‐state replacement methods are used in GAs.
Genetic Algorithms
GA Algorithm - Evaluation
• Responsible for evaluating a chromosome
• Only part of the GA that has any knowledge about the problem.
The rest of the GA modules are simply operating on (typically) bit
strings with no information about the problem
• A different evaluation module is needed for each problem
3/7/2010
18
Genetic Algorithms
GA Algorithm - Population Module
• Responsible for maintaining the population
• Initilisation
– Random
– Known Solutions
Genetic Algorithms
GA Algorithm - Population Module• Deletion
– Delete-All : Deletes all the members of the current population and replaces
them with the same number of chromosomes that have just been created
– Steady-State : Deletes n old members and replaces them with n new
members; n is a parameter
But do you delete the worst individuals, pick them at random or delete the
chromosomes that you used as parents?
– Steady-State-No-Duplicates : Same as steady-state but checks that no
duplicate chromosomes are added to the population. This adds to the
computational overhead but can mean that more of the search space is
explored
3/7/2010
19
Genetic Algorithms
GA Parent Selection - Roulette Wheel•Sum the fitnesses of all the population members, TF
•Generate a random number, m, between 0 and TF
•Return the first population member whose fitness added to the preceding population members is
Chromosome 1 2 3 4 5 6 7 8 9 10Fitness 12 18 15 17 3 136 12 15 20 15
Running Total 12 30 45 62 65 201 213 228 248 263
1 2 3 4 5 6 7 8 9 10
Random Number 213 90 120 43 11 104 176 245 47 124
Chromsome Chosen 8 6 6 3 #N/A 6 6 9 4 6
NotesPress F9 to regenerate random numbersNotice how C6 tends to dominate due to its dominant fitness
Roulette Wheel Selection
preceding population members is greater than or equal to m
Genetic Algorithms
GA Parent Selection - Tournament• Select a pair of individuals at random. Generate a random
number, R, between 0 and 1. If R < r use the first individual as
a parent. If the R >= r then use the second individual as the
parent. This is repeated to select the second parent. The value of
r is a parameter to this method
• Select two individuals at random. The individual with the
highest evaluation becomes the parent. Repeat to find a second
parent
3/7/2010
20
Genetic Algorithms
GA Fitness Techniques• Fitness-Is-Evaluation : Simply have the fitness of the
chromosome equal to its evaluation
• Windowing : Takes the lowest evaluation and assigns each
chromosome a fitness equal to the amount it exceeds this
minimum.
• Linear Normalization : The chromosomes are sorted by
decreasing evaluation value. Then the chromosomes are
assigned a fitness value that starts with a constant value and
decreases linearly. The initial value and the decrement are
parameters to the techniques
Genetic Algorithms
GA Population Module - Parameters
• Population Size
• Elitism
3/7/2010
21
Genetic Algorithms
GA Reproduction - Crossover OperatorsOperators
One Point Crossover inOne Point Crossover inGenetic AlgorithmsGenetic Algorithms
© Graham Kendall
http://cs.nott.ac.uk/~gxk
Uniform Crossover inUniform Crossover inGenetic AlgorithmsGenetic Algorithms
© Graham Kendall
http://cs.nott.ac.uk/~gxk
Partially MatchedPartially MatchedCrossover (PMX) inCrossover (PMX) inGenetic AlgorithmsGenetic Algorithms
© Graham Kendall
http://cs.nott.ac.uk/~gxk
Order Based Crossover
Cycle Crossover
Genetic Algorithms
GA Example• Crossover probability, PC = 1.0p y,• Mutation probability, PM = 0.0• Maximise f(x) = x3 - 60 * x2 + 900 * x +100• 0 <= x >= 31• x can be represented using five binary digits
0 100
1 9412 16683 22874 28045 32256 35567 38038 39729 4069
10 4100 4500
Max : x = 10
f(x) = x^3 - 60x^2 + 900x + 100
10 410011 407112 398813 385714 368415 347516 323617 297318 269219 239920 210021 180122 150823 122724 96425 72526 51627 34328 21229 12930 100
0
500
1000
1500
2000
2500
3000
3500
4000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37
3/7/2010
22
Genetic Algorithms
GA Example• Generate random individuals
Chromosome Binary String x f(x) P1 11100 28 212 P2 01111 15 3475 P3 10111 23 1227
P4 00100 4 2804 TOTAL 7718 AVERAGE 1929.50
Genetic Algorithms
GA Example• Choose Parents, using roulette wheel selection• Crossover point is chosen randomly
Roulette Wheel Parent Chosen Crossover Point 4116 P3 N/A 1915 P 11915 P2 1
3/7/2010
23
Genetic Algorithms
GA Example - Crossover
1 0 1 1 1
0 1 1 1 1
P3
P2
1 1 1 1 1C1
0 0 1 0 0
0 1 1 1 1
P4
P2
0 0 1 1 1C3
0 0 1 1 11
C2 0 1 1 0 03
C4
Genetic Algorithms
GA Example - After First Round of BreedingBreeding
• The average evaluation has risen• P2, was the strongest individual in the initial population. It was
chosen both times but we have lost it from the current population• We have a value of x=7 in the population which is the closest
value to 10 we have foundChromosome Binary String x f(x)
P1 11111 31 131 P2 00111 7 3803 P3 00111 7 3803 P4 01100 12 3998 TOTAL 11735 AVERAGE 2933.75
3/7/2010
24
Genetic Algorithms
GA Example - Question?
• Assume the initial population was 17, 21, 4 and 28. Using the same GA methods we used above (PC = 1.0, PM = 0.0), what chance is there of finding the global optimum?
Genetic Algorithms
GA Example - Mutation
• A method of ensuring premature convergence does not occur• Usually set to a small value• Dynamic mutation and crossover rates
3/7/2010
25
Genetic Algorithms
Try Previous Exam Question
• Question and answer are available from the course web site
Genetic Algorithms
Representation Examples
• Jakobs S. (1996) On Genetic Algorithms for the Packing of Polygons, European Journal of Operational Research, 88:165-181
• Hart E., Ross P. and Nelson J.A.D. (1999) Dynamic Scheduling chicken catching – An investigation into the success of a genetic algorithm on a real-world scheduling problem, Annals of Operations Research 92:363–380Operations Research, 92:363 380
• Both of these papers are available on the course web site
3/7/2010
26
Genetic Algorithms
G5BAIMArtificial Intelligence MethodsArtificial Intelligence Methods
Graham KendallEnd of Genetic Algorithms