You are on page 1of 113

CHAPTER 5:

GENETIC ALGORITHM
Intro to GA
 https://www.youtube.com/watch?v=vg1FTkWHNSg
 https://www.youtube.com/watch?v=cxweR4i0ejA
 https://www.youtube.com/watch?v=XcinBPhgT7M
 https://www.youtube.com/watch?v=uQj5UNhCPuo
&t=9s
Application of GA
 Upload a video for any application using Genetic
Algorithm.
 Upload in Padlet page given before end of class
today.
https://padlet.com/normaniha_ghani/z2kyp89s839uz
4lm
History
 Introduced in the 1960s by I. Rechenberg in his
work "Evolution strategies" (Evolutions strategie in
original).
 Genetic Algorithms (GAs) were invented by
John Holland and developed by him and his
students and colleagues. → Holland's book
"Adaption in Natural and Artificial Systems"
published in 1975.
History (2)
 In 1992 John Koza has used genetic algorithm to
evolve programs to perform certain tasks. →
"genetic programming" (GP).
 LISP programs were used.
loop
read in an expression from the console;
evaluate the expression;
print the result of evaluation to the console;
end loop.
For example, if you want to compute the value of (2 * cos(0) * (4 + 6)), you type in:

USER(1): (* 2 (cos 0) (+ 4 6))

Common LISP replies: 20.0


What is GA ?
 Genetic algorithms are a part of evolutionary
computing, which is a rapidly growing area of
artificial intelligence.
 Genetic algorithms are inspired by Darwin's theory
about evolution.
 Simply said, solution to a problem solved by genetic
algorithms is evolved.
 https://www.tutorialspoint.com/genetic_algorithms/g
enetic_algorithms_quick_guide.htm
Classes of Search Techniques

Search techniques

Calculus-based techniques Guided random search techniques Enumerative techniques

Direct methods Indirect methods Evolutionary algorithms Simulated annealing Dynamic programming

Finonacci Newton Evolutionary strategies Genetic algorithms

Parallel Sequential

Centralized Distributed Steady-state Generational


GA Algorithm
 Algorithm is started with a set of solutions
(represented by chromosomes) called population.
 Solutions from one population are taken and used
to form a newThispopulation.
is repeated until some
condition (for example number of
 This is motivated by a hope, that the new population
populations or improvement of
will be betterthe
than
bestthe old one.
solution) is satisfied.
 Solutions which are selected to form new solutions
