GA Lecture
GA Lecture
Genetic Algorithms
Max Peysakhov
About Genetic Algorithms
Initialization Initial
Population
Evaluate Evaluated
Next
Chromosomes Population
Generation Select
Chromosomes
Mutate
Candidate
Chromosomes Next
Candidate Crossover Generation
Next Chromosomes
Generation
Illustration of the Genetic Algorithm
Evaluation Function
Evaluation Function
Initial Population Final Population
Individual
Best individual solution
Representation and Initialization
You begin with a population of random bit strings.
Each bit string encodes some problem configuration.
Example: You can encode SAT problem by representing each
Boolean variable by a position in the bit string
(a0 a1 a2 ) (a0 a2 a3 ) (a0 a2 a3 ) (a2 a3 a4 ) (a0 a2 a4 )
}
1 0 1 1 0
0 1 1 0 0
1 1 1 1 0 N randomly generated
individuals (initial population)
0 0 1 0 1
1 0 1 0 1
Some Terminology
Chromosome, Individual, Genotype Configuration of the
Population member bits in the string.
}
1 0 1 0 1
1 0 1 1 0 Phenotype What genotype
represents.
0 1 1 0 0
a0 = T, a1 = F, a2 = T, a3 = F, a4 =T
1 1 1 1 0
Fitness Landscape graph of
0 0 1 0 1
Population the fitness function
1 0 1 0 1
Genes
Fitness Function
Chr 1
Chr 2
Chr 3
Chr 4
Chr 5
Chr 6
Chr 7
Chr 8
Chr 9
Chr 10
Selection: Universal Stochastic Sampling
Than using Fitness Proportional Selection it is possible
(although unlikely) that all selected individuals will have
lowest fitness.
To fix that problem USS suggests to spin N-pointer roulette
wheel only once.
Chr 1
Chr 2
Chr 3
Chr 4
Chr 5
Chr 6
Chr 7
Chr 8
Chr 9
Chr 10
Selection: Sigma Scaling
Some individuals may be much more fit then others. Their
offspring will dominate the population and can cause a
convergence on a local maximum.
Sigma Scaling is designed to keep a selections pressure
relatively constant over the run of GA.
Exp.Val = iif (Stddev = 0, 1, 1+(f(x) Mean(f)) / 2*Stddev)
Chr 1
Chr 2
Chr 3
Chr 4
Chr 5
Chr 6
Chr 7
Chr 8
Chr 9
Chr 10
Selection: Rank proportional
Same purpose as Sigma scaling.
All individuals in the population are ranked in order of their fitness.
By adjusting Max desirable constant selection pressure can be
achieved
Min + Max = 2 and 1 < Max < 2
Chr 1
Chr 2
Chr 3
Chr 4
Chr 5
Chr 6
Chr 7
Chr 8
Chr 9
Chr 10
Crossover: Single Point Crossover
Parent 1 Offspring 1
1 1 1 1 0 1 1 1 0 1
Crossover point
0 0 1 0 1 0 0 1 1 0
Parent 2 Offspring 2
Crossover: K-Point Crossover
Parent 1 Offspring 1
1 1 1 1 0 1 0 1 1 1
Crossover points
0 0 1 0 1 0 1 1 0 0
Parent 2 Offspring 2
Crossover: Uniform Crossover
Parent 1 Offspring 1
1 1 1 1 0 0 1 1 1 1
Crossover points
0 0 1 0 1 1 0 1 0 0
Parent 2 Offspring 2
Mutation
1 1 1 1 0
Mutated gene
1 1 0 1 0
Elitism
Trick that works.
Select small number of the most fit individuals.
Copy them to the new generation unchanged.
Preserve valuable members of the population
0 1 1 0 0 } Elite
1 0 1 1 0
0 1 1 0 0 } Elite
} }
1 1 1 1 0 1 0 1 0 1
1 0 1 1 0
0 0 1 0 1 Rest of the Rest of the
population population
1 0 1 0 1 1 0 1 1 1
When to Stop?
When you found an optimal solution.
When you completed the predefined number of
generations.
When time limit expired.
When population converges to a single individual.
When fitness function converges to a single value.
After some number of generations with no
improvement.
Any other ideas?
Usually use combination of 2 or 3 stopping criteria.
Simple GA
Meta-level optimization.
Employing a second GA to optimize a parameters of
the firs one.
Fitness evaluation is expensive.
Difficult to identify fitness.
Adapting control parameters.
Adapting control parameters over time.
Using problem related feedback to adjust parameters.
Messy Genetic Algorithms
Length of the chromosome may change during the
execution.
Achieved by using messy crossover operators.
Cut - cuts chromosome in arbitrary point.
Splice - joins two parts of the chromosome together.
Used then length of the solution is unknown.
Parent 1 Offspring 1
1 1 1 1 0 1 1 1 1 0 1
Cut points
0 0 1 0 1 0 0 1 0
Parent 2 Offspring 2
Genetic Programming (GP)
Formulated by Koza in 1990 as means of automatic
programming
Similar to GA but:
Chromosomes are encoded as pars trees typically
representing a computer program in Lisp
IF
(if (> x y) x y)
> X Y
X Y
GP: Initialization
Define your function set C
{+, -, *, /, ABS, if, }
Define your terminal states T
{0, 1, 2, , x, y, z, , Pi, e, }
For each population member
1. Start with empty parse tree P
2. Add Xi to P such that Xi C or Xi T
3. Repeat procedure recursively for all children of Xi
GP: Crossover
IF IF
> X Y > +
X
X Y Crossover X Y X Y
(if (> x y) x y) points (if (> x y) x (+ x y))
*
*
+ Y
Y Y
X Y
(* (+ x y) y) (* y y)
GP: Mutation
IF IF
> X Y > - Y
Mutated
X Y X Y X Y
gene
120
100
Solution quality
80 Regular
60 Algorithm
40 Anytime
20 Algorithm
0
-20
Time
Knapsack Problem
Choices:
Genetic Algorithm
Messy Genetic Algorithm
Genetic Programming
Knapsack Problem: Choosing a Representation.
Answer: Messy Genetic algorithms, because
the solution length is unknown up front.
S 0 S 1 S 2 S 3 S4 S5 S 6 S 7 S8 SN
P(s) 64 59 35 27 31 34 43 63 62 15
W(s) 13 75 32 53 83 5 7 37 41 48
Knapsack Problem: Choosing Crossover Operators.
Answer: Genotype - 0 1 5 6 2 8
Phenotype - items S0 , S1 , S5 , S6 , S2 , S8
with total weight - 326
with total value - 142
0 1 5 6 2 8 5 1 5 6 4 7 10
Can we fix it
Knapsack Problem: Choosing Evaluation Function.
5 3 2 2 8 5 3 2 8
Arrow Ratchet
Tetra Snake
Golem Project Arrow Creature
Hod Lipson and Jordan Pollack
Real Arrow
Simulated Arrow
Golem Project Tetra Creature
Hod Lipson and Jordan Pollack
Real Tetra
Simulated Tetra
Project Objectives
In this case the goal was to evolve a structure with the size of 10
Lego units in each x-y-z dimension with the minimal weight.
Left structure was created at 895 generation and has sizes 10 by 10 by
6.8
Right structure was created at 3367 generation and has sizes 10 by 10
by 10.
Both structures among the lightest possible structures that satisfy
these parameters that can be created from the set of elements
given.
Examples: Pillar-Like Dense Structure