You are on page 1of 71

Genetic Algorithms (GA)

“Genetic Algorithms are good at taking large, potentially huge search


spaces and navigating them, looking for optimal combinations of
things, solutions you might not otherwise find in a lifetime.”
Originator
 John Holland, University of Michigan
(1975)

Variation to GA

o Canonical Genetic Algorithm


o Vose, 1993
Introduction
 Computing pioneers (especially in AI) looked
to natural systems as guiding metaphors
 Evolutionary computation
 Any biologically-motivated computing activity
simulating natural evolution
 Genetic Algorithms are one form of this
activity
 Directed search algorithms based on the mechanics
of biological evolution
 Original goals
 Formal study of the phenomenon of adaptation
 John Holland
 An optimization tool for engineering problems
Introduction (cont..)

 Provide efficient, effective


techniques for optimization and
machine learning applications
 Widely-used today in business,
scientific and engineering circles
Classes of Search Techniques
S e a rc h te c h n iq u e s

C a lc u lu s - b a s e d te c h n iq u e s G u id e d ra n d o m s e a rc h te c h n iq u e s E n u m e r a tiv e te c h n iq u e s

D ir e c t m e th o d s In d ir e c t m e th o d s E v o lu tio n a ry a lg o rith m s S im u la te d a n n e a lin g D y n a m ic p r o g r a m m in g

F in o n a c c i N e w to n E v o lu tio n a r y s tr a te g ie s G e n e tic a lg o rith m s

P a ra lle l S e q u e n tia l

C e n tra liz e d D is trib u te d S te a d y -s ta te G e n e ra tio n a l


Why evolution as a metaphor
o Ability to efficiently guide a search through
a large solution space
 Ability to adapt solutions to changing
environments
 “Emergent” behavior is the goal
 “The hoped-for emergent behavior is

the design of high-quality solutions to


difficult problems and the ability to
adapt these solutions in the face of a
changing environment”
 Melanie Mitchell, An Introduction to Genetic
Algorithms
Evolutionary terminology

 Abstractions imported from biology


 Chromosomes, Genes, Alleles
 Fitness, Selection
 Crossover, Mutation
Components of a GA

 Encoding technique (gene, chromosome)


 Initialization procedure (creation)
 Evaluation function (environment)
 Selection of parents (reproduction)
 Genetic operators (mutation, recombination)
 Parameter settings (practice and art)
( Parameters that affect GA are initial population, size of the
population, selection process and fitness function)
GA terminology
 GA chromosomes are strings of genes
 Each gene has a number of alleles; i.e.,
settings
 Each chromosome is an encoding of a
solution to a problem

 A population of such chromosomes is


operated on by a GA
Encoding
 A data structure for representing candidate
solutions
 Often takes the form of a bit string

 Usually has internal structure; i.e., different


parts of the string represent different
aspects of the solution)
Crossover
 Mimics biological recombination
 Some portion of genetic material is swapped
between chromosomes
 Typically the swapping produces an offspring

 Mechanism for the dissemination of


“building blocks” (schemas)
Mutation
 Selects a random locus – gene location –
with some probability and alters the allele
at that locus

 The intuitive mechanism for the


preservation of variety in the population
Fitness
 A measure of the goodness of the organism

 Expressed as the probability that the organism


will live another cycle (generation)

 Basis for the natural selection simulation


 Organisms are selected to mate with
probabilities proportional to their fitness

 Probabilistically better solutions have a better


chance of conferring their building blocks to
the next generation (cycle)
A Simple GA
Generate initial population
do
Calculate the fitness of each member
// simulate another generation
do
Select parents from current population
Perform crossover add offspring to the
new population
while new population is not full

Merge new population into the current


population

Mutate current population

while not converged


How do GAs work
 The structure of a GA is relatively simple
to comprehend, but the dynamic behavior
is complex
 “GAs work by discovering, emphasizing,
and recombining good ‘building blocks’ of
solutions in a highly parallel fashion.”
 Using formalism
 Notion of a building block is formalized as a
schema
 Schemas are propagated or destroyed
according to the laws of probability
Schema
 A template, much like a regular
expression, describing a set of strings
 The set of strings represented by a given
schema, characterizes a set of candidate
solutions sharing a property
 This property is the encoded equivalent of
a building block
Example
 0 or 1 represents a fixed bit

 Asterisk represents a “don’t care”

 11****00 is the set of all solutions


encoded in 8 bits, beginning with two ones
and ending with two zeros

 Solutions in this set all share the same


variants of the properties encoded at these
loci
Schema qualifiers
 Length
 The inclusive distance between the two bits
in a schema which are furthest apart
(the defining length of the previous example is 8)

 Order
 The number of fixed bits in a schema

(the order of the previous example is 4)


Not just sum of the parts
 GAs explicitly evaluate and operate on
