Genetic Algorithm

Download Report

Transcript Genetic Algorithm

Genetic algorithms
Prof Kang Li
Email: [email protected]
Last lecture
 RBF
This Lecture
Genetic algorithm
Basic GA operations
2 /39


What is Genetic Algorithm?
How to implement GA?
◦
◦
◦
◦



Encoding
Selection
Crossover
Mutation
A example
Matlab demo
Differential evolution
3 /39




Bio-Inspired artificial intelligence
class of probabilistic optimization
algorithms
Well-suited for nonlinear/hard
problems with a large search
space
Influenced by Darwin’s Origin of
species
Developed by John Holland,
Adaptation in Natural and Artificial Systems,
U of Michigan Press, 1975
4 /39


Genetic contents -> survival capacity -> features
Reproduction
◦ recombination (or crossover) first occurs. Genes from parents
combine to form a whole new chromosome.
◦ Newly created offspring mutated, elements of DNA are changed.
 Diversity

Survival of the fittest
◦ Gene of the fittest survive, gene of weaker die out
◦ Elitism

Evolution - change of species’ feature to fit environment
5 /39
6 /39




Produce a population of candidate solutions for a given
problem
Use operators inspired by the mechanisms of natural
genetic variation
Apply selective pressure toward certain properties
Evolve to a more fit solution
7 /39
Nature
Computer
Population
Individual
Fitness
Chromosome
Gene
Set of solutions
Solution to a problem
Quality of a solution
Encoding for a Solution
Part of the encoding of a solution
8 /39
f ( x1, x2 )  x12  x22 x1, x2  [0,15]
196 
170 


200 


288


14 2 
7 11


10 10 


12
12


9
Simple_Genetic_Algorithm()
{
Initialize the Population;
Calculate Fitness Function;
While(the number of generation > maximum number)
{
Selection;//Natural Selection, Survival Of
Fittest
Crossover;//Reproduction, Propagate favorable
characteristics
Mutation;//Mutation
Calculate Fitness Function;
}
}
10 /39
crossover
selection
Search
space
A
0 1 0 0 0
B
1 0 1 1 0
C
1 1 0 1 0
D
0 1 0 1 1
1 0 1 1 0
1 0 0 1 1
0 1 0 1 1
0 1 1 1 0
mutation
1 0 0 1 1
Fitness
evaluation
population
0 1 1 1 0
reproduction
Substitution
11 /39
Initial population
5th generation
10th generation
12 /39

Difficult Problems such as NP-class
◦
◦
◦
◦
◦
◦
◦
◦
◦
◦
Nonlinear dynamical systems - predicting, data analysis
Designing neural networks, both architecture and weights
Robot Trajectory Planning
Evolving LISP programs (genetic programming)
Strategy planning
Finding shape of protein molecules
TSP and sequence scheduling
Functions for creating images
VLSI layout planning
…
13 /39
Encoding
Selection
Crossover
Mutation
14 /39

The process of representing the solution in the form of a
string that conveys the necessary information.

Just as in a chromosome, each gene controls a
particular characteristics of the individual, and each bit in
the string represents a characteristics of the solution.
15 /39

Binary Encoding
Most common method of encoding. Chromosomes are strings
of 1s and 0s and a gene of chromosomes represents the a
particular characteristics of the problem.
Chromosome A
10110010110011100101
Chromosome B
11111110000000011111
16 /39

Permutation Encoding
Useful in ordering problems such as the Traveling Salesman
Problem (TSP). Example. In TSP, every chromosome is a
string of numbers, each of which represents a city to be
visited.
Chromosome A
1 5 3 2 6 4 7 9 8
Chromosome B
8 5 6 7 2 3 1 4 9
17 /39

Value Encoding
Used in problems where complicated values, such as real
numbers, are used and where binary encoding would not
suffice. Good for some problems, but often necessary to
develop some specific crossover and mutation techniques for
these chromosomes.
Chromosome A
1.235 5.323 0.454 2.321 2.454
Chromosome B
(left), (back), (left), (right), (forward)
18 /39

Based on fitness function:
◦ Determines how ‘good’ an individual is (fitness)
◦ Better fitness, higher probability of survival



Selection of individuals for differential reproduction of
offspring in next generation
Favors better solutions
Decreases diversity in population
A C
19 /39

Each solution gets a region
on a roulette wheel
according to its fitness

