Upload
alok-anand-narayan-tripathi
View
238
Download
0
Embed Size (px)
Citation preview
8/2/2019 assaf-ga (1)
1/57
Introduction to Genetic Algorithms 1
Introduction to
Genetic Algorithms
Assaf Zaritsky
Ben-Gurion University, Israel
www.cs.bgu.ac.il/~assafza
8/2/2019 assaf-ga (1)
2/57
Introduction to Genetic Algorithms 2
Genetic Algorithms (GA)
OVERVIEW
A class of probabilistic optimization algorithms
Inspired by the biological evolution process
Uses concepts of Natural Selection andGenetic Inheritance (Darwin 1859)
Originally developed by John Holland (1975)
8/2/2019 assaf-ga (1)
3/57
Introduction to Genetic Algorithms 3
GA overview (cont)
Particularly well suited for hard problems wherelittle is known about the underlying search space
Widely-used in business, science and engineering
8/2/2019 assaf-ga (1)
4/57
Introduction to Genetic Algorithms 4
Classes of Search Techniques
Search Techniqes
Calculus Base
TechniqesGuided random search
techniqes
Enumerative
Techniqes
BFSDFS DynamicProgramming
Tabu Search Hill
Climbing
Simulated
Anealing
Evolutionary
Algorithms
Genetic
Programming
Genetic
Algorithms
Fibonacci Sort
8/2/2019 assaf-ga (1)
5/57
Introduction to Genetic Algorithms 5
A genetic algorithm maintains a
population of candidate solutions
for theproblemat hand,
and makes it evolve by
iteratively applying
a set of stochastic operators
8/2/2019 assaf-ga (1)
6/57
Introduction to Genetic Algorithms 6
Stochastic operators
Selection replicates the most successfulsolutions found in a population at a rate
proportional to their relativequalityRecombinationdecomposes two distinctsolutions and then randomly mixes their partsto form novel solutions
Mutation randomly perturbs a candidatesolution
8/2/2019 assaf-ga (1)
7/57Introduction to Genetic Algorithms 7
The Metaphor
NatureGenetic Algorithm
EnvironmentOptimization problem
Individuals living in thatenvironment
Feasible solutions
Individuals degree of
adaptation to itssurrounding environment
Solutions quality (fitness
function)
8/2/2019 assaf-ga (1)
8/57Introduction to Genetic Algorithms 8
The Metaphor (cont)
NatureGenetic Algorithm
A population of organisms(species)
A set of feasible solutions
Selection, recombinationand mutation in naturesevolutionary process
Stochastic operators
Evolution of populations tosuit their environment
Iteratively applying a setof stochastic operators ona set of feasible solutions
8/2/2019 assaf-ga (1)
9/57Introduction to Genetic Algorithms 9
The Metaphor (cont)
The computer model introduces simplifications
(relative to the real biological mechanisms),BUT
surprisingly complex and interesting structures
have emerged out of evolutionary algorithms
8/2/2019 assaf-ga (1)
10/57Introduction to Genetic Algorithms 10
Simple Genetic Algorithmproduce 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
8/2/2019 assaf-ga (1)
11/57Introduction to Genetic Algorithms 11
The Evolutionary Cycle
selection
population evaluation
modification
discard
deleted
members
parents
modified
offspring
evaluated offspring
initiate &
evaluate
8/2/2019 assaf-ga (1)
12/57
Introduction to Genetic Algorithms 12
8/2/2019 assaf-ga (1)
13/57
Introduction to Genetic Algorithms 13
Example:
the MAXONE problem
Suppose we want to maximize the number ofones in a string of l binary digits
Is it a trivial problem?
It may seem so because we know the answer inadvance
However, we can think of it as maximizing thenumber of correct answers, each encoded by 1,to l yes/no difficult questions`
8/2/2019 assaf-ga (1)
14/57
Introduction to Genetic Algorithms 14
Example (cont)
An individual is encoded (naturally) as astring of l binary digits
The fitnessfof a candidate solution to theMAXONE problem is the number of ones inits genetic code
We start with a population of nrandomstrings. Suppose that l = 10 and n= 6
8/2/2019 assaf-ga (1)
15/57
Introduction to Genetic Algorithms 15
Example (initialization)
We toss a fair coin 60 times and get thefollowing 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
8/2/2019 assaf-ga (1)
16/57
Introduction to Genetic Algorithms 16
Example (selection1)
Next we apply fitness proportionate selection with theroulette wheel method:
21n
3
Area is
Proportional
to fitness
value
Individual i will havea
probability to be chosen
i
if
if
)(
)(
4
We repeat the extractionas many times as thenumber of individuals we
need to have the sameparent population size(6 in our case)
8/2/2019 assaf-ga (1)
17/57
Introduction to Genetic Algorithms 17
Example (selection2)
Suppose that, after performing selection, we getthe following population:
s1` = 1111010101 (s1)
s2` = 1110110101 (s3)
s3` = 1110111101 (s5)
s4` = 0111000101 (s2)
s5` = 0100010011 (s4)
s6` = 1110111101 (s5)
8/2/2019 assaf-ga (1)
18/57
Introduction to Genetic Algorithms 18
Example (crossover1)
Next we mate strings for crossover. For eachcouple we decide according to crossoverprobability (for instance 0.6) whether to actually
perform crossover or notSuppose that we decide to actually performcrossover only for couples (s1`, s2`) and (s5`, s6`).
For each couple, we randomly extract acrossover point, for instance 2 for the first and 5for the second
8/2/2019 assaf-ga (1)
19/57
Introduction to Genetic Algorithms 19
Example (crossover2)
s1` = 1111010101
s2` = 1110110101
s5` = 0100010011
s6` = 1110111101
Before crossover:
After crossover:
s1`` = 1110110101
s2`` = 1111010101
s5`` = 0100011101
s6`` = 1110110011
8/2/2019 assaf-ga (1)
20/57
Introduction to Genetic Algorithms 20
Example (mutation1)
The final step is to apply random mutation: for each bit that
we are to copy to the new population we allow a smallprobability of error (for instance 0.1)
Before applying mutation:
s1`` = 1110110101
s2`` = 1111010101
s3`` = 1110111101
s4`` = 0111000101
s5`` = 0100011101
s6`` = 1110110011
8/2/2019 assaf-ga (1)
21/57
Introduction to Genetic Algorithms 21
Example (mutation2)
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
8/2/2019 assaf-ga (1)
22/57
Introduction to Genetic Algorithms 22
Example (end)
In one generation, the total population fitnesschanged from 34 to 37, thus improved by ~9%
At this point, we go through the same processall over again, until a stopping criterion is met
8/2/2019 assaf-ga (1)
23/57
Introduction to Genetic Algorithms 23
8/2/2019 assaf-ga (1)
24/57
Introduction to Genetic Algorithms 24
Components of a GA
A problem definition as input, and
Encoding principles (gene, chromosome)
Initialization procedure (creation)Selection of parents (reproduction)
Genetic operators (mutation, recombination)
Evaluation function (environment)Termination condition
8/2/2019 assaf-ga (1)
25/57
Introduction to Genetic Algorithms 25
Representation (encoding)
Possible individuals encoding
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 ...
8/2/2019 assaf-ga (1)
26/57
Introduction to Genetic Algorithms 26
Representation (cont)
When choosing an encoding method rely on thefollowing key ideas
Use a data structure as close as possible to thenatural representation
Write appropriate genetic operators as needed
If possible, ensure that all genotypes correspond
to feasible solutionsIf possible, ensure that genetic operatorspreserve feasibility
8/2/2019 assaf-ga (1)
27/57
Introduction to Genetic Algorithms 27
Initialization
Start with a population of randomlygenerated individuals, or use- A previously saved population- A set of solutions provided by
a human expert- A set of solutions provided by
another heuristic algorithm
8/2/2019 assaf-ga (1)
28/57
Introduction to Genetic Algorithms 28
Selection
Purpose: to focus the search in promisingregions of the space
Inspiration: Darwins survival of the fittest
Trade-off between exploration and exploitationof the search space
Next we shall discuss possible selection methods
8/2/2019 assaf-ga (1)
29/57
Introduction to Genetic Algorithms 29
Fitness Proportionate Selection
Derived by Holland as the optimal trade-offbetween exploration and exploitation
DrawbacksDifferent selection forf1(x) andf2(x) = f1(x) + c
Superindividualscause convergence (that maybe premature)
8/2/2019 assaf-ga (1)
30/57
Introduction to Genetic Algorithms 30
Linear Ranking Selection
Based on sorting of individuals by decreasing fitness
The probability to be extracted for the ith individual
in the ranking is defined as
21,1
1)1(2
1)(
n
i
nip
wherecan be interpreted as
the expected sampling rate ofthe best individual
8/2/2019 assaf-ga (1)
31/57
Introduction to Genetic Algorithms 31
Local Tournament Selection
Extracts kindividuals from the populationwith uniform probability (without re-insertion)
and makes them play a tournament,where the probability for an individual to winis generally proportional to its fitness
Selection pressure is directly proportional tothe number kof participants
8/2/2019 assaf-ga (1)
32/57
Introduction to Genetic Algorithms 32
Recombination (Crossover)
* Enables the evolutionary processto move toward promising
regions of the search space* Matches good parents sub-solutions
to construct better offspring
8/2/2019 assaf-ga (1)
33/57
Introduction to Genetic Algorithms 33
Mutation
Purpose: to simulate the effect of errors thathappen with low probability during duplication
Results:
- Movement in the search space
- Restoration of lost information to the population
8/2/2019 assaf-ga (1)
34/57
Introduction to Genetic Algorithms 34
Evaluation (fitness function)
Solution is only as good as the evaluationfunction; choosing a good one is often the
hardest partSimilar-encoded solutions should have asimilar fitness
8/2/2019 assaf-ga (1)
35/57
Introduction to Genetic Algorithms 35
Termination condition
Examples:
A pre-determined number of generations or time
has elapsed
A satisfactory solution has been achieved
No improvement in solution quality has taken
place for a pre-determined number of generations
8/2/2019 assaf-ga (1)
36/57
Introduction to Genetic Algorithms 36
8/2/2019 assaf-ga (1)
37/57
Introduction to Genetic Algorithms 37
Another Example:
The Traveling Salesman
Problem (TSP)
The traveling salesman must visit every city in histerritory exactly once and then return to the starting
point; given the cost of travel between all cities, howshould he plan his itinerary for minimum total cost ofthe entire tour?
TSP NP-Complete
Note: we shall discuss a single possible approachto approximate the TSP by GAs
TSP (R t ti E l ti
8/2/2019 assaf-ga (1)
38/57
Introduction to Genetic Algorithms 38
TSP (Representation, Evaluation,
Initialization and Selection)
A vector v = (i1 i2 in) represents a tour (v is apermutation of {1,2,,n})
Fitnessfof a solution is the inverse cost of the
corresponding tour
Initialization: use either some heuristics, or arandom sample of permutations of {1,2,,n}
We shall use the fitness proportionate selection
8/2/2019 assaf-ga (1)
39/57
Introduction to Genetic Algorithms 39
TSP (Crossover1)
OX builds offspring by choosing a sub-sequence ofa tour from one parent and preserving the relativeorder of cities from the other parent and feasibility
Example:
p1= (1 2 3 4 5 6 7 8 9) and
p2= (4 5 2 1 8 7 6 9 3)
First, the segments between cut points are copied into offspringo1= (x x x 4 5 6 7 x x) and
o2= (x x x 1 8 7 6 x x)
8/2/2019 assaf-ga (1)
40/57
Introduction to Genetic Algorithms 40
TSP (Crossover2)
Next, starting from the second cut point of one parent, thecities from the other parent are copied in the same order
The sequence of the cities in the second parent is9 3 4 5 2 1 8 7 6
After removal of cities from the first offspring we get9 3 2 1 8
This sequence is placed in the first offspring
o1= (2 1 8 4 5 6 7 9 3), and similarly in the second
o2= (3 4 5 1 8 7 6 9 2)
8/2/2019 assaf-ga (1)
41/57
Introduction to Genetic Algorithms 41
TSP (Inversion)
The sub-string between two randomly selected
points in the path is reversed
Example:
(1 2 3 4 5 6 7 8 9) is changed into (1 2 7 6 5 4 3 8 9)
Such simple inversion guarantees that theresulting offspring is a legal tour
8/2/2019 assaf-ga (1)
42/57
Introduction to Genetic Algorithms 42
8/2/2019 assaf-ga (1)
43/57
Introduction to Genetic Algorithms 43
GAs: Why Do They Work?
In this section we take an in-depth look at theworking of the standard genetic algorithm,explaining why GAs constitute an effectivesearch procedure
For simplicity we discuss binary string
representation of individuals
8/2/2019 assaf-ga (1)
44/57
Introduction to Genetic Algorithms 44
Notation (schema)
{0,1,#} is the symbol alphabet, where # is aspecial wild cardsymbol
A schema is a template consisting of a stringcomposed of these three symbols
Example: the schema [01#1#] matches thestrings: [01010], [01011], [01110] and [01111]
8/2/2019 assaf-ga (1)
45/57
Introduction to Genetic Algorithms 45
Notation (order)
The orderof the schema S (denoted by o(S)) is thenumber of fixed positions (0 or 1) presented in theschema
Example: for S1 = [01#1#], o(S1) = 3for S2 = [##1#1010], o(S2) = 5
The order of a schema is useful to calculate
survival probability of the schema for mutations
There are 2l-o(S)
different strings that match S
8/2/2019 assaf-ga (1)
46/57
Introduction to Genetic Algorithms 46
Notation (defining length)
The defining length of schema S (denoted by (S)) is thedistance between the first and last fixed positions in it
Example: for S1 = [01#1#], (S1) = 4 1 = 3,
for S2 = [##1#1010], (S2) = 8 3 = 5
The defining length of a schema is useful to calculatesurvival probability of the schema for crossovers
8/2/2019 assaf-ga (1)
47/57
Introduction to Genetic Algorithms 47
Notation (cont)
m(S,t) is the number of individuals in thepopulation belonging to a particular schema Sat time t (in terms of generations)
fS(t) is the average fitness value of stringsbelonging to schema S at time t
f(t) is the average fitness value over all stringsin the population
8/2/2019 assaf-ga (1)
48/57
Introduction to Genetic Algorithms 48
The effect ofSelection
Under fitness-proportionate selection the expectednumber of individuals belonging to schema S at time(t+1) is m (S,t+1) = m (S,t) (fS(t)/f(t) )
Assuming that a schema S remains above averageby 0 c, (i.e., fS(t) =f(t) + cf(t) ), then
m (S,t) = m (S,0) (1 + c)t
Significance: aboveaverage schema receives anexponentially increasing number of strings in thenext generation
8/2/2019 assaf-ga (1)
49/57
Introduction to Genetic Algorithms 49
The effect ofCrossover
The probability of schema S (|S| = l) to survivecrossover is ps(S) 1pc((S)/(l1))
The combined effect of selection and crossover
yields
m (S,t+1) m (S,t) (fS(t)/f(t) ) [1 - pc((S)/(l1))]
Above-average schemata with short defining lengthswould still be sampled at exponentially increasingrates
8/2/2019 assaf-ga (1)
50/57
Introduction to Genetic Algorithms 50
The effect ofMutation
The probability of S to survive mutation is:ps(S) = (1pm)
o(S)
Sincepm
8/2/2019 assaf-ga (1)
51/57
Introduction to Genetic Algorithms 51
Schema Theorem
Short, low-order, above-average schemata receiveexponentially increasing trials in subsequent
generations of a genetic algorithm
Result: GAs explore the search space by short,low-order schemata which, subsequently, are
used for information exchange during crossover
8/2/2019 assaf-ga (1)
52/57
Introduction to Genetic Algorithms 52
Building Block Hypothesis
A genetic algorithm seeks near-optimal performance
through the juxtaposition of short, low-order, high-
performance schemata, called the building blocks
The building block hypothesis has been foundto apply in many cases but it depends on the
representation and genetic operators used
8/2/2019 assaf-ga (1)
53/57
Introduction to Genetic Algorithms 53
Building Block Hypothesis (cont)
It is easy to construct examples for which the above
hypothesis does not hold:
S1 = [111#######] and S2 = [########11]
are above average, but their combination
S3 = [111#####11] is much less fit than S4 = [000#####00]
Assume further that the optimal string is S0 = [1111111111]. AGA may have some difficulties in converging to S0, since itmay tend to converge to points like [0001111100].
Some building blocks (short, low-order schemata) canmislead GA and cause its convergence to suboptimal points
8/2/2019 assaf-ga (1)
54/57
Introduction to Genetic Algorithms 54
Building Block Hypothesis (cont)
Dealing with deception:
Code the fitness function in an appropriate way
(assumes prior knowledge)
or
Use a third genetic operator, inversion
8/2/2019 assaf-ga (1)
55/57
Introduction to Genetic Algorithms 55
A b i f i t d ti t
8/2/2019 assaf-ga (1)
56/57
Introduction to Genetic Algorithms 56
A brief introduction to
Co-evolution
Two or more species evolve and interactthrough the fitness function
Closer to real biological systemsCompetitive (prey-predator) or Cooperative
Examples: Hillis (competitive), my work(cooperative)
References
8/2/2019 assaf-ga (1)
57/57
References
C. Darwin. On the Origin of Species by Means of Natural Selection;or, the Preservation of flavored Races in the Struggle for Life. John
Murray, London, 1859.W. D. Hillis. Co-Evolving Parasites Improve Simulated Evolution asan Optimization Procedure. Artificial Life 2, vol 10, Addison-Wesley, 1991.
J.H. Holland. Adaptation in Natural and Artificial Systems. TheUniversity of Michigan Press, Ann Arbor, Michigan, 1975.
Z.Michalewicz. Genetic Algorithms + Data Structures = EvolutionPrograms. Springer-Verlag, Berlin, third edition, 1996.
M. Sipper. Machine Nature: The Coming Age of Bio-InspiredComputing. McGraw-Hill, New-York, first edition, 2002.
M. Tomassini. Evolutionary algorithms. In E.Sanchez andM.Tomassini, editors, Towards Evolvable Hardware, volume 1062
of Lecture Notes in Computer Science, pages 19-47. Springer-Verlag, Berlin, 1996.