whole solutions

 GAs implicitly evaluate and operate on


building blocks
 Existing schemas may be destroyed or
weakened by crossover
 New schemas may be spliced together from
existing schema
Why do they work
 Schemas can be destroyed or conserved

 So how are good schemas propagated


through generations?
 Conserved – good – schemas confer higher
fitness on the offspring inheriting them

 Fitter offspring are probabilistically more


likely to be chosen to reproduce
Approximating schema dynamics
 Let H be a schema with at least one instance
present in the population at time t
 Let m(H, t) be the number of instances of H at
time t
 Let x be an instance of H and f(x) be its fitness
 The expected number of offspring of x is
f(x)/f(pop) (by fitness proportionate selection)
 To know E(m(H, t +1)) (the expected number
of instances of schema H at the next time
unit), sum f(x)/f(pop) for all x in H
 GA never explicitly calculates the average
fitness of a schema, but schema
proliferation depends on its value
Approximating schema dynamics
 Approximation can be refined by taking
into account the operators

 Schemas of long defining length are less


likely to survive crossover
 Offspring are less likely to be instances of
such schemas

 Schemas of higher order are less likely to


survive mutation
Implications
 Instances of short, low-order schemas whose
average fitness tends to stay above the mean
will increase exponentially
 Changing the semantics of the operators can
change the selective pressures toward
different types of schemas

Lemmas to the Schema Theorem


 Selection focuses the search
 Crossover combines good schemas
 Mutation is the insurance policy
Simple Genetic Algorithm
{
initialize population;
evaluate population;
while TerminationCriteriaNotSatisfied
{
select parents for reproduction;
perform recombination and mutation;
evaluate population;
}
}
The GA Cycle of Reproduction
children
reproduction modification
modified
parents children
population evaluation
evaluated children
deleted
members

discard
Population
population
Chromosomes could be:
 Bit strings (0101 ... 1100)
 Real numbers (43.2 -33.1 ... 0.0 89.2)
 Permutations of element (E11 E3 E7 ... E1 E15)
 Lists of rules (R1 R2 R3 ... R22 R23)
 Program elements (genetic programming)
 ... any data structure ...
Reproduction
children
reproduction

parents

population

Parents are selected at random with


selection chances biased in relation to
chromosome evaluations.
Chromosome Modification
children
modification
modified children

 Modifications are stochastically triggered


 Operator types are:
 Mutation

 Crossover (recombination)
Mutation: Local Modification
Before: (1 0 1 1 0 1 1 0)
After: (0 1 1 0 0 1 1 0)

Before: (1.38 -69.4 326.44 0.1)


After: (1.38 -67.5 326.44 0.1)

 Causes movement in the search space


(local or global)
 Restores lost information to the population
Crossover: Recombination
*
P1 (0 1 1 0 1 0 0 0) (0 1 0 0 1 0 0 0) C1
P2 (1 1 0 1 1 0 1 0) (1 1 1 1 1 0 1 0) C2

Crossover is a critical feature of genetic


algorithms:
 It greatly accelerates search early in
evolution of a population
 It leads to effective combination of
schemata (sub solutions on different
chromosomes)
Evaluation
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
Deletion
population
discarded members

discard

 Generational GA:
entire populations replaced with each
iteration
 Steady-state GA:
a few members replaced each generation
Generational GA
 All parents reproduce at the same time
 Offspring generation replaces parent
generation
Current Parent (temporary) Offspring

: : :
Steady State GA
 Fewer offspring generated and replace
parents or other members of population

Current population
Select
parents

Generate one
or more offspring
:

Offspring replace
population member
Population Initialization

Start with a population of randomly


generated individuals, or use
- A previously saved population
- A set of solutions provided by
a human expert
- A set of solutions provided by
another heuristic algorithm
Parent Selection

 Selection is a procedure of picking parent chromosome to


produce off-spring.
 Types of selection:
 Random Selection – Parents are selected randomly from the
population.
 Proportional Selection – probabilities for picking each
chromosome is calculated

 Rank Based Selection – This method uses ranks instead of


absolute fitness values.

o Purpose: to focus the search in promising regions of the


space
 Inspiration: Darwin’s “survival of the fittest”
 Trade-off between exploration and exploitation of the search
space
How to select these chromosomes
o Selection Methods
o Fitness Proportionate Selection
o Roulette wheel selection
o Rank selection
o Steady state selection
o Tournament selection
o Others..
Fitness Proportionate Selection

A simple selection method is each individual, i,


has the probability
Fitness(i) / sum_over_all_individuals_j Fitness(j)

where Fitness(i) is the fitness function value


for individual i.
Roulette Wheel Selection

Imagine a roulette wheel where are placed all


chromosomes in the population, every has its place big
accordingly to its fitness function, like on the following
picture.

