Institute of Southern Punjab Multan: Syed Zohair Quain Haider Lecturer ISP Multan
Institute of Southern Punjab Multan: Syed Zohair Quain Haider Lecturer ISP Multan
CS-216
Institute of Southern Punjab
Multan
Last Discussion
Last Discussion
In Today’s Lecture
• Genetic algorithm
Today’s Discussion
Today’s Discussion
• Searching algorithm based on the mechanics of biological evolution
• Developed by John Holland, University of Michigan (1970’s)
• To understand the adaptive processes of natural systems
• To design artificial systems software that retains the robustness of
natural systems
Genetic Algorithm
Genetic Algorithm
• IF there are organisms that reproduce, and
• IF offspring's inherit traits from their progenitors, and
• IF there is variability of traits, and
• IF the environment cannot support all members of a growing population,
• THEN those members of the population with less-adaptive traits
(determined by the environment) will die out, and
• THEN those members with more-adaptive traits (determined by the
environment) will thrive
The result is the evolution of species
Basic idea
Basic idea
• Provide efficient, effective techniques for optimization and machine
learning applications
• Widely-used today in business, scientific and engineering circles
Repeat
Generate a random possible solution
Test the solution and see how good it is until solution is good
enough
A dumb solution
A dumb solution
• Sometimes - yes:
• if there are only a few possible solutions
• and you have enough time
• then such a method could be used
• For most problems - no:
• many possible solutions
• with no time to try them all
• so this method can not be used
Components of a GA
Components of a GA
The GA Cycle of Reproduction
children
reproduction modification
modified
parents children
population evaluation
evaluated children
deleted
members
discard
population
Population
Population
children
reproduction
parents
population
Reproduction
Reproduction
children
modification
modified children
Chromosome Modification
Chromosome Modification
modified
evaluated children
children
evaluation
• The evaluator decodes a chromosome and assigns it a
fitness measure
• The evaluator is the only link between a classical GA and
the problem it is solving
Evaluation
Evaluation
population
discarded members
discard
• Generational GA:
entire populations replaced with each iteration
Deletion
Deletion
• Binary Encoding
• Permutation Encoding
• Value Encoding
• Tree Encoding
Encoding
Encoding
• Roulette Wheel Selection
– Calculate sum of all chromosome finesses in population and generate
random number from interval. Go through the population and sum finesses
from 0 - sum s. When the sum s is greater then r, stop and return the
chromosome where you are.
• Rank Selection
– First ranks the population and then every chromosome receives fitness from
this ranking. The worst will have fitness 1, second worst 2 etc. and the best
will have fitness N (number of chromosomes in population).
• Steady State Selection
– In every generation are selected a few (good - with high fitness)
chromosomes for creating a new offspring. Then some (bad - with low
fitness) chromosomes are removed and the new offspring is placed in their
place. The rest of population survives to new generation.
• Elitism
– Elitism is name of method, which first copies the best chromosome (or a few
best chromosomes) to new population. The rest is done in classical way.
Elitism can very rapidly increase performance of GA, because it prevents
losing the best found solution.
Selection
Selection
• Single Point Crossover
• Two Point Crossover
• Multi Point Crossover
• Uniform Crossover
• Ring Crossover
• Arithmetic Crossover
Different Kind of Mutation
Crossover Operator
Crossover Operator
• Rate of Mutation
• Bit Inversion Mutation
• Order Changing Mutation
Mutation operator
Mutation operator
• Decade long debate: which one is better?
• Mainly depends on the problem
• Generally it is good to have both
• Certainly both have different role
Crossover or mutation
Crossover or mutation
• Only crossover can combine information from two parents
• Only mutation can introduce new information
• Crossover does not change the frequencies of the population
• To hit the optimum you often need a ‘lucky’ mutation
Crossover or mutation
Crossover or mutation
• Simple problem: max x2 over {0,1,…,31}
• GA approach:
• Representation: binary code, e.g. 01101 13
• Population size: 4
• 1-point crossover, bitwise mutation
• Roulette wheel selection
• Random initialization
• We show one generational cycle done by hand
An example
x2 example: selection
x example: selection
2
X 2 example: crossover
X example: crossover
2
• Choosing basic implementation issues:
representation
population size, mutation rate, ...
selection, deletion policies
crossover, mutation operators
• Termination Criteria
• Solution is only as good as the evaluation function (often
hardest part)
Genetic Programming
Genetic Programming
Eight Queens Problems
Questions Session
Questions Session