Dr. Kourosh Kiani Genetics-Algorithm Lecture 01 Introduction Genetics Algorithm
Dr. Kourosh Kiani Genetics-Algorithm Lecture 01 Introduction Genetics Algorithm
DREAM
IDEA
IDEA
PLAN
PLAN
IMPLEMENTATION
IMPLEMENTATION
Genetic algorithms
Present to:
Amirkabir University of Technology (Tehran
Polytechnic) & Semnan University
"A man who dares to waste an hour of life has not discovered
the value of life"
Genetic algorithms
Chromosome A 1 0 1 1 0 1 0 0 0 1 0 1 1
Chromosome B 1 1 1 0 0 1 1 0 0 0 1 10 1
Chromosome A 0 0 1 1 1 1 0 0 1 1 0 1 0 0 1
x y z
Chromosome B 1 1 1 1 0 1 0 1 1 1 0 1 0 0 0
x y z
Components of Genetic algorithms : Encoding
Given the digits 0 through 9 and the operators +, -, * and /, find a
sequence that will represent a given target number. The operators will be
applied sequentially from left to right as you read.
So, given the target number 23, the sequence 6+5*4/2+1 would be one
possible solution.
If 75.5 is the chosen number then 5/2+9*7-5 would be a possible solution.
011010100101110001001101001010100001
Components of Genetic algorithms : Decoding
A Quick Word about Decoding
Because the algorithm deals with random arrangements of bits it is
often going to come across a string of bits like this:
0010001010101110101101110010
Decoded, these bits represent:
0010 0010 1010 1110 1011 0111 0010
2 2 + n/a - 7 2
Which is meaningless in the context of this problem! Therefore, when
decoding, the algorithm will just ignore any genes which don’t conform
to the expected pattern of: number -> operator -> number -> operator
…and so on. With this in mind the above ‘nonsense’ chromosome is
read (and tested) as:
Crossover: Uniform
Parent 1: 000000000000000000
Parent 2: 111111111111111111
Offspring 1: 010010110001011001
Offspring 2: 101101001110100110
Crossover
Single arithmetic
crossover
• Parents: 〈x1,…,xn 〉 and 〈y1,…,yn〉
• Pick a single gene (k) at random,
• child1 is: x1 , ..., xk , α ⋅ yk + (1 −α) ⋅ xk , ..., xn
Parent 1: 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Parent 2: 0.3 0.1 0.4 0.5 0.3 0.2 0.6 0.6 0.3
Parent 1: 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Parent 2: 0.3 0.1 0.4 0.5 0.3 0.2 0.6 0.6 0.3
0.8 × 0.6 + (1 − 0.8)0.8 = 0.48 + 0.16 = 0.64 ≈ 0.6
0.8 × 0.3 + (1 − 0.8)0.9 = 0.24 + 0.18 = 0.42 ≈ 0.4
Offspring 1: 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.6 0.4
0.8 × 0.8 + (1 − 0.8)0.6 = 0.64 + 0.12 = 0.76 ≈ 0.8
0.8 × 0.9 + (1 − 0.8)0.3 = 0.72 + 0.06 = 0.78 ≈ 0.8
Offspring 1: 0.3 0.1 0.4 0.5 0.3 0.2 0.6 0.8 0.8
Crossover
With some small probability (the mutation rate) flip each bit in the
offspring (typical values between 0.1 and 0.001)
Mutation
(1.29 5.68 2.86 4.11 5.55) => (1.29 5.68 2.73 4.22 5.55)
Components of Genetic algorithms :
Create initial population (usually
random)
1 101100101100101011100101010100110110010110010101
110
2 001000101100101011100101010111110110010110000101
110
3 001000101100111111100101110111000010010110000101
110
4 100000101100101011101111110100110110010000010101
110
5 111111111100101011100101011111110110010110010111
111
6 001000101100111111111111111000110010010110000101
110
7 100000101001100111110010101110111111010011011001
001
8 111111111110000000001111101111110100110111111101
000
9 000000000000000000000000000000001111111101010101
011
10 000000000110011100001010101010100000000000011111
111
Simple example of Genetic optimization
The chosen problem is to minimize the value of a string of 1’s and 0’s as a
binary number. While this is a trivial problem, it will serve to illustrate
the operation of the algorithm without the obscuring effects of a
complicated objective function.
The genetic algorithm performs minimization in the following steps:
Selected
In the reproduction population
0.142, 14%
phase, each chromosome 011010
0.168, 17%
After crossover:
sC1 = 011011 sC3 = 000011 sC5 = 100110
sC2 = 001010 sC4 = 011011 sC6 = 010111
Components of Genetic algorithms :
Mutation
A surprisingly small role is played by mutation. Biologically, it randomly perturbs the
population’s characteristics, thereby preventing evolutionary dead ends.
Most mutations are damaging rather than beneficial; therefore, rates must be low to avoid
the destruction of species. In the simulation we will assume a mutation rate of on bit per
thousand, where a mutation acts to reverse the value of single bit. Since we have only 36 bits
in our population, the probability of a mutation is only 0.036; therefore, no bits are reversed
in the simulation. By mutation, algorithm explores parts of the space that crossover might
miss, and helps prevent premature convergence.
After 1101101001011100
Components of Genetic algorithms :
Crossover (Recombination)
After One
J chromosome Binary Generation
Decimal value Oj = 1/(decimal value) Fj =Oj / (Total Oj)
number chromosome Objective function Fraction of Total
Total 0.576 1
Selected
population 0.075, 7% 0.064, 6%
01011
0.046, 5% 01101
001010 1
In the reproduction 0.064, 6% 10011
1
01101
1
0.174, 17%
Before crossover:
sP1 = 001010 sP3 = 000011 sP5 = 000011
After crossover:
sC1 = 001011 sC3 = 000011 sC5 = 000011
sC2 = 000010 sC4 = 000011 sC6 = 010111
Components of Genetic algorithms :
Crossover (Recombination)
After Two
J chromosome Binary Generation
Decimal value Oj = 1/(decimal value) Fj =Oj / (Total Oj)
number chromosome Objective function Fraction of Total
Total 1.633 1
Selected
population 0.026, 3% 0.0557, 6%
Before crossover:
sP1 = 000010 sP3 = 000011 sP5 = 000011
After crossover:
sC1 = 000010 sC3 = 000011 sC5 = 000011
sC2 = 000010 sC4 = 000011 sC6 = 000011
Components of Genetic algorithms :
Crossover (Recombination)
After Three
J chromosome Binary Generation
Decimal value Oj = 1/(decimal value) Fj =Oj / (Total Oj)
number chromosome Objective function Fraction of Total
Mutate offspring
1 1111010101 7 0.206
2 0111000101 5 0.147
3 1110110101 7 0.206
4 0100010011 4 0.118
5 1110111101 8 0.235
6 0100110000 3 0.088
Total 34 1
Genetic algorithms :
Selection of parents ( reproduction)
J Binary Oj = 1/(decimal value) Fj =Oj / (Total Oj) Round (Fj*6)=
chromosome chromosome Objective function Fraction of Total Copy number
number
1 1111010101 7 0.206 1
2 0111000101 5 0.147 1
3 1110110101 7 0.206 1
4 0100010011 4 0.118 1
5 1110111101 8 0.235 1
6 0100110000 3 0.088 0
Total 34 1
Selected
population
1111010101
0111000101
1110110101
0100010011
Genetic algorithms : Example
(crossover1)
the MAXONE problem
After crossover:
sC1 = 1110110101 sC4 = 0100011101
sC3 = 1111010101 sC5 = 1110110011
Genetic algorithms : Example (Mutation)
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)
1110110101 1110100101
0111000101 0111000101
1111010101 1111110100
0100011101 0100011101
1110110011 1110110001
Genetic algorithms : Example (End)
the MAXONE problem
J chromosome Binary Oj = number of ones Fj =Oj / (Total Oj)
number chromosome Objective function Fraction of Total
1 1110100101 6 0.162
2 0111000101 5 0.135
3 1111110100 7 0.189
4 0100011101 5 0.135
5 1110110001 6 0.162
In one generation, the total population fitness changed from 34
to 37, thus
6 improved by ~9%
1110101111 8 0.216
At this point,
Total we go through the same
37 process all 1over again,
until a stopping criterion is met
Genetic algorithms : Optimization of a
simple function
The function is defined as:
2.5
which 1
that,0 0
determined:
f ( x) = sin(10π .x) + 10πx. cos(10π .x) = 0 The function f reaches its local
tan(10π .x) = −10π .x max for xi if i is an odd integer and
2i − 1 its local min for xi if i is an even
xi = for i = 1,2, integer. The function reaches its
20
max for:
37
x0 = 0 x19 = = 1.85
20
2i + 1 π
xi = for i = −1,−2, f (1.85) = 1.85. sin(18π + ) + 1.0 = 2.85
20 2
Genetic algorithms : Optimization of a
simple function
he mapping from a binary vector (chromosome) (b21 b20 ....b0) into a real number
from the range [-1 2] is straightforward and is completed in to steps:
Convert the binary chromosome (b21 b20 ….b0) from the base 2 to base 10:
21
(b21b20 b0 ) 2 = ∑ bi .2i = x '
i =0 10
• Find a corresponding real number x :
bi − ai 3
xi = ai + decimal(10001....100002 ). x = −1.0 + x ' .
2 mi − 1 2 22 − 1
Where -1.0 is the left boundary of the domain and 3 is the length of the domain:
Genetic algorithms : Presentation
(Encoding)
Chromosome: 1000101110110101000111
3
x = −1.0 + x . 22
'
2 −1
3
x = −1.0 + 2288967. = 0.637197
4194303
eval (v) = f ( x)
As noted earlier, the evaluation plays the role of the environment, rating potential solutio
In terms of their fitness. For example, three chromosomes:
v1 = (1000101110110101000111) corresponed to x1 = 0.637197
v2 = (0000001110000000010000) corresponed to x2 = −0.958973
v3 = (1110000000111111000101) corresponed to x3 = 1.627888
learly, the chromosome v3 is the best of the three chromosomes, since its evaluation retur
he highest value.
Genetic algorithms :
Mutation
Assume that the fifth gene from the v3 chromosome was selected for mutation:
After crossover:
v’2 = 0000000000111111000101
v’3 = 1110001110000000010000
v ' 2 = (0000000000111111000101) corresponed to x ' 2 = −0.998113 eval (v ' 2 ) = f ( x ' 2 ) = 0.940865
v '3 = (1110001110000000010000) corresponed to x '3 = 1.666028 eval (v '3 ) = f ( x '3 ) = 2.459245
Note that the second offspring has a better evaluation than both of its parents.
Genetic algorithms :
Parameters
For this particular problem we have used the following parameters: Population
size: pop_size = 50, probability of crossover Pc =0.25, probability of mutation Pm
= 0.01.
Generation Evaluation function
number
In table, we provide the generation
number for which we noted an 1 1.441942
improvement in the evaluation function, 6 2.250003
together with the value of function. The
8 2.250283
best chromosome after 150 generations
was: 9 2.250284
10 2.250363
vmax = (1111001101000100000101) 12 2.328077
corresponed to xmax = 1.850773 39 2.344251
40 2.345087
51 2.738930
99 2.849246
137 2.850217
145 2.850227
Genetic algorithms : Optimization of a two
variables function
The function is defined as: f ( x1 , x2 ) = 21.5 + x1. sin( 4π .x1 ) + + x2 . sin( 20π .x2 )
The domain of the variable x1 has length 15.1; the precision requirement
implies that the range [-3 12.1] should be divided into at least
15.1*10000=151000 equal size ranges. This means that 18 bits are
required as a binary vector (chromosome):
131072 = 2 < 151000 < 2 = 262144
17 18
The domain of the variable x2 has length 1.7; the precision requirement
implies that the range [4.1 5.8] should be divided into at least
1.7*10000=17000 equal size ranges. This means that 15 bits are required
as a binary vector (chromosome):
f(1.052426,5.755330)=20.252640.
Genetic algorithms : Initial
population
To optimize the function f using a genetic algorithm, we create a
population of pop_size = 20 chromosomes. All 33 bits in all chromosomes
are initialized randomly.
v1 = 100110100000001111111010011011111
v2 = 111000100100110111001010100011010
v3 = 000010000011001000001010111011101
v4 = 100011000101101001111000001110010
v5 = 000111011001010011010111111000101
v6 = 000101000010010101001010111111011
v7 = 001000100000110101111011011111011
v8 = 100001100001110100010110101100111
v9 = 010000000101100010110000001111100
v10 = 000001111000110000011010000111011
v11 = 011001111110110101100001101111000
v12 = 110100010111101101000101010000000
v13 = 111011111010001000110000001000110
v14 = 010010011000001010100111100101001
v15 = 111011101101110000100011111011110
v16 = 110011110000011111100001101001011
v17 = 011010111111001111010001101111101
v18 = 011101000000001110100111110101101
v19 = 000101010011111111110000110001100
v20 = 101110010110011110011000101111110
During the evaluation phase we decode each chromosome and calculate
the fitness
Function values from (x1, x2) values just decoded. We get:
v1 = 100110100000001111111010011011111 | x1 = 6.0844 x2 = 5.6522 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 26.0196
v2 = 111000100100110111001010100011010 | x1 = 10.3484 x2 = 4.3802 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 7.5800
v3 = 000010000011001000001010111011101 | x1 = −2.5166 x2 = 4.3903 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 19.5263
v4 = 100011000101101001111000001110010 | x1 = 5.2786 x2 = 5.5934 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 17.4067
v5 = 000111011001010011010111111000101 | x1 = −1.2551 x2 = 4.7344 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 25.3411
v6 = 000101000010010101001010111111011 | x1 = −1.8117 x2 = 4.3919 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 18.1004
v7 = 001000100000110101111011011111011 | x1 = −0.9914 x2 = 5.5802 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 16.0208
v8 = 100001100001110100010110101100111 | x1 = 4.9106 x2 = 4.7030 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 17.9597
v9 = 010000000101100010110000001111100 | x1 = 0.7954 x2 = 5.3814 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 16.1277
v10 = 000001111000110000011010000111011 | x1 = −2.5548 x2 = 4.7937 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 21.2784
v11 = 011001111110110101100001101111000 | x1 = 3.1300 x2 = 4.9960 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 23.4106
v12 = 110100010111101101000101010000000 | x1 = 9.3561 x2 = 4.2394 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 15.0116
v13 = 111011111010001000110000001000110 | x1 = 11.1346 x2 = 5.3786 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 27.3167
v14 = 010010011000001010100111100101001 | x1 = 1.3359 x2 = 5.1513 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 19.8762
v15 = 111011101101110000100011111011110 | x1 = 11.0889 x2 = 5.0545 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 30.0602
v16 = 110011110000011111100001101001011 | x1 = 9.2115 x2 = 4.9937 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 23.8672
v17 = 011010111111001111010001101111101 | x1 = 3.3675 x2 = 4.5713 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 13.6961
v18 = 011101000000001110100111110101101 | x1 = 3.8430 x2 = 5.1582 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 15.4141
v19 = 000101010011111111110000110001100 | x1 = −1.7466 x2 = 5.3955 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 20.0959
v20 = 101110010110011110011000101111110 | x1 = 7.9359 x2 = 4.7573 | eval ( x1 , x2 ) = f ( x1 , x2 ) = 13.6669
Total Fitness 387.7768
It is clear, that the chromosome v15 is the strongest one, and the
chromosome v2 the weakest.
Now we constructs a roulette wheel for the selection process. The total
20
fitness of the population
F = evalis:
∑ (v ) = 387.7768
i =1
i
v3 = 0
q14 = 0.6988 < r7 = 0.7022 < q15 = 0.7763 Select v15 chromosome
r3 = 0.3087 q3 = 0.1370 v '3 = v7
r4 = 0.5345 q4 = 0.1819 v4 = 2 v ' 4 = v11 q4 = 0.1819 < r8 = 0.2226 < q5 = 0.2472 Select v5 chromosome
r5 = 0.9476 q5 = 0.2472 v5 = 1 v '5 = v19 q10 = 0.4780 < r9 = 0.4948 < q11 = 0.5384 Select v11 chromosome
r6 = 0.1717 q6 = 0.2939 v6 = 1 v 6 = v4
'
v7 = 1
q9 = 0.4231 < r10 = 0.4247 < q10 = 0.4780 Select v10 chromosome
r7 = 0.7022 q7 = 0.3352 v ' 7 = v15
r8 = 0.2226 q8 = 0.3815 v8 = 1 v '8 = v5 q14 = 0.6988 < r11 = 0.7039 < q15 = 0.7763 Select v15 chromosome
r9 = 0.4948 q9 = 0.4231 v9 = 1 v '9 = v11 q8 = 0.3815 < r12 = 0.3890 < q9 = 0.4231 Select v9 chromosome
r10 = 0.4247 q10 = 0.4780 v10 = 1 v '10 = v10
v11 = 3
q5 = 0.2472 < r13 = 0.2772 < q6 = 0.2939 Select v6 chromosome
r11 = 0.7039 q11 = 0.5384 v '11 = v15
r12 = 0.3890 q12 = 0.5771 v12 = 0 v '12 = v9 q7 = 0.3352 < r14 = 0.3681 < q8 = 0.3815 Select v8 chromosome
r13 = 0.2772 q13 = 0.6475 v13 = 1 v '13 = v6 q19 = 0.9648 < r15 = 0.9834 < q20 = 1.0000 Select v20 chromosome
v14 = 0 v '
= v8
r14 = 0.3681 q14 = 0.6988 14
q0 = 0.0000 < r16 = 0.0054 < q1 = 0.0670 Select v1 chromosome
v15 = 4 v '15 = v20
r15 = 0.9834 q15 = 0.7763
v16 = 1 v '16 = v1 q14 = 0.6988 < r17 = 0.7656 < q15 = 0.7763 Select v15 chromosome
r16 = 0.0054 q16 = 0.8379
v17 = 0 v '17 = v15 q12 = 0.5771 < r18 = 0.6446 < q13 = 0.6475 Select v13 chromosome
r17 = 0.7656 q17 = 0.8732
v18 = 0 v '
= v13
r18 = 0.6446 q18 = 0.9129 18
q14 = 0.6988 < r19 = 0.7671 < q15 = 0.7763 Select v15 chromosome
v19 = 1 v '19 = v15
r19 = 0.7671 q19 = 0.9648
v20 = 1 v ' 20 = v16 q15 = 0.7763 < r20 = 0.7802 < q16 = 0.8379 Select v16 chromosome
r20 = 0.7802 q20 = 1.0000
Genetic algorithms : Crossover
Now we are ready to apply the crossover operation to the individuals in the new
population (vector v’I ). The probability of crossover Pc=0.25, so we expect that on
average 25% of chromosomes (i.e., 4 out of 20) undergo crossover.
We proceed in the following way: Let us assume that a (random) sequence of 20
numbers from range [0 1] is:
r1 =0.8230
r2 =0.1519 This mean that the chromosomes v’2, v’11 , v’13 and v’18 were selected
r3 =0.6255
for crossover. For each of these two pairs, we generate a random
r4 =0.3115
r5 =0.3490
integer number pos from range [1 32] ( 33 is the total length-
r6 =0.9172 number of bits-in chromosome). The number pos indicates the
r7 =0.5198 position of the crossing point. The first pair of chromosomes is:
r8 =0.4012
r9 =0.6068
v ' 2 = 100011000101101001111000001110010
r10 =0.7854 v '11 = 111011101101110000100011111011110
r11 =0.0315
r12 =0.8699 And the generated number
r13 =0.1665 pos=9.
r14 =0.6745 v 2 = 100011000101110000100011111011110
''
r15 =0.7584
v ''11 = 111011101101101001111000001110010
r16 =0.5819
r17 =0.3892
r18 =0.2002
r19 =0.3557
r20 =0.8269
Genetic algorithms : Crossover
The second pair of chromosomes is: The current version of the
population
And the generated number v 1 = 0110011111 1011010110 0001101111 000
'
Chromosome position
v1 = 1110111101 1001101110 0101010111 011 eval (v1 ) = f (11 .12, 5.0925 ) = 30 .2985
v2 = 1110011001 1000010001 0101010111 000 eval (v2 ) = f (10 .5888 , 4.6674 ) = 26 .8697
v3 = 1110111101 1101101110 0101010111 011 eval (v3 ) = f (11 .1246 , 5.0925 ) = 30 .3166
v4 = 1110011000 1000011000 0101010111 001 eval (v4 ) = f (10 .5741, 4.2442 ) = 31 .9331
v5 = 1110111101 1101101110 0101010111 011 eval (v5 ) = f (11 .1246 , 5.0925 ) = 30 .3166
v6 = 1110011001 1000010000 0100010100 001 eval (v6 ) = f (10 .5888 , 4.2146 ) = 34 .3561
v7 = 1101011000 1001001000 1100010110 000 eval (v7 ) = f (9.6311, 4.4279 ) = 35 .4586
v8 = 1111011000 1000101000 1101010010 001 eval (v8 ) = f (11 .5181, 4.4528 ) = 23 .3090
v9 = 1110011000 1001001000 1100010110 001 eval (v9 ) = f (10 .5748 , 4.4279 ) = 34 .3938
v10 = 1110111101 1101101110 0101010111 011 eval (v10 ) = f (11 .1225 , 5.0925 ) = 30 .3166
v11 = 1101011000 0001001000 1100010110 000 eval (v11 ) = f (9.6237 , 4.4279 ) = 35 .4779
v12 = 1101011000 1001001000 1100010110 001 eval (v12 ) = f (9.6311, 4.42779 ) = 35 .4561
v13 = 1110111101 1101101110 0101010111 011 eval (v13 ) = f (11 .1246 , 5.0925 ) = 30 .3166
v14 = 1110011001 1000010000 0101010111 011 eval (v14 ) = f (10 .5888 , 4.2425 ) = 32 .9321
v15 = 1110011010 1011100101 0100110110 001 eval (v15 ) = f (10 .6066 , 4.6537 ) = 30 .7468
v16 = 1110011001 1000010100 0100010100 001 eval (v16 ) = f (10 .5888 , 4.2146 ) = 34 .3595
v17 = 1110011001 1000010000 0101010111 011 eval (v17 ) = f (10 .5888 , 4.2425 ) = 32 .9321
v18 = 1110011001 1000010000 0101010111 001 eval (v18 ) = f (10 .5888 , 4.2424 ) = 32 .9567
v19 = 1111011000 1000101000 1110000010 001 eval (v19 ) = f (11 .5181, 4.4728 ) = 19 .6697
v20 = 1110011001 1000010000 0101010111 001 eval (v20 ) = f (10 .5888 , 4.2424 ) = 32 .9567
Total = 625 .3728
Hybrid intelligent systems
x1 0.9
1 4
-0.8
From neuron: 1 2 3 4 5 6 7 8
0.1 -0.6
To neuron: 1 0 0 0 0 0 0 0 0 0.4
2 0 0 0 0 0 0 0 0 5
-0.3 0.1
3 0 0 0 0 0 0 0 0
x2 0.6 y
4 0.9 -0.3 -0.7 0 0 0 0 0 2 8
5 -0.8 0.6 0.3 0 0 0 0 0 -0.2
-0.2
0.5
6 0.1 -0.2 0.2 0 0 0 0 0 6
7 0.4 0.5 0.8 0 0 0 0 0 -0.7
0.3 0.9
8 0 0 0 -0.6 0.1 -0.2 0.9 0
0.2
x3
3 0.8 7
Chromosome: 0.9 -0.3 -0.7 -0.8 0.6 0.3 0.1 -0.2 0.2 0.4 0.5 0.8 -0.6 0.1 -0.2 0.9
Fitness Function
■ The second step is to define a fitness function for
evaluating the chromosome’s performance. This
function must estimate the performance of a
given neural network. We can apply here a
simple function defined by the sum of squared
errors.
■ The training set of examples is presented to the
network, and the sum of squared errors is
calculated. The smaller the sum, the fitter the
chromosome. The genetic algorithm attempts
to find a set of weights that minimises the sum
of squared errors.
weight optimisation
Crossover & Mutation
■ The third step is to choose the genetic operators –
crossover and mutation. A crossover operator
takes two parent chromosomes and creates a
single child with genetic material from both
parents. Each gene in the child’s chromosome is
represented by the corresponding gene of the
randomly selected parent.
■ A mutation operator selects a gene in a
chromosome and adds a small random value
between −1 and 1 to each weight in this gene.
Crossover in weight optimisation
Parent 1 Parent 2
3 3
x1 -0.6 x1 0.3 0.3
0.1
1 1
-0.2 0.9
0.4 0.5
y -0.8 -0.9
y
-0.7
4 6 0.2
4 6
x2 0.9 x2 -0.5
2 -0.8 2 0.6
-0.3 -0.1
5 5
0.1 -0.7 -0.2 0.9 0.4 -0.3 -0.6 0.5 -0.8 0.3 0.2 0.9 -0.5 -0.8 -0.1 0.3 -0.9 0.6
Child
3
x1 0.1 -0.6
1 0.9
-0.8 0.5
y
-0.7
4 6
x2 -0.5
2 -0.8
-0.1
5
Mutation in weight optimisation
5 5
0.1 -0.7 -0.2 0.9 0.4 -0.3 -0.6 0.5 -0.8 0.1 -0.7 -0.2 0.9 -0.1 0.2 -0.6 0.5 -0.8
Evolutionary neural networks:
optimal topology
Can genetic algorithms help us in selecting
the network architecture?
The architecture of the network (i.e. the number of
neurons and their interconnections) often
determines the success or failure of the application.
Usually the network architecture is decided by trial
and error; there is a great need for a method of
automatically designing the architecture for a
particular application. Genetic algorithms may
well be suited for this task.
Evolutionary neural networks:
optimal topology
3
From neuron: 1 2 3 4 5 6
x1
To neuron: 1 0 0 0 0 0 0 1
2 0 0 0 0 0 0 y
3 1 1 0 0 0 0 4 6
4 1 0 0 0 0 0 x2
5 0 1 0 0 0 0 2
6 0 1 1 1 1 0
5
Chromosome:
0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 1 0
The cycle of evolving a neural network topology
Neural Network j
Generation i
Fitness = 117
Mutation
Questions? Discussion?
Suggestions ?