Chromosome Fitness % of total


1 6.82 31
2 1.11 5
3 8.48 38
4 2.57 12
5 3.08 14
Total 22.0 100
Roulette Wheel Selection ( cont..)
Let i = 1, where i denotes chromosome index;
Calculate P(xi) using proportional selection;
 Calculate sum of all chromosome fitness in population -
sum S.
 Generate random number from interval (0,S) - r.

sum = P(xi);
while sum < r do
i = i + 1; i.e. next chromosome
sum = sum + P(xi);
end
return xi as one of the selected parent;
repeat until all parents are selected

Drawback:
If the best chromosome fitness is 90% of all the roulette
wheel then the other chromosomes will have very few
chances to be selected
Rank Selection

 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).

Situation before ranking (graph of fitnesses)


Rank Selection ( cont..)

Situation after ranking (graph of order numbers)

Drawback:
This method can lead to slower convergence, because the best
chromosomes do not differ so much from other ones.
Steady-State Selection

 Main idea of this selection is that big part of


chromosomes should survive to next
generation.

 GA then works in a following way.


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.
Tournament Selection

 Binary tournament
 Two individuals are randomly chosen; the
fitter of the two is selected as a parent
 Probabilistic binary tournament
 Two individuals are randomly chosen; with a
chance p, 0.5<p<1, the fitter of the two is
selected as a parent
 Larger tournaments
 n individuals are randomly chosen; the fittest
one is selected as a parent
 By changing n and/or p, the GA can be adjusted
dynamically
Reproduction
 Reproduction operators
 Crossover
 Mutation
 Crossover
 Two parents produce two offspring
 There is a chance that the chromosomes of the two
parents are copied unmodified as offspring
 There is a chance that the chromosomes of the two
parents are randomly recombined (crossover) to form
offspring
 Generally the chance of crossover is between 0.6 and
1.0
 Mutation
 There is a chance that a gene of a child is changed
randomly
 Generally the chance of mutation is low (e.g. 0.001)
Crossover
 Performed on two chromosomes as parents
 The probability of parents being crossed
over is given by crossover rate
 Crossover points are randomly selected
 Exchanges genetic code between parents to
create two new chromosomes as offspring
 Commonly used crossover
 One-point crossover
 Two-point crossover
 Uniform crossover
One-Point Crossover
 Only one crossover point is selected
for each parent

Parent 1: 11011100 11000110Offspring 1


Parent 2: 01100110 01111100Offspring 2

Crossover point
One-Point Crossover

 Advantages
 Simple to implement
 Little disruption on evolved schemas
 Weakness
 Cannot combine many schemas

1 * * * 1 1
1 0 0 * 1 1
* 0 0 * * *
Two-Point Crossover
 Two crossover points are selected
for each parent

Parent 1 11011100 11000100 Offspring 1

Parent 2 01100110 01111110 Offspring 2

Crossover Points
Two-Point Crossover
 Advantage
 More likely to combine schemas
(downside: more likely to disrupt
existing schemas)

1 * * * 1 1
1 0 0 * 1 1
* 0 0 * * *
Uniform Crossover
 Every gene can be swapped between
the parents independent of the other
genes
 The probability of swapping genes is
fixed at P0
 No need to select crossover points
Parent 1 11011100 11001110 Offspring 1

Parent 2 01100110 01110100 Offspring 2


Positional/Defining Length Bias
 Defining length
 The distance of two remotest genes defined in a
schema
1 0 0 * 1 1 Defining length = 5
 Formation and disruption of a schema depends on its
defining length or its locations in the chromosome
 One-point crossover has positional/defining length
bias
 Schemas with longer defining length are more
likely to be disrupted
 Uniform crossover has no positional/defining
length bias
 Each pair of genes has the same probability of
being swapped independent of its location
Distribution Bias
 The number of genes to be swapped may be
distributed around a particular value instead of
uniformly from 1 to L-1 (L = individual length)
 One-point crossover has no distribution bias
 Crossover point is selected randomly within the
chromosome
 Uniform crossover has high distribution bias
 The number of genes to be swapped depends on
P0
Mutation
 Involves only one chromosome
 Applies to each gene individually
 The value of a mutated gene is flipped

11011100 11011000
 The probability of a gene being mutated is
controlled by mutation rate M
 The mutation rate per chromosome = M * L
 Low mutation rate: low exploration power
 High mutation rate: too disruptive
Implementation Variations
 Varying rates of Crossover/Mutation
 Start with low mutation rate and increase afterwards
 Start with high crossover rate and decrease afterwards
 Adaptive crossover and mutation rates
 Adjust rates under certain conditions
 Problem dependent variations
 Random crossover for variable length GAs
 Crossover points can be selected separately for
parents
 Creates offspring with different lengths from their