(offspring) are selected according to their fitness -
the more suitable they are the more chances they
have to reproduce.
Outline of GA
1. [Start] Generate random population of n
chromosomes (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 steps until the new population is
complete
 [Selection]Select two parent chromosomes from a
population according to their fitness (the better fitness,
the bigger chance to be selected)
Outline of GA (2)
 [Crossover] With a crossover probability cross over the
parents to form a new offspring (children). If no
crossover was performed, offspring is an exact copy of
parents.
 [Mutation] With a mutation probability mutate new
offspring at each locus (position in chromosome).
 [Accepting] Place new offspring in a new population

4. [Replace] Use new generated population for a


further run of algorithm
5. [Test] If the end condition is satisfied, stop, and
return the best solution in current population
6. [Loop] Go to step 2
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.


Chromosome Modification
children
modification
modified children

 Modifications are done using operators below :


 Selection
 Crossover

 Mutation

 Accepting
Crossover
 Crossover selects genes from parent chromosomes
and creates a new offspring. The simplest way how
to do this is to choose randomly some crossover
point and everything before this point copy from a
first parent and then everything after a crossover
point copy from the second parent.
 Crossover can then look like this ( | is the crossover
point): • 16 genes of chromosome
• One-point Crossover
operation at point 5
Mutation
 Mutation is to prevent falling all solutions in
population into a local optimum of solved problem.
 Mutation changes randomly the new offspring. For
binary encoding we can switch a few randomly
chosen bits from 1 to 0 or from 0 to 1. Mutation can
then be following:
Evaluation

modified
evaluated children
children
evaluation

 The evaluator decodes a chromosome and assigns it a


fitness measure
Deletion
population
discarded members

discard

 Generational GA:
entire populations replaced with each iteration
 Steady-state GA:
a few members replaced each generation
GA Example

GA Example
 Evaluate the fitness of each individual. Show all
your calculations and arrange them in order with
the highest value of fitness first and the least value
of fitness last.
Population Gene
X1 (6+5) - (4*3) = -1
X2 (1+5) - (7*3) = -15
X3 (2+9) – (0*1) = 11
X4 (1+5) – (3*8) = -18

Arranging from highest value to least value → X3, X1, X2 and X4


GA Example (2)
Arranging from highest value to least value → X3, X1, X2 and X4


GA Example (3)
New offsprings (updated population)
Population Gene
(2+9) - (4*3) = -1
(6+5) - (0*1) = 11
(6+5) – (7*3) = -10
(1+5) – (4*3) = -7

Previous result ( initial population )


Population Gene
X1 (6+5) - (4*3) = -1
X2 (1+5) - (7*3) = -15
X3 (2+9) – (0*1) = 11
X4 (1+5) – (3*8) = -18
Case Study 1
GA – Case Study
 Suppose it is desired to find the maximum of the
“peak” function of two variables:
2 − x 2 −( y +1) 2 − x2 − y 2
f ( x, y) = (1 − x) e − (x − x − y ) e
3 3

where parameters x and y vary between -3 and 3.


 The first step is to represent the problem variables
as a chromosome - parameters x and y as a
concatenated binary string:
1 0 0 0 1 0 1 0 0 0 1 1 1 0 1 1

x y
GA – Case Study
 We also choose the size of the chromosome population, for
instance 6, and randomly generate an initial population.
 The next step is to calculate the fitness of each chromosome. This is
done in two stages.
 First, a chromosome, that is a string of 16 bits, is partitioned into
two 8-bit strings:
1 0 0 0 1 0 1 0 and 0 0 1 1 1 0 1 1
 Then these strings are converted from binary (base 2) to decimal
(base 10):
(10001010) 2 = 1 27 + 0  26 + 0  2 5 + 0  2 4 + 1  23 + 0  2 2 + 1  21 + 0  2 0 = (138)10
and
(00111011) 2 = 0  2 7 + 0  2 6 + 1  25 + 1  2 4 + 1  2 3 + 0  2 2 + 1 21 + 1  2 0 = (59)10
GA – Case Study

Case Study 2: Finding Maximum
Value of a Function
Finding Maximum Values of A
Function

1 0 1 1 1 1

X Y
Finding Maximum Values of A
Function (ctd)
a) Find the fitness value of each population. Arrange
from the maximum value to the minimum value.
b) For the 1st generation do the following
(i) Cross the fittest two individuals using one-point
crossover at the middle point.
(ii) Cross the second and third fittest individuals using a
two-point crossover (point’s b and d).
(iii) Find the fitness value of new population and evaluate
the performance after the 1st generation
Answer

 STEP 1 : Change the binary values to decimal


values in the given range ( -2 < x,y < 2)
Answer

Population
8.5
6.85
5.22
15.45
Answer
a) For the 1st generation do the following
(i) Cross the fittest two individuals using one-point crossover at the middle point.

(ii) Cross the second and third fittest individuals using a two-point crossover
(point’s b and d).
Answer
(iii) Find the fitness value of new population and evaluate
the performance after the 1st generation

Population Population
10.15 8.5
8.5 6.85
8.5 5.22
10.37 15.45
After 1st generation Initial Population
GA – Case Study
◼ Using decoded values of x and y as inputs in the mathematical
function, the GA calculates the fitness of each chromosome.
◼ To find the maximum of the “peak” function, we will use crossover
with the probability equal to 0.7 and mutation with the
probability equal to 0.001.
◼ As we mentioned earlier, a common practice in GAs is to specify
the number of generations.
◼ Suppose the desired number of generations is 100. That is, the
GA will create 100 generations of 6 chromosomes before
stopping.
Chromosome locations on the surface of the
“peak” function: initial population
Chromosome locations on the surface of the
“peak” function: first generation
Chromosome locations on the surface of the
“peak” function: local maximum
Chromosome locations on the surface of the
“peak” function: local maximum
Performance graphs for 100 generations of 6
chromosomes: local maximum
pc = 0.7, pm = 0.001
0. 7

