Lecture 6 Genetic Algorithms
Lecture 6 Genetic Algorithms
GENETIC ALGORITHM
LOCAL SEARCH AND GA
Local search methods involve making small changes to potential solutions to a problem until an optimal solution
is identified.
Genetic Algorithm (GA) is a search-based optimization technique based on the principles of Natural
Genetics and Natural Selection.
It finds the Optimal Solution based in survival of the fittest.
Optimization is the process of making something better i.e. to get the “best” output value.
EVOLUTIONARY COMPUTING
Over time, the entire population of the ecosystem is said to evolve to contain organisms that, on average, are
fitter for environment than those of previous generations of the population
4
GENETIC ALGORITHMS
5
GENETIC ALGORITHM
Reproduction Competition
Survive Selection
9
ENCODING TECHNIQUES
Binary
Value
Permutations
Tree
REPRESENTATION OF STATES (SOLUTION)
The best solutions are more likely to survive and more likely to produce
even better solutions
EVALUATION AND SELECTION
We then see how good the solutions are, using an evaluation function (recall f(n) in
infomed search)
The final population can then be evaluated more deeply to decide on the best solution
13
SURVIVAL OF THE FITTEST
Likelihood of survival is related in some way to your score on the fitness function
The most common technique is roulette wheel selection
Fitness Based
Roulette Wheel Selection
Ordinal Based
Ranking Selection
Tournament Selection
Threshold Based
Truncation Selection
GENETIC OPERATORS
These operators mimic what happens to our genetic material when we reproduce
Crossover
Mutation
16
CROSSOVER OPERATOR
Cut two solutions at a random point and switch the respective parts
Typically a value of 0.7 for crossover probability gives good results.
a1 a2 a3 a4 a5 a6 b1 b2 b3 b4 b5 b6
a1 a2 a3 a4 b5 b6 b1 b2 b3 b4 a5 a6
17
CROSSOVER
CROSSOVER OPERATOR
The crossover operator is applied to two chromosomes of the same length as follows:
1. Select a random crossover point.
2. Break each chromosome into two parts, splitting at the crossover point.
3. Recombine the broken chromosomes by combining the front of one with the back of the other, and vice versa, to
produce two new chromosomes.
For example, consider the following two chromosomes:
110100110001001
010101000111101
MUTATION OPERATOR
a1 a2 a3 a4 a5 a6 Mutation of a2 = b1
20
a1 b1 a3 a4 a5 a6
MUTATION
FITNESS FUNCTION (OPTIMIZATION)
1.5
0.5
0 f(x)=sin(x)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
-0.5
-1
-1.5 22
FITNESS FUNCTION (OPTIMIZATION)
Using population size of 4 chromosomes
First Generation: Generate a random population:
c1 = 1001 (9) c3 = 1010 (10)
c2 = 0011 (3) c4 = 0101 (5)
To calculate fitness of a chromosome, we calculate 𝑓(𝑥) for its decimal value
Assign fitness as a numeric value from 0 to 100
0 is the least fit
100 is the most fit.
𝑓(𝑥) generates real numbers between -1 and 1.
Assign a fitness score of 100 to 𝑓(𝑥) = 1 and fitness of 0 to 𝑓 𝑥 = −1
Fitness of 50 will be assigned to 𝑓(𝑥) = 0 23
f'(x) =
x f(x)=sin(x) 50(f(x)+1)
0
FITNESS FUNCTION (OPTIMIZATION) 1
2
Fitness of x, 𝒇′ 𝒙 :
3
4
𝑓′(𝑥) = 50(𝑓(𝑥) + 1) 5
𝑓′(𝑥) = 50(sin(𝑥) + 1) 6
7
8
22.8, 15%
3 9
57.06, 38% 5 10
70.61, 46%
9 11
10 12
2.05, 1%
13
14 24
15
FITNESS FUNCTION (OPTIMIZATION)
The range of real numbers from 0 to 100 is divided up between the chromosomes proportionally to each
chromosome’s fitness.
In first generation:
c1 has 46.3% of the range (i.e., from 0 to 46.3)
c2 37.4% of the range (i.e., from 46.4 to 83.7)
25
ROULETTE-WHEEL SELECTION
Important: Method does not stop less fit chromosomes from reproducing, to ensure that populations do not
stagnate, by constantly breeding from the same parents.
26
NEXT GENERATION
27
NEXT GENERATION CONT.
Combine first two to produce two new offspring:
Crossover point
c1 = 1001 (9) c2 = 0011 (3)
c5 = 1011 c6 = 0001 (1)
(11)
Combine last two to produce two new offspring:
Crossover point
Extremely fit
29
TERMINATION CRITERIA
Termination criteria would probably determine that c7 is the most fit (local
optimum) and the algorithm will be stopped.
30
EXAMPLE: 𝑓 𝑥 = 𝑥 2
Step 1:
Code the decision variable of the problem a binary unsigned integer of length 5.
To start we select an initial population of size 4 by tossing a fair coin times.
Fitness function is defined by 𝑓 𝑥 = 𝑥 2
EXAMPLE: 𝑓 𝑥 = 𝑥 2
String Initial Pop. 𝑥- 𝑓 𝑥 = 𝑥2
No. value
1 01101 13 169
2 11000 24 576
3 01000 8 64
4 10011 19 361
1 11101 29 841
3 10100 20 400
4 11001 25 625
Chromosome Chromosome Decoded Chro
label string integer f
X1 1 1 00 12
X2 0 1 00 4
X3 0 0 01 1
PRACTICE QUESTION X4
X5
1
0
1
1
10
11
14
7
X6 1 0 01 9
60 60
f(x)
50 50
40 40
30 30
0 0
0 5 10 15 0
x
Represent problem using chromosomes built from four genes: (a) Chromosome initial locations. (b) Chr
40 40
30 30
PRACTICE QUESTION
Use fitness ratios to determine which chromosomes are selected for crossover and mutation operations:
100 0
X1: 16.5%
X2: 20.2%
75.2 X3: 6.4%
X4: 6.4%
X5: 25.3%
36.7 X6: 24.8%
49.5 43.1