Genetic Algorithms a Step by Step Tutorial
-
Upload
samking1986 -
Category
Documents
-
view
1.675 -
download
3
Transcript of Genetic Algorithms a Step by Step Tutorial
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Genetic AlgorithmsA step by step tutorial
Max Moorkamp
Dublin Institute for Advanced Studies
Barcelona, 29th November 2005
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Outline
1 General remarks and comparison with other method
2 Genetic algorithms step-by-stepA hand-calculated exampleSome experiments on simple problems
3 Advanced topicsMulti-objective optimizationA geophysical example
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Comparison of different optimization methods
Method Func. Eval. Class of Problems
Analytical Gradient 1 One special problemNumerical Gradient 10− 102 differentiable, lim. no. of min.Genetic Algorithm 103 − 104 limited parameter rangeMonte Carlo 105 noneGrid Search 108 none
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Advantages and Disadvantages of Genetic Algorithm
Advantages:
No derivatives needed
Easy to parallelize
Can escape local minima
Works on a wide range of problems
Disadvantages:
Need much more function evaluations than linearized methods
No guaranteed convergence even to local minimum
Have to discretize parameter space
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
General program flow of a genetic algorithm
Generate random population
Select models into new population
Calculate probabilities from Objective function
Determine parameter encoding
Crossover
Mutation
N It
erat
ions
The general structure is the same for allgenetic algorithms
Individual steps can be done in a varietyof ways
We will only discuss the most basicoperators
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Outline
1 General remarks and comparison with other method
2 Genetic algorithms step-by-stepA hand-calculated exampleSome experiments on simple problems
3 Advanced topicsMulti-objective optimizationA geophysical example
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Encoding the parameters
Model parameters are encoded into a binary string
x = (1.2, 3.4, . . . , 100)← (0101110011 . . . 100011)
For each paramter a minimum value, stepsize and encoding lengthhas to be specified. For example two parameters x1, x2:
x1 ∈ [−1 . . . 1] and x2 ∈ [0 . . . 3.1]
5-bit x1 x2
Basevalue -1 0Stepsize 0.0625 0.1
10-bit x1 x2
Basevalue -1 0Stepsize 0.0002 0.003
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Generating a population
At the start a population of N random models is generated.
p1 = (0101110011) → (01011) = −1 + 26 ∗ 0.0625 = 0.625
(10011) = 0 + 25 ∗ 0.1 = 2.5
p2 = (1111010110) → (11110) = −1 + 15 ∗ 0.0625 = −0.0625
(10110) = 0 + 13 ∗ 0.1 = 1.3
p3 = (1001010001) → (10010) = −1 + 9 ∗ 0.0625 = −0.4375
(10001) = 0 + 17 ∗ 0.1 = 1.7...
...
pN = (0110100001) → (01101) = −1 + 22 ∗ 0.0625 = 0.375
(00001) = 0 + 16 ∗ 0.1 = 1.6
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Calculating the objective function values
For each member of the population calculate the value of theobjective function:
O(x1, x2) = x21 + x2
2
p1 → O(0.625, 2.5) = 6.64
p2 → O(−0.0625, 1.3) = 1.69
p3 → O(−0.4375, 1.7) = 3.08...
...
pN → O(0.375, 1.6) = 2.70
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Assigning probabilities
Based on the objective function value, a probability is assigned tomake it into the next generation P(pj) = f (O(xi )). In our example
P(pj) =1∑
i max O(xi ) − O(xi )(max O(xi ) − O(xi ))
In our case:∑
i max O(xi ) − O(xi ) = 12.45 this gives:
P(p1) =6.64− 6.64
12.45= 0.
P(p2) =6.64− 1.69
12.45= 0.40
P(p3) =6.64− 3.08
12.45= 0.28
P(p4) =6.64− 2.70
12.45= 0.32
Now we can generate a new population of the same size.Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Selection
Each model’s chance to mate is determined by their probability.The offsprings undergo two steps: Crossover and Mutation
Mating Cand. Old Pos. Prob.
m1 p2 0.4m2 p3 0.28m3 p4 0.32m4 p2 0.4
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Crossover
With probability Pc two members of the population exchange theirgenes after a randomly chosen point.
(000111) (000001)3−→
(110001) (110111)
Typically 0.2 ≤ Pc ≤ 0.7.
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Mutation
With a probability Pm one bit changes its value.
(000111)→ (010111)
Typically Pm is chosen so that 80-90 percent of the population donot mutate.
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Combined effect on the reproduction operators
Result of selection, crossover and mutation:
New Father Mother Cross. Mut. Result O(x)
p1 m1 m2 (1111010110) 1.69p2 m1 m2 (1001010001) 2.7p3 m3 m4 4 (0110|100001)→ (0110010110) 2.08p4 m3 m4 4 3 (1111|010110)→ (1101100001) 3.03
The resulting genetic strings make up the new population.
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Outline
1 General remarks and comparison with other method
2 Genetic algorithms step-by-stepA hand-calculated exampleSome experiments on simple problems
3 Advanced topicsMulti-objective optimizationA geophysical example
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
A slightly more difficult problem
O(x) = (x − 6)(x − 2)(x + 4)(x + 6)
has two minima O(−5.11) = −78.03 and O(4.41) = −335.475.We search x ∈ [−10 . . . 20] with 15-bit and a stepsize of 0.001.N = 20 and we calculate 6 generations i.e 120 forward calculations.The objective function ↔ probability scaling is
P(pi ) =1∑ exp(−O(x)/T ) where T =
1000 g < 3100 g ≥ 3
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Statistics of GA performance
0 1 2 3 4Generation
-400
-200
0
200
400
Func
tion
Val
ue
Best memberMean performance
Fitness vs. Generation
25799.3 starting value
0 500 1000 1500 2000
4.1
4.2
4.3
4.4
4.5
Index
GA
Res
ult
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Performance of the GA
−10 −5 0 5 10 15 20
050
000
1000
0015
0000
Generation 0
x
y
+
+
+
+
+
+++++ +++ +
+
+
+
−10 −5 0 5 10
020
0040
0060
00
Generation 1
x
y
+
+
+
+
+++++ ++ +++ +
+
+++−10 −5 0 5 10
020
0040
0060
00
Generation 2
x
y
+++++ ++++++ +++ ++++++
−10 −5 0 5 10
020
0040
0060
00
Generation 3
x
y
++ ++
+
+++++ ++++ ++++++−10 −5 0 5 10
020
0040
0060
00
Generation 4
x
y
+++++++
+++++++++
+++−10 −5 0 5 10
020
0040
0060
00
Generation 5
x
y++++++++++++ ++++++++
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Looking at some statistics
0 500 1000 1500 2000-6
-4
-2
0
2
4
6
2000 runs, N=20, g=6
Histogram of x
x
Fre
quen
cy
−6 −4 −2 0 2 4 6
010
020
030
040
050
060
070
0
Min. 1st Qu. Median Mean 3rd Qu. Max.
-5.671 4.255 4.383 4.215 4.465 6.389
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
A hard problem
O(x) = |floor(x)|+ 0.5 (1.− (|x | − |floor(x)|))
Objective function
−10 −5 0 5 10 15 20
05
1015
20
x
y
Histogram of result of 2000 runs
N = 20 6 generations T = 1000Histogram of ga
ga
Fre
quen
cy
−2 0 2 4
050
100
150
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
A hand-calculated exampleSome experiments on simple problems
Statistics for the hard problem
Statistical results for different GA-parameters
Parms Min. 1st Qu. Median Mean 3rd Qu. Max.
20/6/1000 -2.930 0.221 0.580 0.636 0.920 4.40530/10/1000 -0.9550 0.2467 0.5070 0.5340 0.7930 2.9590
20/6/10 -3.4410 0.2357 0.5550 0.6158 0.8350 4.099030/10/10 -1.0000 0.2350 0.4990 0.5103 0.7552 2.9590
The algorithm fails to find the exact minimum, but identifies thegeneral regionMore iterations do not improve the mean/median performance, butdecrease diversity in the populationIn this case the parameter T has no big influence on the result
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Multi-objective optimizationA geophysical example
Outline
1 General remarks and comparison with other method
2 Genetic algorithms step-by-stepA hand-calculated exampleSome experiments on simple problems
3 Advanced topicsMulti-objective optimizationA geophysical example
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Multi-objective optimizationA geophysical example
Multi-objective optimization
Multi-objective optimization means that we try to minimize severalfunctions simultaneously.
O(xi ) =
O1(xi )O2(xi )
...OM(xi )
Usually the weighted norm of this vector is then minimized e.g
‖W · O(xi )‖2 =M∑
j=1
(WjOj(xi ))2
Genetic algorithms can also directly work on the vector withoutweighting.
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Multi-objective optimizationA geophysical example
Pareto optimality and domination
Domination:
(x <p y)⇔ (∀ i : xi ≤ yi ∧ ∃ i : xi < yi )
If a member of the population is not dominated by any other it iscalled nondominated or pareto-optimal.
10 20 30 40MT RMS
0
0,02
0,04
0,06
Mod
el R
ough
ness
Rank 1Rank 2Rank 3Rank 4
Population fitnessGeneration 1
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Multi-objective optimizationA geophysical example
Transforming rank into probability
Pi =
(1− r
rmax
)αr < rmax
0 r ≥ rmax
0 10 20 30 40Rank
0
0,2
0,4
0,6
0,8
1
α = 1 α = 2 α = 3 α = 4 α = 0.5
Fitness as a function of Rankr max = 40
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Multi-objective optimizationA geophysical example
Designing an objective function
In linearized methods the objective function has to be scalar and isa linear combination of the individual objective functions
Olin(di , si ) = WMTOMT (di , si ) + WRecORec(di , si ) + WRegOReg (xj)
WMT , WRec and Wreg are usually constant, but could be variableduring inversion.In contrast genetic algorithms can handle vector valued objectivefunctions without a need to weight the individual objectivefunctions.
Ogen(di , xj) =
OMT (di , f (xj))ORec(di , f (xj))
OReg (xj)
OMT (di , f (xj)) =
1
n
n∑i=1
(di − si∆di
)2
with si ∈ [ρa, φ, Z ]
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Multi-objective optimizationA geophysical example
Outline
1 General remarks and comparison with other method
2 Genetic algorithms step-by-stepA hand-calculated exampleSome experiments on simple problems
3 Advanced topicsMulti-objective optimizationA geophysical example
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Multi-objective optimizationA geophysical example
Inversion of synthetic data
A simple two-layer model is inverted to test the inversion.
0 10 20 30 40 50 60 702
3
4
5
6
7
8
S-Vel.DensityP-Vel.
Input model
0 10 20 30 40 50 60 70Depth [km]
20
40
60
80
100
120
140
Res
istiv
ity
0 20 40 602
3
4
5
6
7
8
S-Vel.DensityP-Vel.
Inversion result
0 20 40 60Depth [km]
0
20
40
60
80
100
120
140
Res
istiv
ity
0,01 1 100 10000 Period [s]
0
15
30
45
60
75
90
Pha
se
Input Data
Inversion
0,01 1 100 1000010
100
1000
ρ a [
Ωm
]
Data fitSynthetic Input model
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Multi-objective optimizationA geophysical example
Evolution of misfit and roughness
0,01 0,1 1 10 100MT Misfit
0,0001
Rec
. Fun
c. M
isfi
t
Iteration 0Iteration 20Iteration 40Iteration 60Iteration 80Iteration 100
Best modelsNo Regularization
0 50 100 150 2000,0001
0,001
0,01
0,1
1
10
100
1000
Max MisfitMin MisfitMedian MisfitMin RoughnessMedian Roughness
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Multi-objective optimizationA geophysical example
Inversion of a more realistic model
0,01 1 100 10000 Period [s]
0
15
30
45
60
75
90
Pha
se
Original data
Inversion result
0 1 100 1000010
100
1000
ρ a [
Ωm
]
Inversion fitMT Data
1 10 100Depth [km]
10
100
1000
ρ a [
Ωm
]
Original ModelInversion Result
MT Models
0 100 200 300 400 500Time [s]
0
0,02
0,04
Am
plitu
de
Inversion FitReceiver function data
1 10 100Depth [km]
1,5
2
2,5
3
3,5
4
4,5
5
Vs
[km
/s]
Inversion resultOriginal model
Receiver function model comparison
Max Moorkamp Genetic Algorithms
General remarks and comparison with other methodGenetic algorithms step-by-step
Advanced topicsSummary
Summary
Genetic algorithms can be applied to a wide range of problems
Their flexibility comes at the cost of more function evaluations
There are many variants of genetic algorithms available, eachwith its own strengths and weaknesses
Max Moorkamp Genetic Algorithms
Appendix For Further Reading
For Further Reading
D. E. GoldbergGenetic algorithms in search, optimization & machine learningAddison Wesley, 1990.
K. DebA Fast and Elitist Multiobjective Genetic Algorithm: NSGA-IIIEEE Transactions on Evolutionary Computation, Vol. 6, No.2, April 2002
Kanpur Genetic Algorithm LaboratoryNSGA-II and general informationhttp://www.iitk.ac.in/kangal/index.shtml
M. WallGALib programming library in C++http://lancet.mit.edu/ga
Max Moorkamp Genetic Algorithms