0. 6

0. 5

0. 4
Fitness

0. 3

0. 2

0. 1

Best
0 Average

-0.1
0 10 20 30 40 50 60 70 80 90 100
Generations
Performance graphs for 100 generations of 6
chromosomes: global maximum
pc = 0.7, pm = 0.01
1.8

1.6

1.4

1.2
Fitness

1.0

0.8

0.6

Best
0.4 Average

0.2
0 10 20 30 40 50 60 70 80 90 100
Generations
Performance graphs for 20 generations of
60 chromosomes
pc = 0.7, pm = 0.001
1.8

1.6

1.4

1. 2
Fitness

1.0

0.8

0.6

Best
0.4 Average

0.2
0 2 46 8 10 12 14 16 18 20
Generations
Global and Local Maxima
Example Examination Question1

 Anti – lock breaking system (ABS) is a system that helps


vehicle to do emergency stop such as in slippery
conditions. There are 4 main components in it; speed
sensor, valve, pump and controllers. The speed sensor
measures the vehicle speed and valve is used to
provide sufficient pressure to the system. If the pressure
is high, then vehicle stops immediately. Using GA, we
can construct the system as follows.
◦ The chromosome can encode how ABS works. Consider only
2 inputs to the system that are the vehicle speed and the
valve. The gene is shown by using a 4 bit binary string e.g.
1011
GA – Example Question (Ctd)
◦ Each 2 of 4 different genes are representing the
vehicle speed and valve respectively.
◦ The ideal chromosome (High speed and medium pressure)
is 1101.
◦ The current consumer population is shown below
Type Chromosome
1 0001
2 0010
3 0111
4 1011
GA – Example Question (Ctd)
 Question : Calculate the fitness for above problem
using GA approach by treating ONE point for each
gene that agrees with ideal chromosome. Use
selection, crossover and mutation (if applicable) to
find the best solution that similar to ideal
chromosome.
Random Solution

Type Chromosome
1 0001
The ideal chromosome
2 0010
(High speed and medium
3 0111 pressure) is 1101.
4
4 1011
1011

Type Chromosome Fitness Reproduction probability


1 0001 2 2/6 = 0.333
2 0010 0 0/6 = 0
3 0111 2 2/6 = 0.333
4 1011 2 2/6 = 0.333
Total Fitness 6
Random Solution
 Cross-over : type 3 and 4 will be selected 2 times.
Type Chromosome Fitness Reproduction probability
1 0001 2 2/6 = 0.333
2 0010 0 0/6 = 0
3 0111 2 2/6 = 0.333
4 1011 2 2/6 = 0.333

The ideal chromosome is 1101.

Type Type operation New chromosome Fitness Reproduction probability

1’ 1 and 4 (cross-over) 0011 1 1/7 = 0.143

2’ 2 and 3 (cross-over) 0110 1 1/7 = 0.143

3’ 3 and 4 ( cross-over) 0111 2 2/7 = 0.286

4’ 3 and 4 (cross-over) 1111 3 3/7 = 0.428


Total fitness : 7
Final Solution
 Final → mutation of type 4’
1111 → 1101
The same as ideal
chromosome
Example Examination Question2
Genetic Algorithm (GA) is used for optimizing the
appropriate values of weight in a Neural Network for
solving an XOR problem with TWO (2) inputs. The
network is shown in Figure 1. A sigmoid function is
applied at the hidden and output layer. The training
data set is shown in Table 1.
The population in this problem is a collection of binary
set that represents the values of weight from input to
hidden and from hidden to output layer. The format of
the population is shown in Figure 2
W11

W11
Lk

