Evolutionary Algorithms Overview
Evolutionary Algorithms Overview
.in
rs
de
SC – GA – Introduction
ea
• Search Optimization Algorithms
yr
.m
w
w
Fig. below shows different types of Search Optimization algorithms.
,w
ty
or
ab
Search
kr
ha
Optimization
C
C
R
Indirect Direct
method Uninformed Informed
method
Search Search
Newton Finonacci
Genetic Genetic
Programming Algorithms
07
fo
.in
rs
de
SC – GA - Introduction
ea
1.3 Evolutionary Algorithm (EAs)
yr
.m
w
w
Evolutionary Algorithm (EA) is a subset of Evolutionary Computation (EC) which is
,w
ty
or
Computation.
-GAs simulate natural evolution, mimicking processes the nature uses :
Development History
EC = GP + ES + EP + GA
Evolutionary Genetic Evolution Evolutionary Genetic
Computing Programming Strategies Programming Algorithms
ea
• Biological Background – Basic Genetics
yr
.m
w
w
‡ Every organism has a set of rules, describing how that organism is built.
,w
ty
‡ Possible settings for a trait (e.g. blue, brown) are called alleles.
‡ Each gene has its own position in the chromosome called its locus.
‡ The physical expression of the genotype (the organism itself after birth) is
called the phenotype, its physical and mental characteristics, such as eye
color, intelligence etc.
‡ When two organisms mate they share their genes; the resultant offspring
may end up having half the genes from one parent and half from the
other. This process is called recombination (cross over) .
‡ The new created offspring can then be mutated. Mutation means, that
the elements of DNA are a bit changed. This changes are mainly caused
by errors in copying genes from parents.
10
fo
.in
rs
de
SC – GA - Introduction
ea
[ continued from previous slide - Biological background ]
yr
.m
w Below shown, the general scheme of in genetic
w
,w
ty
Parents
C
C
Parents
R
Initialization
Recombination
Population
Mutation
Termination
Offspring
Survivor
Fig. General Scheme of Evolutionary process
Pseudo-Code
BEGIN
INITIALISE population with random candidate solution.
1. SELECT parents;
2. RECOMBINE pairs of parents;
3. MUTATE the resulting offspring;
4. SELECT individuals or the next generation;
END.
11
fo
.in
rs
de
SC – GA - Introduction
ea
• Search Space
yr
.m
w
w
In solving problems, some solution will be the best among others. The space
,w
ty
or
of all feasible solutions (among which the desired solution resides) is called
ab
kr
In using GA, the process of finding solutions generates other points (possible
solutions) as evolution proceeds.
12
fo
.in
rs
de
SC – GA - Introduction
ea
• Working Principles
yr
.m
w
w
Before getting into GAs, it is necessary to explain few terms.
,w
ty
or
ab
genes.
C
C
R
problem specific.
Breeding : taking two fit individuals and then intermingling there
Working principles :
Genetic algorithm begins with a set
of solutions (representedby chromosomes) called the
population.
Solutions from one population are taken and used to form a new population.
This is motivated by the possibility that the new population will be better than
the old one.
Solutions are selected according to their fitness to form new solutions
13
SC – GA - Introduction
• Outline of the Basic Genetic Algorithm
1. [Start] Generate random population of n chromosomes (i.e. suitable
solutions for the problem).
2. [Fitness] Evaluate the fitness f(x) of each chromosome x in the
population.
3. [New population] Create a new population by repeating following
S teps until the new population is complete.
(a)[Selection] Select two parent chromosomes from a population
according to their fitness (better the fitness, bigger the chance to be
selected)
(b)[Crossover] With a crossover probability, cross over the parents to form
new offspring (children). If no crossover was performed, offspring is the
exact copy of parents.
(c)[Mutation] With a mutation probability, mutate new offspring at
each locus (position in chromosome).
(d) Place new offspring in the new population
4. [Accepting] new generated population for a further run of the
[Replace]
5. Use
algorithm
6. [Test] If the end condition is satisfied, stop, and return the best solution in
current population
[Loop] Go to step 2
ea
• Flow Chart for Genetic Programming
yr
.m
w
w
,w
Start
ty
or
ab
kr
ha
Seed Population
C
Genesis
C
Generate N individuals
R
No
Reproduction Use crossover operator
Recombination to produce off- springs Crossover
Yes
Survival of Fittest
Natural Select one off-spring
Apply replacement Yes No
operator to incorporate Selection
new individual into
population
Apply Mutation operator
Mutation to produce Mutated
offspring
No
Terminate?
Mutation Scoring : assign
Finished? fitness to off- spring
Yes
Finish
ea
2. Encoding
yr
.m
w
Before a genetic algorithm can be put to work on any problem, a method is needed to
w
,w
ty
process.
ha
C
of 1's and 0's, where the digit at each position represents some the value of
aspect of the solution.
Example :
A Gene represents some data (eye color, hair color, sight, etc.). A
chromosome is an array of genes. In binary form
a Gene looks like : (11100010)
16
fo
.in
rs
de
SC – GA - Encoding
ea
• Binary Encoding
yr
.m
w
w
Binary encoding is the most common to represent information contained. In
,w
ty
or
Chromosome 1: 1 0 1 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 0 1
Chromosome 2: 1 1 1 1 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1
This encoding is often not natural for many problems and sometimes
Example 1:
17
fo
.in
rs
de
SC – GA – Encoding
ea
[ continued binary encoding ]
yr
.m
w
w Example 2 :
,w
Xi Xi
R
Because 4-bit string can represent integers from 0 to 15,
so (0000 0000) and (1111 1111) represent the points for X1 , X2 as
( X L , L ) and U
( X1 , X
U
2
) respectively.
1 X 2
1 x 23 = 8
2 k Sk
k=0
10
where Si can be 0 or 1 and the
string S is represented as
Sn-1 . . . . S3 S2 S1 S0
23 x 0 + 22 x 1 + 21 x 1 + 20 x 1 = 7
Knowing L
and U
corresponding to (0000) and (1111) ,
X X
i i
(X U − Xi
L
)
i
Xi L + --------------- x (decoded value of string)
=X i
( 2ni − 1 )
4-bit string Xi = (1010) would represent. First get decoded value for
Si = 1010 = 23 x 1 + 22 x 0 + 21 x 1 + 20 x 0 = 10 then
(17 -2)
Xi = 2 + ----------- x 10 = 12
(24 - 1)
ea
• Value Encoding
yr
.m
w
w
The Value encoding can be used in problems where values such as real
,w
ty
or
numbers are used. Use of binary encoding for this type of problems would be
ab
kr
ha
difficult.
C
C
R
Chromosome B ABDJEIFJDHDIERJFDLDFLFEGT
19
fo
.in
rs
de
SC – GA – Encoding
ea
• Permutation Encoding
yr
.m
w
w
Permutation encoding can be used in ordering problems, such as traveling
,w
ty
or
Examples :
20
fo
.in
rs
de
SC – GA - Encoding
ea
• Tree Encoding
yr
.m
w
w
Tree encoding is used mainly for evolving programs or expressions. For
,w
ty
or
genetic programming :
ab
kr
be encoded in trees.
The crossover and mutation can be done relatively easy way .
Example :
Chromosome A Chromosome B
+
do untill
x /
step wall
5 y
ea
3. Operators of Genetic Algorithm
yr
.m
w
w
Genetic operators used in genetic algorithms maintain genetic
,w
ty
or
Genetic operators are analogous to those which occur in the natural world:
C
C
In addition to these operators, there are some parameters of GA. One important
parameter is Population size.
Population size says how many chromosomes are in population (in one
generation).
If there are only few chromosomes, then GA would have a few possibilities to
Research shows that after some limit, it is not useful to increase population
size, because it does not help in solving the problem faster. The population size
depends on the type of encoding and the problem.
22
fo
.in
rs
de
SC – GA – Operators
ea
3.1 Reproduction, or Selection
yr
.m
w
w
Reproduction is usually the first operator applied on population. From the
,w
ty
or
offspring.
ha
C
C
R
According to Darwin's evolution theory "survival of the fittest" – the best ones
should survive and create new offspring.
Many reproduction operators exists and they all essentially do same thing. They
pick from current population the strings of above average and insert their multiple
copies in the mating pool in a probabilistic manner.
Tournament selection,
The Roulette wheel and Boltzmann selections methods are illustrated next.
23
fo
.in
rs
de
SC – GA – Operators
ea
• Example of Selection
yr
.m
w
w
,w
[Link] parents (two individuals) for crossover based on their fitness in pi.
Out of many methods for selecting the best
n
in the population is
chromosomes, pi = F i / (if Fj) , where
j=1
roulette-wheel selection is used, then the probability of the i th string
F i is fitness for the string i in the population, expressed as f(x) pi is
24
fo
.in
rs
de
SC – GA – Operators
ea
• Roulette wheel selection (Fitness-Proportionate Selection)
yr
.m
w
w
,w
recombination.
C
C
R
In fitness-proportionate selection :
the chance of an individual's being selected is proportional to its fitness,
Cumulative Probability5 = pi
i=1
25
fo
.in
rs
de
SC – GA – Operators
ea
• Boltzmann Selection
yr
.m
w
w
Simulated annealing is a method used to minimize or maximize a function.
,w
ty
or
ab
This method simulates the process of slow cooling of molten metal to achieve
kr
ha
C
Thus, by controlling the temperature T and assuming that the search process
26
fo
.in
rs
de
SC – GA – Operators
ea
2. Crossover
yr
.m
w
w
Crossover is a genetic operator that combines (mates) two chromosomes
,w
ty
or
crossover is that the new chromosome may be better than both of the
C
C
R
parents if it takes the best characteristics from each of the parents. Crossover
occurs during evolution according to a user-definable crossover probability.
Crossover selects genes from parent chromosomes and creates a new
offspring.
the others are Two Point, Uniform, Arithmetic, and Heuristic crossovers.
The operators are selected based on the way chromosomes are encoded.
27
x2 example: selection
X2 example: crossover
X2 example: mutation
fo
.in
rs
de
SC – GA – Operators
ea
• One-Point Crossover
yr
.m
w
w
One-Point crossover operator randomly selects one crossover point and then
,w
ty
or
copy everything before this point from the first parent and then everything
ab
kr
ha
after the crossover point copy from the second parent. The Crossover would
C
C
R
Parent 1 11011|00100110110
Parent 2 11011|11000011110
28
fo
.in
rs
de
SC – GA – Operators
ea
• Two-Point Crossover
yr
.m
w
w
Two-Point crossover operator randomly selects two crossover points within a
,w
ty
or
Parent 1 11011|0010011|011 0
Parent 2 11011|1100001|111 0
29
fo
.in
rs
de
SC – GA – Operators
ea
• Uniform Crossover
yr
.m
w
w
Uniform crossover operator decides (with some probability – know as the
,w
ty
or
mixing ratio) which parent will contribute how the gene values in the
ab
kr
ha
chromosomes to be mixed at the gene level rather than the segment level (as
with one and two point crossover).
Parent 1 1 1 0 1 1 0 0 1 0 0 1 1 0 1 1 0
Parent 2 1 1 0 1 1 1 1 0 0 0 0 1 1 1 1 0
If the mixing ratio is 0.5 approximately, then half of the genes in the offspring
will come from parent 1 and other half will come from parent 2. The possible
set of offspring after uniform crossover would be:
Offspring 1 11 12 02 11 11 12 12 02 01 01 02 11 12 11 11 02
Offspring 2 12 11 01 12 12 01 01 11 02 02 11 12 01 12 12 01
Note: The subscripts indicate which parent the gene came from.
30
fo
.in
rs
de
SC – GA – Operators
ea
• Arithmetic
yr
.m
w
w
Arithmetic crossover operator linearly combines two parent chromosome
,w
ty
or
* * * *
C
R
31
fo
.in
rs
de
SC – GA – Operators
ea
• Heuristic
yr
.m
w
w
Heuristic crossover operator uses the fitness values of the two parent
,w
ty
or
Offspring2 = BestParent
where r is a random number between 0 and 1.
32
fo
.in
rs
de
SC – GA – Operators
ea
3.3 Mutation
yr
.m
w
w
After a crossover is performed, mutation takes place.
,w
ty
or
Mutation alters one or more gene values in a chromosome from its initial state.
This can result in entirely new gene values being added to the gene pool. With the
new gene values, the genetic algorithm may be able to arrive at better solution
than was previously possible.
The operators are selected based on the way chromosomes are encoded .
33
fo
.in
rs
de
SC – GA - Operators
ea
• Flip Bit
yr
.m
w
w
The mutation operator simply inverts the value of the chosen gene.
,w
ty
or
mutation operator
Consider the two original off-springs selected for mutation.
Original offspring 1 1 1 0 1 1 1 1 0 0 0 0 1 1 1 1 0
Original offspring 2 1 1 0 1 1 0 0 1 0 0 1 1 0 1 1 0
34
fo
.in
rs
de
SC – GA - Operators
ea
• Boundary
yr
.m
w The mutation operator replaces the value of the chosen gene with either the
w
,w
ty
This mutation operator can only be used for integer and float genes.
ha
C
C
R
• Non-Uniform
The mutation operator increases the probability such that the amount of the
mutation will be close to 0 as the generation number increases. This mutation
operator prevents the population from stagnating in the early stages of the
evolution then allows the genetic algorithm to fine tune the solution in the
later stages of evolution.
This mutation operator can only be used for integer and float genes.
• Uniform
The mutation operator replaces the value of the chosen gene with a uniform
random value selected between the user-specified upper and lower bounds
for that gene.
This mutation operator can only be used for integer and float genes.
• Gaussian
The mutation operator adds a unit Gaussian distributed random value to the
chosen gene. The new gene value is clipped if it falls outside of the user-
specified lower or upper bounds for that gene.
This mutation operator can only be used for integer and float genes.
35
fo
.in
rs
de
SC – GA – Examples
ea
4. Basic Genetic Algorithm :
yr
.m
w
w
Examples to demonstrate and explain : Random population, Fitness, Selection,
,w
ty
or
•
C
Example 1 :
C
R
Maximize the function f(x) = x2 over the range of integers from 0 . . . 31.
ea
[ continued from previous slide ]
yr
.m
w Genetic Algorithm Approach to problem - Maximize the function f(x) = x2
w
,w
ty
or
2. heuristic for evaluating the fitness of any particular solution : The function
R
f(x) is simple, so it is easy to use the f(x) value itself to rate the fitness of a
solution; else we might have considered a more simpler heuristic that would
more or less serve the same purpose.
3. Coding - Binary and the String length :
GAs often process binary representations of solutions. This works well, because
crossover and mutation can be clearly defined for binary solutions. A Binary string
of length 5 can represents 32 numbers (0 to 31).
4. Randomly generate a set of solutions :
ea
6. Produce a new
yr
.m
generation of
w
w
solutions by
,w
existing
ab
kr
ha
pool of solutions
C
C
R
Random number generator decides for us to mate the first two strings together
and the second two strings together.
8. Within each pair swap parts of the members solutions to create offspring
1100 0 1 1 0 0 |0 11
001
110 00 , 10011
For the second pair of strings:
We randomly select the crossover point to be after the second digit. Crossing
10011 1 0 |0 1 1 10000
38
fo
.in
rs
de
SC – GA – Examples
ea
9. Randomly mutate
yr
.m
a very small
w
w
fraction of genes in
,w
the population :
ty
or
ab
With a typical
kr
ha
10. Go back and re-evaluate fitness of the population (new generation) : This
C
mutation probability
C
R
Observe that :
[Link] populations : At start step 5 were
01101, 11000, 01000,10011
[Link] total fitness has gone from 1170 to 1754 in a single generation.
[Link] algorithm has already come up with the string 11011 (i.e x = 27) as a
possible solution.
39
fo
.in
rs
de
SC – GA – Examples
ea
• Example 2 : Two bar pendulum
yr
.m
w
w
Two uniform bars are connected by pins at A and B and supported force
,w
ty
or
ℓ1
1 Find : Equilibrium configuration of the system if fiction at
B all joints are neglected ?
ℓ2 C
2
P Solution : Since there are two unknowns 1 and
2 , we use 4 – bit binary for each unknown.
W1
XU - XL 90 - 0
W2 Accuracy = ----------- = --------- = 60
24 - 1 15
Fig. Two bar pendulum
Hence, the binary coding and the corresponding angles Xi are given as
XiU - XiL
th
Xi = XiL + ----------- Si where Si is decoded Value of the i
chromosome.
2 - 1
4
e.g. the 6th chromosome binary code (0 1 0 1) would have the corresponding
angle given by Si = 0 1 0 1 = 23 x 0 + 22 x 1 + 21 x 0 + 20 x 1 = 5
90 - 0
Xi = 0 + ----------- x 5 = 30
15
The binary coding and the angles are given in the table below.
∏ = - P[(ℓ1 sin1 + ℓ2 sin2 )] - (W1 ℓ1 /2)cos1 - W2 [(ℓ2 /2) cos2 + ℓ1 cos1] (Eq.1)
ea
[ continued from previous slide ]
yr
.m
w First randomly generate 8 population with 8 bit strings as shown in table below.
w
,w
ty
1 ,
ha
2
C
C
1 0 0 0 0 0 0 0 0 0 0 1
R
2 0 0 1 0 0 0 0 0 12 6 2.1
3 0 0 0 1 0 0 0 0 6 30 3.11
4 0 0 1 0 1 0 0 0 12 48 4.01
5 0 1 1 0 1 0 1 0 36 60 4.66
6 1 1 1 0 1 0 0 0 84 48 1.91
7 1 1 1 0 1 1 0 1 84 78 1.93
8 0 1 1 1 1 1 0 0 42 72 4.55
These angles and the corresponding to fitness function are shown below.
ea
5. References : Textbooks
yr
.m
w
w
1. "Genetic Algorithms in Search, Optimization, and Machine Learning", by David E.
,w
Chapter 1- 6,
ha
page 1- 203,
C
C
R
4. "Genetic algorithms and engineering design", by Mitsuo Gen, and Runwei Cheng,
(1997), John Wiley & Sons Inc, chapter 1- 10, page 1-411.
5. "Practical genetic algorithms", by Randy L. Haupt, (2004), John Wiley & Sons Inc,
Chapter 1- 7, page 1- 251.
6. Related documents from open source, mainly internet. An exhaustive list is being
prepared for inclusion at a later date.
42