From Biological Systems to Computer Sciences and Back Pedro Pablo González e-mail: [email protected] ALMA MATER STUDIORUM UNIVERSITA’ DI BOLOGNA DEIS, SEDE DI CESENA, ITALIA Course and Lab
From Biological Systems to
Computer Sciences and Back
Pedro Pablo González
e-mail: [email protected]
ALMA MATER STUDIORUM UNIVERSITA’ DI BOLOGNA
DEIS, SEDE DI CESENA, ITALIA
Course and Lab
Introduction to Genetic Algorithms
Pedro Pablo González
Generation t
Generation t+1
Selection operator
Crossover operator
Crossover operator
Mutation operator
+
1001101111001100
1001110011001001
Genetic algorithms
Genetics
Genetic algorithm
Theory of natural selection
Searching
Optimization
Machine learning
Population of chromosomes
Fitness function
Genetic operators
task
task
task
Genetic algorithms: an overview
• Genetics algorithms (GAs) are adaptive heuristic
search algorithms inspired by evolutionary ideas of
natural selection and genetic
• GAs were proposed and developed by John
Holland and its colleagues at the University of
Michigan in the 1960s and the 1970s.
• Initial Holland’s aims were to improve the
understanding of natural adaptation process, and
to design artificial systems having properties
similar to natural systems.
Genetic algorithms: an overview
• A function to optimize
• A population of chromosomes (bit strings)
• Selection method according to fitness
• Crossover to generate new chromosomes
• Random mutation to alter the value of bits of
the new chromosomes
A genetic algorithm is characterized by the following
elements:
Genetic algorithms: the method
• Work on the encoding of the function
parameters, rarely work on the parameters
themselves
• Work on a search space (a population of
points)
• Use the only values of the function to
optimize
• Use probabilistic transition rules
Genetic algorithms for solving
computational problems
• Searching in a search space
• Optimization
• Machine learning
• Genetic programming
Genetic terminology
Values of fitness function variables
itself
Phenotype
Bit string encoding of the values of
fitness function variables
Genotype
Bit position on the string Locus
Bit valueAllele
Bit or characteristic Gene
Bit stringChromosome
Genetic algorithmGenetic terminology
Elements of genetic algorithms
• A population of strings (chromosomes)
• A fitness function
• A set of genetic operators: selection,
crossover and mutation
The simplest form of genetic algorithm involves three
types of elements:
Elements of genetic algorithms
To use a genetic algorithm, the potential solutions to the
problem must be encoded in string structures, known as
chromosomes. Each bit (locus) in the chromosome can take
two possible values: 0 and 1. Each chromosome represents a
complete solution to the problem to optimize, and it can be
thought of as a point in the search space of potential solutions.
Population of strings (chromosomes)
Encoded
Potential
solution
128Chromosome
1 0 0 0 0 0 0 0
gene o bit
Elements of genetic algorithms
Example of a population of chromosomes
01110
01001
11100
01101
11101
00101
11011
10011
Chromosome
14
9
28
13
29
5
27
19
Value
8
7
6
5
4
3
2
1
Element
number
• X takes integer
values into the
interval [0,31]
• Chromosome
length is equal to
5
Elements of genetic algorithms
A fitness function assigns a score or fitness to each
chromosome in the current population. The fitness function
determines how acceptable each chromosome is for the
solution to the problem at hand.
Fitness function
Examples of fitness function
( )[ ] ( ) ( )[ ] 2
1
2
1
∑∑==
−==K
k
K
k
kykdkeE
),( XWd
( )Ae
Af−+
=1
1
• Weighted function
• Distance measure
• Sigmoid function
• Sum of the square
error
j
N
j
j XWnet ∑=
=1
A first example
Consider the following net function defined for real numbers,
X, W ∈ R:
A = -W1*X1 + W2*X2 - W3*X3 +W4*X4 + W5*X5 - 70
where:
W = (W1, W2, W3, W4, W5) is the weight vector, and each Wi
takes integer values into the interval [0,31]
X = (X1, X2, X3, X4, X5) is the input pattern and takes the fixed
values (2, 4, 1, 3, 2)
We would like to maximize the function A using the
genetic algorithm approach
A first example
First, we need to encode decision variables (weight vectors)
into binary strings. Here 25 bits are used to represent a
variable W = (W1, W2, W3, W4, W5). In the chromosome
population each chromosome is composed by five genes, and
each gene is represented by a binary string of five bits. The
mapping from a chromosome string to a real numbers for a
variable W is completed as follows:
Wchromosome = W1gene + W2gene + W3gene + W4gene +
W5gene
and
Wigene Widecodes
(binary) (integer)
A first example
The chromosome population and the fitness values of the chromosomes for
the net function:
A = -W1*X1 + W2*X2 - W3*X3 +W4*X4 + W5*X5 - 70
are shown in the table below
3414 19 13 15 1201110100110110101111011008
809 17 15 23 2301001100010111110111101117
-5928 13 24 7 2211100011011100000111101106
-3113 6 21 11 601101001101010101011001105
3329 23 4 25 2211101101110010011001101104
455 13 13 20 1300101011010110110100011013
-2227 11 21 15 1711011010111010101111100012
1619 14 7 11 2110011011100011101011101011
FitnessValoriStringaNo.
Elements of genetic algorithms
Selection operator
The selection of strings in the current population is done
considering theirs fitness function values. The selection
operator randomly selects the better chromosomes in the
current population, allowing them to pass on their genetic
material to the new population.
Selection operator
Generation t
f = 200
f = 240
f = 180
f = 160
f = 80
f = 60
f = 100
f = 70 f = 200
f = 200
f = 240
f = 240
f = 240
f = 180
f = 100
f = 160
Elements of genetic algorithms
Selection operator
• Roulette selection. A random selection method where the
selection probability of an individual is proportional to its
fitness.
• Tournament selection. The roulette selection is used N times
to produce a tournament subset of chromosome. The selected
chromosome will be the best chromosome in the subset.
• Top percent selection. This operator randomly selects a
chromosome from the top N percent of the population. The
value N is specified by the user.
Selection operator can be implemented in different ways:
A first example
The chromosome population and the fitness values of the chromosomes for the net
function: A = -W1*X1 + W2*X2 - W3*X3 +W4*X4 + W5*X5 - 70 are shown in the table
below
≈≈≈≈ 100%736Total
15.48
21.73
2.85
6.65
15.35
16.98
7.88
13.04
AFitness/
FitnessT
114
160
21
49
113
125
58
96
AFitness
3414 19 13 15 1201110100110110101111011008
809 17 15 23 2301001100010111110111101117
-5928 13 24 7 2211100011011100000111101106
-3113 6 21 11 601101001101010101011001105
3329 23 4 25 2211101101110010011001101104
455 13 13 20 1300101011010110110100011013
-2227 11 21 15 1711011010111010101111100012
1619 14 7 11 2110011011100011101011101011
FitnessValoriStringaNo.
A first example
Eight chromosomes are selected from the original population
using the roulette selection method:
58-2211011010111010101111100012
1133311101101110010011001101104
1608001001100010111110111101117
1608001001100010111110111101117
12545 00101011010110110100011013
114
58
96
AFitness
3401110100110110101111011008
-2211011010111010101111100012
1610011011100011101011101011
FitnessStringaNo.
Elements of genetic algorithms
Crossover operator
The crossover operator commonly combines two
chromosomes (parents) to produce two new chromosomes
(offsprings). This operator randomly selects a crossover point
in the chromosome (position in the string) and exchanges the
subsequences before and after that point between two
chromosomes to create the two offsprings.
The crossover operator can choose one or two crossover
points for determining the subsequence to exchange.
Crossover occurs according to a crossover probability, which
is defined by user.
Elements of genetic algorithms
Crossover operator
f = 200
f = 200
f = 240
f = 240
f = 240
f = 180
f = 100
f = 160
1
2
3
4
5
6
7
8
6
2 2
6 6’
2’
Crossover length: l = 8
Crossover site: k = 5
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
A first example
1608001001100010111110111101117
1133311101101110010011001101104
AFitnessFitnessSelected chromosomeNo.
With crossover probability pc, crossover the pair of selected strings at a
randomly crossover point to form two offsprings. The crossover used here
is one-cut-point method, which randomly selects one cut-point and
exchanges the right parts of two parents to generate offspring.
Crossover point = 10
4: 1110110111001001100110110
7: 0100110001011111011110111
01001100010010011001101107’
11101101110111110111101114’
AFitnessFitnessOffspringsNo.
Elements of genetic algorithms
Mutation operator
The mutation operator alters one or more gene values in the
chromosome (character in the string). This operator can be
applied at each gene in the chromosome with some
probability, usually very small. The application of the mutation
operator can result in entirely new chromosome being added
to the new population. This fact could help to genetic
algorithm to arrive at better solution than was previously
possible.
Functioning of a genetic algorithm
Crossover operator (step 1)
Crossover operator (step 2)
Selection operator
Generation t
Generation t+1
Mutation operator
+
1001101111001100
1001110011001001
Functioning of a genetic algorithm
The genetic algorithm creates a population of chromosomes and then
applies the selection, crossover and mutation operators to the strings in the
current population to generate a new population. A simple GA works as
shown in figure above and its algorithm is as follows:
1. Encoding of the problem in a binary string
2. Random generation of a population of n strings of
length n (where each string or chromosome
represents a candidate solution to the problem)
3. Calculate the value of fitness function f(x) for each
string x in the population
4. Repeat the following steps until n offsprings have
been created:
Functioning of a genetic algorithm
� Selection of the pair of parents strings from the current
population according to their share in the population
global fitness
� With crossover probability pc, crossover the pair of
selected strings at a randomly crossover point to form
two offsprings
� With mutation probability pm, mutate the two offspring
� Copy the two news strings in the population
5. Replace the old population with the new population.
6. Go to 3.
Other genetic operators and techniques
Operator/techniqueGA phase
Two-point crossover
Parameterized uniform crossover
Crossover
Elitism
Steady-state selection
Selection
Inversion Encoding
The premature convergence problem
The scaling problem
In order to reduce the premature convergence problem, it’s
possible to transform the fitness values. Here we present
three main methods:
• Exponential. This method consists in taking the squared
roots of the fitness plus one. In this way, the influence of
the strongest subjects is reduced.
• Linear transformation. This method applies a linear
transformation to each fitness (i.e. f’ = a*f + b).
• Windowing. This method reduces the fitness of each
individual by the fitness of the worse individual in the
population.
GA schemas
• Schema. Genetic algorithms work in the space of
schemata. A schema is a set of bit strings that can be
described by a template made up of 1, 0 and *, the *
representing wild cards. A schema includes all the
strings with certain common string elements.
• Schema order. The order of a schema o(H) is the
number of fixed positions (1 or 0).
• Schema length. Schema length δ(H) is defined as the
distance between the first fixed position and the last
fixed position of the schema.
Genetic algorithm applications
• Evolving neural networks
• Evolving cellular automata
• Protein structure prediction
• Scheduling applications
• Automated design
• Learning robot behavior
• Electronic circuit design
• Game theory
• Image restoration
• Configuration applications
Genetic Algorithm tools
http://www.aridolan.com/ga/gaa/
gaa.html
It is a general purpose
genetic algorithm toolkit
where the user can
define and run his own
optimization problems
Genetic
Algorithms Toolkit
http://www.rennard.org/alife/engli
sh/gavgb.html
Demonstration applet of
the functioning of a
Genetic Algorithm
Genetic algorithm
viewer
httpDescriptionTool