j=1 k=1
Layer i Hidden
Layer k
Layer j

Figure 1: A Multilayer Neural Network

Table 1: Training Data Set for XOR Problem


Figure 2: Format of GA Population to Solve XOR Problem

Table 2: Initial Population / Individuals

Population Chromosome
1 0 0 0 1 0 1 1 0 1 0 0
1 1 0 0 0 1 0 1 1 1 1 1
1 1 1 1 1 0 1 1 0 0 0 1
1 0 1 0 1 0 1 1 0 0 1 1
 The weight between all layers has range between -0.5 and 0.5. The initial
population is listed in Table 2.
(i) Calculate the output value of 𝐿𝑘 for all population using the FIRST (1st) data
pattern. (NOTE : Sigmoid function is represented as f(x) = (1+e-x)-1)
(ii) Calculate the error for each population. Arrange the population from the
minimum error (NOTE : called the fittest individual) to the maximum error
(NOTE : called the less fit individual).
(iii) For the 1st generation do the following :
a) Cross the fittest two individuals using one-point crossover at the middle
point.
b) Cross the less fit individuals using a two-point crossover (point ‘d’ and
‘h’).
c) Mutate the FIFTH (5th) gen of the less fit individual.
(iv) Find the error of the new population obtained in (iii) and evaluate the
performance after the FIRST (1st ) generation.
END OF CHAPTER 5

PREPARE FOR :

Quiz 4
&
FINAL EXAM
Conclusions

Question: ‘If GAs are so smart, why ain’t they rich?’

Answer: ‘Genetic algorithms are rich - rich in


application across a large and growing
number of disciplines.’
- David E. Goldberg, Genetic Algorithms in Search, Optimization and Machine Learning
Introduction to GA
56

Search Techniqes

Guided random search Enumerative


Calculus Base
techniqes Techniqes
Techniques

Fibonacci DFS Dynamic BFS


Sort Programming

Tabu Search Simulated Evolutionary


Hill
Anealing Algorithms
Climbin
g
Genetic Genetic
Programming Algorithms
57
GA Components

Source: http://www.engineering.lancs.ac.uk
GA Components With Example
58

❑ The MAXONE problem : Suppose we want to