Spin wheel, select solution
marked by roulette-wheel
pointer

stochastic selection
(better fitness = higher
chance of reproduction)
Individual i will have a
f (i )
 f (i)
i
probability to be chosen20 /39

randomly select q individuals from current population

Winner:
individual(s) with best fitness among these q individuals

Example:
select the best two individuals as parents for recombination
q=6
selection
21 /39
Crossover is a critical feature of genetic algorithms:




Crossover process simulates the exchange of genetic material that occurs
during biological reproduction
In this process pairs in the breeding population are mated randomly with a
crossover rate, Pc
Typical crossover properties include that an offspring inherits the common
feature from the parents along with the ability of the offspring to inherit two
completely different features
Popular crossover techniques: one point, two point and uniform crossover
Chromosome A
…
…
Chromosome B
…
…
Chromosome A*
…
…
Chromosome B*
…
…
22 /39

Single point crossover
11001011+11011111 = 11001111+11011011

Two point Crossover
11001011 + 11011110 = 11011111+11001010
23 /39
Uniform crossover : bits are randomly copied from the parents
11001011 + 11011101 = 11011111
if random-number > Crossover-rate then Crossover
otherwise remain unaltered




Mutation consists of making small alterations to the values of one or
more genes in a chromosome
Mutation randomly perturbs the population’s characteristics, and
prevents evolutionary dead ends
Most mutations are damaging rather than beneficial and hence
mutation rate must be low to avoid the destruction of species
It works by randomly selecting a bit with a certain mutation rate in
the string and reversing its value
42
58
Offspring
0010 1010
Mutated Offspring
0011 1010
25 /39

A measure of how successful an individual is in the
environment
◦ Problem dependent

Given chromosome, the fitness function returns a
number
◦ f:SR

Smooth and regular
◦ Similar chromosomes produce close fitness values
◦ Not have too many local extremes and isolated global extreme
26 /39

Finding the maximum of a function:
◦ f(x) = x²
◦ Range [0, 31] Goal: find max (31² = 961)
◦ Binary representation: string length 5 = 32 numbers (0-31)
= f(x)
27 /39

Typical parameter values
◦ population size : 30 -100
◦ crossover rate : 0.7 -1
◦ mutation rate : 0.01 - 0.2
binary
value
fitness
String 1
00110
6
36
String 2
00011
3
9
String 3
01010
10
100
String 4
10101
21
441
String 5
00001
1
1
28 /39

binary
value
fitness
String 1
00110
6
36
6.13%
String 2
00011
3
9
1.53%
String 3
01010
10
100
17.04%
String 4
10101
21
441
75.13%
String 5
00001
1
1
0.17%
Worst one removed
29 /39

binary
value
fitness
String 1
00110
6
36
String 2
00011
3
9
String 3
01010
10
100
String 4
10101
21
441
String 5
00001
1
1
Best individual: reproduces twice  keep population size
constant
30 /39

binary
value
fitness
String 1
00110
6
36
String 2
00011
3
9
String 3
01010
10
100
String 4
10101
21
441
String 5
10101
21
441
All others are reproduced once
31 /39
Parents and x-position
randomly selected
partner
x-position
String 1
String 2
4
String 3
String 4
2
String 1:
6
0 0 1 1 0
0 0 1 1 1
7
String 2:
3
0 0 0 1 1
0 0 0 1 0
23
String 3:
10
0 1 0 1 0
0 1 1 0 1
21
String 4:
21
1 0 1 0 1
1 0 0 1 0
17
32 /39

bit-flip
◦ Offspring -String 1:
00111 (7)
◦ Offspring -String 3:
10101 (21)
10111 (23)
10001 (17)
33 /39
• All individuals in the parent population are replaced by
offspring in the new generation
• (generations are discrete!)
• New population (Offspring):
String 1
String 2
String 3
String 4
String 5
binary
00111
10111
10101
10001
10101
value
7
23
21
17
21
fitness
49
529
441
289
441
34 /39

Iterate until termination condition reached, e.g.:
◦
◦
◦
◦

Number of generations
Best fitness
Process time
No improvements after a number of generations
Result after one generation:
◦ Best individual: 10111 (23) – fitness 529

Best solution after 100 generation:
◦ Best solution: 11111 (31) – fitness 961
35 /39





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
36 /39


Introduction to GA
Basic GA operations
37 /39