parents
Parent 1 Offspring 1
Parent 2 Offspring 2
Other Genetic Operators
 Inversion

412305

214305
• Transposition
412305

305412
A Simple Example

The Traveling Salesman Problem:

Find a tour of a given set of cities so


that
 each city is visited only once
 the total distance traveled is minimized
Representation
Representation is an ordered list of city
numbers known as an order-based GA.

2) London 3) Dunedin 5) Beijing


4) Singapore 6) Phoenix

CityList1 (3 5 2 6 4)
CityList2 (2 5 6 3 4)
Initial Population for TSP

(5,3,4,6,2) (2,4,6,3,5) (4,3,6,5,2)

(2,3,4,6,5) (4,3,6,2,5) (3,4,5,2,6)

(3,5,4,6,2) (4,5,3,6,2) (5,4,2,3,6)

(4,6,3,2,5) (3,4,2,6,5) (3,6,5,2,4)


Select Parents

(5,3,4,6,2) (2,4,6,3,5) (4,3,6,5,2)

(2,3,4,6,5) (4,3,6,2,5) (3,4,5,2,6)

(3,5,4,6,2) (4,5,3,6,2) (5,4,2,3,6)

(4,6,3,2,5) (3,4,2,6,5) (3,6,5,2,4)

Try to pick the better ones.


Create Off-Spring – 1 point

(5,3,4,6,2) (2,4,6,3,5) (4,3,6,5,2)

(2,3,4,6,5) (4,3,6,2,5) (3,4,5,2,6)

(3,5,4,6,2) (4,5,3,6,2) (5,4,2,3,6)

(4,6,3,2,5) (3,4,2,6,5) (3,6,5,2,4)

(3,4,5,6,2)
Create More Offspring

(5,3,4,6,2) (2,4,6,3,5) (4,3,6,5,2)

(2,3,4,6,5) (4,3,6,2,5) (3,4,5,2,6)

(3,5,4,6,2) (4,5,3,6,2) (5,4,2,3,6)

(4,6,3,2,5) (3,4,2,6,5) (3,6,5,2,4)

(3,4,5,6,2) (5,4,2,6,3)
Mutate

(5,3,4,6,2) (2,4,6,3,5) (4,3,6,5,2)

(2,3,4,6,5) (4,3,6,2,5) (3,4,5,2,6)

(3,5,4,6,2) (4,5,3,6,2) (5,4,2,3,6)

(4,6,3,2,5) (3,4,2,6,5) (3,6,5,2,4)

(3,4,5,6,2) (5,4,2,6,3)
Mutate

(5,3,4,6,2) (2,4,6,3,5) (4,3,6,5,2)

(2,3,4,6,5) (2,3,6,4,5) (3,4,5,2,6)

(3,5,4,6,2) (4,5,3,6,2) (5,4,2,3,6)

(4,6,3,2,5) (3,4,2,6,5) (3,6,5,2,4)

(3,4,5,6,2) (5,4,2,6,3)
Eliminate

(5,3,4,6,2) (2,4,6,3,5) (4,3,6,5,2)

(2,3,4,6,5) (2,3,6,4,5) (3,4,5,2,6)

(3,5,4,6,2) (4,5,3,6,2) (5,4,2,3,6)

(4,6,3,2,5) (3,4,2,6,5) (3,6,5,2,4)

(3,4,5,6,2) (5,4,2,6,3)
Tend to kill off the worst ones.
Integrate

(5,3,4,6,2) (2,4,6,3,5) (5,4,2,6,3)

(3,4,5,6,2) (2,3,6,4,5) (3,4,5,2,6)

(3,5,4,6,2) (4,5,3,6,2) (5,4,2,3,6)

(4,6,3,2,5) (3,4,2,6,5) (3,6,5,2,4)


Restart

(5,3,4,6,2) (2,4,6,3,5) (5,4,2,6,3)

(3,4,5,6,2) (2,3,6,4,5) (3,4,5,2,6)

(3,5,4,6,2) (4,5,3,6,2) (5,4,2,3,6)

(4,6,3,2,5) (3,4,2,6,5) (3,6,5,2,4)


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
 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
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
Some GA Application Types

Domain Application Types


Control gas pipeline, pole balancing, missile evasion, pursuit

Design semiconductor layout, aircraft design, keyboard


configuration, communication networks
Scheduling manufacturing, facility scheduling, resource allocation

Robotics trajectory planning

Machine Learning designing neural networks, improving classification


algorithms, classifier systems
Signal Processing filter design

Game Playing poker, checkers, prisoner’s dilemma

Combinatorial set covering, travelling salesman, routing, bin packing,


graph colouring and partitioning
Optimization
Genetic Algorithms

 Facts
 Very robust but slow
 In the limit, optimal

You might also like