maximize the number of ones in a string of L
binary digits
❑ It may seem trivial because we know the
answer in advance
❑ However, we can think of it as maximizing the
number of correct answers, each encoded by
1, to L yes/no difficult questions`
GA Components: Representation
59

❑ Encoding
❑ An individual is encoded (naturally) as a string of l
binary digits
➢ Let’s say L = 10. Then, 1 = 0000000001 (10 bits)
Algorithm
60

 produce an initial population of


individuals
 evaluate the fitness of all individuals
 while termination condition not met do
 select fitter individuals for reproduction
 recombine between individuals
 mutate individuals
 evaluate the fitness of the modified individuals
 generate a new population
 End while
Initial Population
61

❑ We start with a population of n random strings. Suppose that


❑ l = 10 and n = 6
❑ We toss a fair coin 60 times and get the following initial
population:
 s1 = 1111010101
 s2 = 0111000101
 s3 = 1110110101
 s4 = 0100010011
 s5 = 1110111101
 s6 = 0100110000
Algorithm
62

 produce an initial population of individuals

 evaluate the fitness of all individuals


 while termination condition not met do
 select fitter individuals for reproduction
 recombine between individuals
 mutate individuals
 evaluate the fitness of the modified individuals
 generate a new population
 End while
Fitness Function: f()
63

 We toss a fair coin 60 times and get the following


initial population:
 s1 = 1111010101 f (s1) = 7
 s2 = 0111000101 f (s2) = 5
 s3 = 1110110101 f (s3) = 7
 s4 = 0100010011 f (s4) = 4
 s5 = 1110111101 f (s5) = 8
 s6 = 0100110000 f (s6) = 3
 ---------------------------------------------------
 = 34
Algorithm
64

 produce an initial population of individuals


 evaluate the fitness of all individuals
 while termination condition not met do

 select fitter individuals for reproduction


 recombine between individuals
 mutate individuals
 evaluate the fitness of the modified individuals
 generate a new population
 End while
Selection (1)
65

❑ Next we apply fitness proportionate selection with


the roulette wheel method:
1 2 Individual i will have a
n probability to be chosen
3 f (i )
4  f (i)
i

❑ We repeat the extraction as many times as the


number of individuals
❑ we need to have the same parent population size
(6 in our case)
Selection (2)
66

❑ Suppose that, after performing selection, we get the


following population:
 s1` = 1111010101 (s1)
 s2` = 1110110101 (s3)
 s3` = 1110111101 (s5)
 s4` = 0111000101 (s2)
 s5` = 0100010011 (s4)
 s6` = 1110111101 (s5)
Algorithm
67

 produce an initial population of individuals


 evaluate the fitness of all individuals
 while termination condition not met do
 select fitter individuals for reproduction

 recombine between individuals


 mutate individuals
 evaluate the fitness of the modified individuals
 generate a new population
 End while
Recombination (1)
68

❑ aka Crossover
❑ For each couple we decide according to
crossover probability (for instance 0.6) whether
to actually perform crossover or not
❑ Suppose that we decide to actually perform
crossover only for couples (s1`, s2`) and (s5`,
s6`).
❑ For each couple, we randomly extract a
crossover point, for instance 2 for the first and
5 for the second
Recombination (2)
69
Algorithm
70

 produce an initial population of individuals


 evaluate the fitness of all individuals
 while termination condition not met do
 select fitter individuals for reproduction
 recombine between individuals

 mutate individuals
 evaluate the fitness of the modified individuals
 generate a new population
 End while
Mutation (1)
71

❑Before applying mutation: ❑After applying mutation:


s1`` = 1110110101 s1``` = 1110100101
s2`` = 1111010101 s2``` = 1111110100
s3`` = 1110111101 s3``` = 1110101111
s4`` = 0111000101 s4``` = 0111000101
s5`` = 0100011101 s5``` = 0100011101
s6`` = 1110110011 s6``` = 1110110001
Mutation (2)
72

❑ The final step is to apply random mutation: for


each bit that we are to copy to the new
population we allow a small probability of error
(for instance 0.1)
❑ Causes movement in the search space
(local or global)
❑ Restores lost information to the population
High-level Algorithm
73

 produce an initial population of individuals


 evaluate the fitness of all individuals
 while termination condition not met do
 select fitter individuals for reproduction
 recombine between individuals
 mutate individuals

 evaluate the fitness of the modified


individuals
 generate a new population
 End while
Fitness of New Population
74

❑ After Applying Mutation:


 s1``` = 1110100101 f (s1```) = 6
 s2``` = 1111110100 f (s2```) = 7
 s3``` = 1110101111 f (s3```) = 8
 s4``` = 0111000101 f (s4```) = 5
 s5``` = 0100011101 f (s5```) = 5
 s6``` = 1110110001 f (s6```) = 6
-------------------------------------------------------------

37
Example (End)
75

❑ In one generation, the total population fitness


changed from 34 to 37, thus improved by ~9%
❑ At this point, we go through the same process
all over again, until a stopping criterion is met
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
Example
 Model parameters are encoded into a binary string

 For each parameter, a minimum value, step size and


encoding length has to be specified. For example two
parameters x1, x2:
Example cont’d
 During initialization, a population of N random
models is generated.
Selection
Crossover
Mutation
Effect to reproduction
Examples
 Design a car parking system that has only four(4)
places for vehicle to park.
 The goal is to find the place where the customer
likely to park their vehicle.
 How about when you have a parking system that
has 4 floors?
USED TERMS
 Chromosome
 Cross over
 Mutation
Example of optimizations techniques
Maxima and Minima

An example
 We have a chromosome
like follows;

 Then we make cross-over

 Now proceed to mutation.


The mutation depends on 1
the encoding as well as the
crossover.
1
Video

Introduction about Genetic Algorithm


◼ Evolution can be seen as a process leading to the maintenance
of a population’s ability to survive and reproduce in a specific
environment. This ability is called evolutionary fitness.

◼ Evolutionary fitness can also be viewed as a measure of the


organism’s ability to anticipate changes in its environment.

◼ The fitness, or the quantitative measure of the ability to predict


environmental changes and respond adequately, can be
considered as the quality that is optimized in natural life.
How is a population with increasing
fitness generated?
◼ Let us consider a population of rabbits. Some rabbits are faster
than others, and we may say that these rabbits possess superior
fitness, because they have a greater chance of avoiding foxes,
surviving and then breeding.

◼ If two parents have superior fitness, there is a good chance that


a combination of their genes will produce an offspring with even
higher fitness. Over time the entire population of rabbits
becomes faster to meet their
environmental challenges in the face of foxes.
Genetic Algorithm
 How GA finds solution?
◦ Through iteration of encoding and evaluation
◦ Encoding; use chromosome and binary strings
◦ Evaluation; exploiting fitness of the system
 Selection, Cross-over, Mutation methods
 Selection: selecting the chromosome for each gene
 Cross-over: exchange parts(genes) of two
chromosomes.
 Mutation: changing gene randomly in a
chromosome.
1 0 1 1 0 1 0 0 0 0 0 1 0 1 0 1
Genetic algorithms: case study
A simple example will help us to understand how
a GA works. Let us find the maximum value of
the function (15x - x2) where parameter x varies
between 0 and 15. For simplicity, we may
assume that x takes only integer values. Thus,
chromosomes can be built with only four genes:
Integer Binary code Integer Binary code Integer Binary code
1 0001 6 0110 11 1011
2 0010 7 0111 12 1100
3 0011 8 1000 13 1101
4 0100 9 1001 14 1110
5 0101 10 1010 15 1111
Suppose that the size of the chromosome population
N is 6, the crossover probability pc equals 0.7, and
the mutation probability pm equals 0.001. The fitness
function in our example is defined by

f(x) = 15 x  x2
The fitness function and chromosome locations
Chromosome Chromosome Decoded Chromosome Fitness
label string integer fitness ratio, %
X1 1 1 00 12 36 16.5
X2 0 1 00 4 44 20.2
X3 0 0 01 1 14 6.4
X4 1 1 10 14 14 6.4
X5 0 1 11 7 56 25.7
X6 1 0 01 9 54 24.8
60 60
f(x)
50 50

40 40

30 30

20 20

10 10

0 0
0 5 10 15 0 5 10 15
x x
(a) Chromosome initial locations. (b) Chromosome final locations.
◼ In natural selection, only the fittest species can survive,
breed, and thereby pass their genes on to the next generation.
GAs use a similar approach, but unlike nature, the size of the
chromosome population remains unchanged from one
generation to the next.

◼ The last column in Table shows the ratio of the individual


chromosome’s fitness to the population’s total fitness. This ratio
determines the chromosome’s chance of being selected for
mating. The chromosome’s average fitness improves from one
generation to the next.
Roulette wheel selection
The most commonly used chromosome selection
techniques is the roulette wheel selection.

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
Crossover operator
◼ In our example, we have an initial population of 6
chromosomes. Thus, to establish the same population in the
next generation, the roulette wheel would be spun six
times.

◼ Once a pair of parent chromosomes is selected, the


crossover operator is applied.
◼ First, the crossover operator randomly chooses a
crossover point where two parent chromosomes
“break”, and then exchanges the chromosome parts
after that point. As a result, two new offspring are
created.

◼ If a pair of chromosomes does not cross over, then


the chromosome cloning takes place, and the
offspring are created as exact copies of each
parent.
Crossover

X6i 1 0 00 1 0 1 00 00 X2i

X1i 0 11 00 00
1 0 11 11 11 X5i

X2i 0 1 0 0 0 1 1 1 X5i
Mutation operator
◼ Mutation represents a change in the gene.
◼ Mutation is a background operator. Its role is to
provide a guarantee that the search algorithm is not
trapped on a local optimum.

◼ The mutation operator flips a randomly selected


gene in a chromosome.
◼ The mutation probability is quite small in nature, and is
kept low for GAs, typically in the range between 0.001
and 0.01.
Mutation
X6'i 1 0 0 0

X2'i 0 1 0 1
0

X1'i 1
0 1 1 1 1 1 X1"i

X5'i 0 1 0
1 0
1

X2i 0 1 0 0 1 0 X2"i

X5i 0 1 1 1
The genetic algorithm cycle

C rossover
Generation i
X1i 1 1 0 0 f = 36 X6i 1 0 00 1 0 1 00 00 X2i
X2i 0 1 0 0 f = 44
X3i 0 0 0 1 f = 14
X4i 1 1 1 0 f = 14 X1i 10 11 00 00 0 11 11 11 X5i
X5i 0 1 1 1 f = 56
X6i 1 0 0 1 f = 54
X2i 0 1 0 0 0 1 1 1 X5i
Generation (i + 1)
X1i+1 1 0 0 0 f = 56 Mutation
X2i+1 0 1 0 1 f = 50 X6'i 1 0 0 0
X3i+1 1 0 1 1 f = 44
X2'i 0 1 0 10
X4i+1 0 1 0 0 f = 44
X1'i 10 1 1 1 1 1 X1"i
X5i+1 0 1 1 0 f = 54
X6i+1 0 1 1 1 f = 56 X5'i 0 1 01 01

X2i 0 1 0 0 1 0 X2"i

X5i 0 1 1 1
Remarks
 The new subject has inherited the intended genome : his paws
have become flippers.
 We can then see that the principle of genetic algorithms is
simple :
1. Encoding of the problem in a binary string.
2. Random generation of a population. This one includes a
genetic pool representing a group of possible solutions.
3. Reckoning of a fitness value for each subject. It will directly
depend on the distance to the optimum.
4. Selection of the subjects that will mate according to their
share in the population global fitness.
5. Genomes crossover and mutations.
6. And then start again from point 3.
End of
Today’s Class
Biological Background
Chromosome
 All living organisms consist of cells.
 In each cell there is the same set of chromosomes.
 Chromosomes are strings of DNA and serves as a
model for the whole organism.
 A chromosome consist of genes, blocks of DNA.
 Each gene encodes a particular protein. Basically
can be said, that each gene encodes a trait, for
example color of eyes. Possible settings for a trait
(e.g. blue, brown) are called alleles.
Chromosome (2)
 Each gene has its own position in the chromosome.
This position is called locus.
 Complete set of genetic material (all chromosomes)
is called genome.
 Particular set of genes in genome is
called genotype.
Reproduction
 During reproduction, first
occurs recombination (or crossover).
 Genes from parents form in some way the whole
new chromosome.
 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.
 The fitness of an organism is measured by success
of the organism in its life.
Basic genetic algorithms
Step 1: Represent the problem variable domain as
a chromosome of a fixed length, choose the size
of a chromosome population N, the crossover
probability pc and the mutation probability pm.

Step 2: Define a fitness function to measure the performance, or


fitness, of an individual chromosome in the problem
domain. The fitness function establishes the basis for selecting
chromosomes that will be mated during reproduction.
Step 3: Randomly generate an initial population of
chromosomes of size N:
x1, x2 , . . . , xN

Step 4: Calculate the fitness of each individual


chromosome:
f (x1), f (x2), . . . , f (xN)

Step 5: Select a pair of chromosomes for mating


from the current population. Parent
chromosomes are selected with a probability
related to their fitness.
Step 6: Create a pair of offspring chromosomes by
applying the genetic operators - crossover and
mutation.

Step 7: Place the created offspring chromosomes


in the new population.

Step 8: Repeat Step 5 until the size of the new


chromosome population becomes equal to the
size of the initial population, N.

Step 9: Replace the initial (parent) chromosome


population with the new (offspring) population.

Step 10: Go to Step 4, and repeat the process until the


termination criterion is satisfied.

You might also like