1
Introduction To Genetic Algorithms
References
2
□ D. E. Goldberg, ‘Genetic Algorithm In Search,
Optimization And Machine Learning’, NewYork:
Addison – Wesley (1989)
□ John H. Holland ‘Genetic Algorithms’, Scientific
American Journal, July 1992.
□ Kalyanmoy Deb, ‘An Introduction To Genetic
Algorithms’, Sadhana, Vol. 24 Parts 4 And 5.
Introduction to optimization
3
Global optima
Local optima
Local optima
Local optima
Local optima
X 7 November 2013
Introduction to optimization
4
Multiple optimal solutions
Genetic Algorithms
5
Genetic Algorithms are the heuristic search
and optimization techniques that mimic the
process of natural evolution.
Principle Of Natural Selection
6
“Select The
Best, Discard
The Rest”
An Example….
7
Giraffes have long necks
□ Giraffes with slightly longer necks could feed on
leaves of higher branches when all lower ones had
been eaten off.
□ They had a better chance of survival.
□ Favorable characteristic
propagated through generations
of giraffes.
□ Now, evolved species has long necks.
An Example….
8
This longer necks may have due to the effect of mutation
initially. However as it was favorable, this was propagated over
the generations.
Evolution of species
9
Initial Population of
animals
Struggle For Existence
Years
Millions Of
Survival Of the Fittest
Surviving Individuals Reproduce,
Propagate Favorable Characteristics
Evolved Species
10
Thus genetic algorithms implement
the optimization strategies by
simulating evolution of species
through natural selection
Simple Genetic Algorithms
11
Start
Initialize
population
Evaluate Solutions
T= 0 NO
Optimum
Solution?
Selection
YES
T=T+1 Stop Crossover
Mutation
7 November 2013
Simple Genetic Algorithm
12
function sga ()
{
Initialize population;
Calculate fitness function;
While(fitness value != termination criteria)
{
Selection;
Crossover;
Mutation;
Calculate fitness function;
}
}
Initial
Generation
Fitness
Next
Selection
Generation
Mutation Crossover
Let us consider an example in which we need
to find the optimum solution of F(X1,X2) .
F(X1,X2) = X12 – X22 – 5.13
The unknown parameters are X1 and X2.
Solution Space of X1 and X2 Є [ 0, 15 ]
Initial
Generation
Fitness
Next
Selection
Generation
Mutation Crossover
Initial Population
X1 X2
1001 1101
10011101
1 Complete Population
Initial Generation
1 1 0 1 1 0 1 0
0 1 1 1 1 0 1 1
1 1 1 0 1 0 1 0
0 0 0 1 1 0 1 0
0 0 1 1 0 0 0 1
1 1 0 1 1 0 0 0
1 0 1 0 1 0 1 1
1 1 1 0 0 0 1 0
1 0 1 0 0 0 1 0
0 1 1 1 1 0 1 1
Initial
Generation
Fitness
Next
Selection
Generation
Mutation Crossover
Fitness Function
Fitness Function is an Objective Function which we
need to maximize .
In our example we have considered
Fitness Function = 1/abs(X12 – X22 – 5.13)
While Choosing An Appropriate Fitness
Function
define Fitness Function in such a way so that it increases
even with searching for minima or maxima.
10011101
In the above string X1 is 9 and X2 is 13.
Therefore, the value of Fitness Function is 0.011.
In this way, the fitness values of all the populations
are calculated .
GA Operators and Parameters
13
□ Selection
□ Crossover
□ Mutation
Selection
14
The process that determines which solutions are
to be preserved and allowed to reproduce and
which ones deserve to die out.
The primary objective of the selection operator is
to emphasize the good solutions and eliminate
the bad solutions in a population while keeping
the population size constant.
“Selects the best, discards the rest”
Functions of Selection operator
15
Identify the good solutions in a population
Make multiple copies of the good solutions
Eliminate bad solutions from the population so that
multiple copies of good solutions can be placed in the
population
Now how to identify the good solutions?
Fitness function
16
A fitness value can be assigned to evaluate the solutions
A fitness function value quantifies the optimality of a solution.
The value is used to rank a particular solution against all the
other solutions
A fitness value is assigned to each solution depending on how
close it is actually to the optimal solution of the problem
Assigning a fitness value
17
Considering c = 0.0654
23 h
d
Selection operator
18
□ There are different techniques to implement
selection in Genetic Algorithms.
□ They are:
□ Tournament selection
□ Roulette wheel selection
□ Proportionate selection
□ Rank selection
□ Steady state selection, etc
Tournament selection
19
□ In tournament selection several tournaments are played
among a few individuals. The individuals are chosen at
random from the population.
□ The winner of each tournament is selected for next
generation.
□ Selection pressure can be adjusted by changing the
tournament size.
□ Weak individuals have a smaller chance to be selected if
tournament size is large.
Tournament selection
20
22 32 Selected
22 25
22 25
13 +30 25
32 22
32 40
32 22
25 13 +30
40 22
Best solution will have two copies
Worse solution will have no copies
7 +45 7 +45
Other solutions will have two, one
25 13 +30 or zero copies
25 13 +30
Roulette wheel and proportionate
21
selection
Chrom # Fitnes % of RW EC AC
s
Parents are selected 1 50 26.88172 1.612903 2
according to their 2 6 3.225806 0.193548 0
3 36 19.35484 1.16129 1
fitness values
4 30 16.12903 0.967742 1
5 36 19.35484 1.16129 1
The better 6 28 15.05376 0.903226 1
chromosomes have 186 100.00 6 6
more chances to be 6Roulet wheel
16% 1
21%
selected
2
3%
5
21%
3
21%
4 7N
18%
Selection
Before Selection After Selection
1 1 0 1 1 0 1 0 1 1 1 0 1 0 1 0
0 1 1 1 1 0 1 1 0 0 1 1 0 0 0 1
1 1 1 0 1 0 1 0 0 0 1 1 0 0 0 1
0 0 0 1 1 0 1 0 0 0 1 1 0 0 0 1
0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1
1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 0
1 0 1 0 1 0 1 1 0 0 1 1 0 0 0 1
1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 1
1 0 1 0 0 0 1 0 1 1 0 1 1 0 0 0
0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 0
Methods of Reproduction
Crossover
Mutation
How to implement crossover
24
The crossover operator is used to create new solutions from the existing solutions
available in the mating pool after applying selection operator.
This operator exchanges the gene information between the solutions in the
mating pool.
0 1 0 0 1 1 0 1 1 0
Encoding of solution is necessary so that our
solutions look like a chromosome
Source: [Link]
Crossover operator
28
The most popular The selection A probability of crossover is
crossover selects any two point is also introduced in order to
solutions strings randomly selected give freedom to an individual
from the mating pool and randomly. solution string to determine
some portion of the strings whether the solution would go
is exchanged between the for crossover or not.
strings.
Solution 1
Solution 2
Child 1
Child 2
Binary Crossover
29
Source: Deb1999
Mutation operator
30
Mutation is the occasional introduction of new features in to the
solution strings of the population pool to maintain diversity in the
population.
Though crossover has the main responsibility to search for the
optimal solution, mutation is also used for this purpose.
Before mutation After mutation
Binary Mutation
31
□ Mutation operator changes a 1 to 0 or vise versa, with a mutation
probability of .
□ The mutation probability is generally kept low for steady convergence.
□ A high value of mutation probability would search here and there like a
random search technique.
Source: Deb1999
Elitism
32
□ Crossover and mutation may destroy the best
solution of the population pool
□ Elitism is the preservation of few best
solutions of the population pool
□ Elitism is defined in percentage or in number
Nature to Computer Mapping
33
Nature Computer
Population Set of solutions
Individual Solution to a problem
Fitness Quality of a solution
Chromosome Encoding for a solution
Gene Part of the encoding solution