Professional Documents
Culture Documents
ML 06
ML 06
ML 06
• Meeting Hours:
2
Learning Objectives
3
Contents of Subject
4
Technique 2: Evolutionary
Computing
(Genetic Algorithms
with
Hands-on simulation)
5
Contents
6
Contents
Genetic Algorithms
• Introduction
• Simulation of Natural Evolution
• Genetic Algorithms : Mice & Cat Story
• Example 1 : Burger and Profit Problem
• Example 2 : Optimization of simple equation
• Example 3 : Optimization of complex equation
• Example 4 : The Traveling Salesman Problem
• Summary
7
Introduction: Can Evolution be
Intelligent ?
8
Introduction…continue
9
Introduction…continue
10
Simulation of Natural
Evolution
11
Simulation of Natural
Evolution…..
13
Classes of search techniques
Search Techniques
Genetic Genetic
Programming Algorithms
14
Evolutionary process !
Father mother
Example of evolutionary process
+ Mice & Cats
15
mice & cats : an evolutionary
process
Run Faster
Zig-zag
pattern
Utilize the
surrounding
...
Mice
To survive:
Mice escape
from the cat Survive?
& cats catch
mice
16
The Mice & Cats algorithm
Population
Environment New
generation
Weak Strong &
intelligent
Die : end
of evolution Survive :
evolve
18
About ..Genetic Algorithms
1 0 1 1 0 0 1 1 1
19
About ..Genetic Algorithms
Nature (God’s Creation) has an ability to adapt and
learn without being told what to do. In other words,
nature finds good chromosomes blindly. Basically GAs
do the same. Two mechanisms link a GA to the problem
it is solving: encoding and evaluation.
22
Metaphor
23
Metaphor (cont..)
24
Basic Genetic Algorithm
25
Basic Genetic Algorithm
• Step 6: Create a pair of offspring chromosomes by applying
crossover and mutation.
• Step 8: repeat Step 5 until the size of the new population equal
to size of initial population, N
27
Another way of looking at this…
30
Example 1:
Burger and Profit Problem
31
The Burger and Profit Problem:
understanding the problem
32
The Burger and Profit Problem:
understanding the problem
33
The burger and profit Problem :
Representation/encoding
• We can represent the problem (decision to make) in
binary. i.e.
34
The burger and profit Problem :
fitness function
• Fitness = Profit
For Simplicity .. The fitness
Generation 0
is evaluated based on the
Fitnes binary value
i String Fitness
s
Xi F(Xi) f (Xi) ratio
f (X ) i
010 011
1 011 3 .25
17% 25%
2 001 1 .08
3 110 6 .50
50% 8%
4 010 2 .17
Total 12
001
Worst 1
Average 3.00
110
Best 6
35
The burger and profit Problem :
Selection/Reproduction
010 011
50% 8%
011 3
– The same goes to the other string or 110 6
individual. 110 6
010 2
– BUT since GA is probabilistic, string 110 Total 17
can be chosen 3X or even none in the Worst 2
Best 6
36
The burger and profit Problem :
CrossOver
• Fixed Point Xover
– Two parents are chosen based
on theirs fitness i.e. 011 and After Xover
110 are selected. (Generation 1)
0 1 0 1 1 1
37
The burger and profit
Problem: Mutation
• Mutation
1 1 0 1 0 0
Offspring1 Offspring2
38
The burger and profit Problem :
Result
i String Fitness f (Xi) Mating Pool Xover String Fitness Mutation String Fitness
Pool Point Point
Xi F(Xi) f (X ) i F(Xi) Xi F(Xi) Xi F(Xi)
Total 12 17 17 19
Worst 1 2 2 2
Average 3.00 4.25 4.25 4.75
Best 6 6 7 7
39
Example 2: Optimization of a
function with one variable, x
40
Answer these questions?
41
Recap..Steps in the GA development
42
Example 2: Solution
Representation
• Since parameter x is between 0 – 15 and assumed
to be integer value only, the solution can be
represented as a string of “0” and “1” of size 4. Thus,
chromosomes can be built with only four genes:
43
Example 2: Operator
Parameters
44
Example 2: The Fitness
Function
f(x )
30
20
10
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
x
45
Example 2: The fitness function and chromosome
locations
C hro m oso m e C hrom oso m e Deco ded C h rom oso m e F itness
label st ring integer fitn ess ra tio, %
X1 1 1 0 0 12 36 16.5
X2 0 1 0 0 4 44 20.2
X3 0 0 0 1 1 14 6.4
X4 1 1 1 0 14 14 6.4
X5 0 1 1 1 7 56 25.7
X6 1 0 0 1 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 initia l locations. (b) Chromosome final locations. 46
Example 2: The fitness function and
chromosome 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.
47
Example 2: Roulette wheel selection
The most commonly used chromosome selection
techniques is the roulette wheel selection.
100 0
X1: 16.5%
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
48
Example 2: Crossover operator
49
Example 2: Crossover operator….
50
Example 2: Crossover
X6i 1 0 00 1 0 1 00 00 X2i
X1i 10 11 00 00 0 11 11 11 X5i
X2i 0 1 0 0 0 1 1 1 X5i
51
Example 2: 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.
52
Example 2: Mutation
X6'i 1 0 0 0
X2'i 0 1 0 10
X1'i 1
0 1 1 1 1 1 X1"i
X5'i 0 1 01 0
1
X2i 0 1 0 0 1 0 X2"i
X5i 0 1 1 1
53
Example 2: The genetic algorithm cycle
Crossover
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 0 11 00 00
1 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 1
0 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
54
Example 2: Stochastic
Operators
55
Example 2: Termination
Criteria
56
DEMO example 2
57
Summary of exercise 2
58
Example 3: Optimization of
two parameters x and y
Find the maximum of the “peak” function of two
variables:
2 x 2 ( y 1) 2 3 3 x2 y 2
f ( x, y ) (1 x) e (x x y ) e
59
Answer these questions?
60
Example 3: Solution
Representation
The first step is to represent the problem variables as
a chromosome
Since parameter x and y is between -3 and +3, we
can represent it in concatenated binary form of 8 bits
for x and 8 bits for y
1 0 0 0 1 0 1 0 0 0 1 1 1 0 1 1
x y
61
Example 3: Solution
Representation
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 2 7 0 2 6 0 2 5 0 2 4 1 2 3 0 2 2 1 21 0 2 0 (138)10
and
(00111011) 2 0 2 7 0 2 6 1 2 5 1 2 4 1 2 3 0 2 2 1 21 1 2 0 (59)10
62
Example 3: Solution
Representation
Now the range of integers that can be handled by 8-
bits, that is the range from 0 to (28 1), is mapped to
the actual range of parameters x and y, that is the
range from 3 to 3:
6
0.0235294
256 1
x 2 ( y 1) 2 x2 y2
f ( x, y ) (1 x ) e
2
( x x y )e
3 3
64
GA Process
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.
65
Recap..Steps in the GA
development
67
Chromosome locations on the surface of the
“peak” function: first generation
68
Chromosome locations on the surface of the
“peak” function: local maximum
69
Chromosome locations on the surface of the
“peak” function: global maximum
70
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
71
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
72
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 4 6 8 10 12 14 16 18 20
Generations
73
Example 3: Stochastic
Operators
• SAME AS BEFORE…
• Selection / reproduction : Roulette Wheel
• Crossover : One point Xover – based on probability of
Xover
• Mutation : Change gene based on probability of
mutation
74
Example 3: Termination
Criteria
75
DEMO example 3
76
Example 4: Traveling Salesman Problem
(TSP)
77
Example 4: TSP Continue ..
78
Example 4: Answer these
questions?
79
Example 4: Solution
Representation
80
TSP.. continue : the path
representation
3
6
5
8
9
7 4
1 6 5 3 2 8 4 9 7
81
Example 4: Operator
Parameters
82
Example 4: The Fitness
Function
83
Example 4: Stochastic
Operators
84
Example 4: CROSSOVER
1 6 5 3 9 4 8 2 5 3 7 6 1 2 8 4 9 7
Child 1 Child 2
85
Example 4: CROSSOVER for TSP
Parent 1 1 6 5 3 2 8 4 9 7 3 7 6 1 9 4 8 2 5
Parent 2
Child 1 * * * 1 9 4 8 * * * * * 3 2 8 4 * *
Child 2
Parent 1 1 6 5 3 2 8 4 9 7 3 7 6 1 9 4 8 2 5
Parent 2
child 1 6 5 3 1 9 4 8 2 7 7 6 1 3 2 8 4 9 5
child 2
86
Example 4: Mutation For TSP
87
Example 4: Mutation For TSP
Original 1 6 5 3 2 8 4 9 7 1 6 5 3 2 8 4 9 7
original
mutated 1 6 8 3 2 5 4 9 7 1 2 3 5 6 8 4 9 7 mutated
88
Example 4: Termination
Criteria
89
DEMO example 4
90
Summary of GA
• Developed: USA in the 1970’s by Holland and his
students
• A class of probabilistic optimization algorithms
• Inspired by the biological evolution process
• Uses concepts of “Natural Selection” and “Genetic
Inheritance” (Darwin 1859)
• Typically applied to:
– discrete optimization (ex. TSP)
• Attributed features:
– good solver for combinatorial problems
• Special:
– many variants, e.g., reproduction models, operators
– formerly: the GA, nowdays: a GA, GAs
91
Summary : What you have
learned ..
92
What we have not covered ..
• .. To name a few
– We have not got into details on techniques in the
stochastic operators.
– Schemata theory to prove GA does work to solve NP-
problems
– Some other alternative to represent chromosomes like
structure ie. bits of “0” & “1”, floating points, integers,
rules, symbols etc.
– ……
93
The End
94