You are on page 1of 56

Evolutionary Computation

Stefano Cagnoni
Introduction
Natural Evolution

In every population in nature mutations occur from time to


time.

Mutations may be disruptive, but may also generate


individuals who are fitter, with respect to the environment.
These will survive longer (natural selection) producing more
numerous offspring (reproduction).

Their offspring partly share their parents’ genetic


characters (chromosomes, made up of genes), partly define
new types, obtained by mixing such characters (crossover).
Natural Evolution

Since fitter individuals are more likely to reproduce, the


following generations are also more likely to share the same
characters as their ‘ancestors’ who had the highest fitness with
respect to the environment.

An individual’s genetic code is called genotype. The


manifestation of the characters encoded in such a code (the
individual itself) is called phenotype.
Artificial Evolution

Computational models of evolution exist, which emulate


natural evolution, to achieve the same results in engineering
problems.

In practice, they implement an iterative process (artificial


evolution) which leads to effective solutions to a given
problem. Solutions improve over generations until they
converge to an optimum, starting from an initial pool of very
approximate, or even randomly generated, solutions.
Artificial Evolution

Formally, given a problem and a function (fitness function)


which can measure how good a solution to the problem is,
processes modeled on natural evolution are used to generate
solutions that have the highest possible fitness, i.e., that
optimize (maximize) the fitness function. This is defined from
the space X of the solutions (e.g., the n_ples of parameters
which encode a solution) to the positive real axis.

In summary, such processes search a solution


fX : f = max (Fitness : X  R+)
X
Natural to artificial evolution mapping

Individual Solution to a problem


Population A set of solutions
Fitness Quality of a solution
Genome Representation of a solution
Chromosome* Component of a representation
Gene* Basic element of a representation
Crossover, Mutation Operators used to search
solutions
Natural Selection Re-use of good solutions
Evolution Search of good solutions
*only for Genetic Algorithms
Evolutionary Computation
EC includes several computational models that reproduce
natural evolution processes to optimize a goal which is
generally represented as a function.

In science it is applied to:


• Verification of hypotheses in biology, sociology, religion,
etc. through simulations

In engineering to:
• Combinatorial/Function Optimization
• Machine Learning
• In general, search for solutions to hard problems
Components of an evolutionary
algorithm
An evolutionary algorithm is fully determined when its
essential components have been defined

1. Representation (encoding)
2. Evaluation Function (fitness function)
3. Population
4. (Parents’) Selection Strategy
5. Operators (Modification/recombination)
6. Survivors’ Selection Strategy (Substitution)
7. Initialization Strategy
8. Termination Condition
General evolutionary algorithm
A typical evolutionary algorithm is composed of the following
steps:

1. Initialize a population
2. Evaluate population’s fitness
3. repeat
a. select a population subset, based on fitness
b.from the selected individuals, generate a new
population using modification/recombination operators
c. Evaluate the new population’s fitness
until a termination criterion is met
Genetic Algorithms
Genetic Algorithms
Genetic algorithms operate on solution encodings to obtain
new solutions: in genetic terms, only the genotype is affected
(as happens in nature). A genotype-to-phenotype decoding
mechanism needs to be defined, by which a solution is
produced from its encoding, in order to evaluate its
effectiveness.

Chromosomes (solutions) are represented as strings of


symbols, most often bits or real numbers.
Individuals may be anything that can be represented by a
string of symbols.
Phenotypes may be, for example, vectors of parameters, list of
possible choices, etc.
Basic Genetic Algorithm
1. Generate a random population of chromosomes.
2. repeat
a. Decode each chromosome into an individual.
b. Evaluate each individual’s fitness.
c. Generate a new population, partly by cloning (copying),
partly by recombining, partly by mutating the
chromosomes of some selected (usually the fittest)
individuals
until a termination condition is met.
The main features of a GA are the encoding of individuals as
strings of symbols and the use of both the mutation and
recombination operators.
Components of a
Genetic Algorithm
Representation (n-bit chromosome)
An n-bit string can be used to represent:

− Numbers
Integers (from 0 to 2n-1, from K to K+2n-1,
from 0 to M with M≠2n-1)
Real Numbers

− Elements belonging to finite sets, for which a


correspondence with the numerable set of the 2n
possible combinations is possible

− Vectors of numbers or parameters


Representation
A GA works better if similar representations represent
similar entities
The Gray Code is often used, in which representations of
consecutive integers differ by 1 bit
Gray Bin Gray Bin
0 000 000 4 110 100
1 001 001 5 111 101
2 011 010 6 101 110
3 010 011 7 100 111

Inverting one bit produces small changes. However, when the


change is large, it is larger than with the traditional binary
encoding.
Fitness Function

It is the objective function of the optimization performed by


the GA and, in general, by all evolutionary algorithms.
It must measure the effectiveness of a solution and satisfy
the following fundamental hypotheses:

1. A measure Q exists for the quality of a solution.


2. Q is positive
3. It must be maximized
4. An individual’s Q is its fitness
Population

A population is a multi-set, i.e., a set which admits the


presence of more copies of the same element, of solutions
(points in the search space).
It is characterized by its size (number of individuals) and,
possibly, by a spatial structure such that genetic operators
can affect only members of the same neighborhood.
The population size is most often kept constant through the
generations.
The population diversity is the number of different individuals
within the population, i.e. the number of distinct elements of
the multi-set.
Selection

Selection is the strategy according to which individuals


(actually their genotypes, represented by the chromosomes)
are selected for reproduction.

To simulate natural selection, higher-fitness individuals must


have higher probability to be selected.
To achieve this goal, different selection strategies may be
adopted, some of which are not biologically plausible.
Selection

Usually in a genetic algorithm:

1. A set of solutions is selected for mating (mating pool)

2. Pairs of individuals are randomly extracted from the


mating pool and are coupled (sexual reproduction)

Offspring inherit part of their genotype from one parent


and the rest from the other parent.
Selection

Fitness-proportionate selection

The most commonly-used selection strategy.

Each individual is assigned a probability to be selected,


which is proportional to its fitness

pi = fi / Skfk

NB It is properly a probability, since Si pi = 1


Selection

Implementation (fitness-proportionate selection)

Suppose 4 individuals have fitness

f1=f2=10 f3=15 f4=25

Then (probability of selection):

p1=p2=1/6 p3=1/4 p4=5/12


Selection
Implementation (fitness-proportionate selection)
1. Roulette-wheel strategy

Each individual is assigned a wheel sector, whose size is


proportional to its fitness. Every position of the arrow
corresponds to a number. A random number is extracted and
the individual which ‘owns’ the region where the arrow is
pointing, is selected.
Selection

2. Vector of size N 112233344444


0 N-1
Each individual is represented in the vector for a number
of times proportional to its fitness. A random number from
0 to N-1 is generated and the individual corresponding to
the vector value in that position is selected.

3. Real number between 0 e Sj fj


The fitness values are ‘enqueued’, and a random number r
in that interval is extracted. An individual i is selected such
that Sj=1,i-1 fj  r < Sj=1,i fj
Selection
Fitness-proportionate selection is implemented easily, but it
may have problems of opposite nature:

Premature convergence
If an individual’s fitness is much higher than the average
population fitness, but much lower than the optimum, it
tends to be repeatedly selected and a mediocre uniform
population is generated.

Stagnation
If all individuals have similar fitness, they tend to have the
same selection probability, causing the optimization strategy
to become a random search.
Selection
Rank selection
Individuals ranked by fitness (in descending order).
A probability distribution function, decreasing with rank, is
defined, independent of fitness values.

Advantages
No premature convergence: no individual can have a
selection probability much higher than any other.
No stagnation: the probability distribution does not change.
Disadvantages
Computationally heavier.

Note: it is not biologically plausible.


Selection

Tournament selection
To select each individual, a random subset of the population
of predefined size is picked, and the best is selected.

Advantages
Same as rank-based selection, with no need for ordering.
Selection
Elitist Selection (applicable also to survivors’ selection)
At least one copy of the best individual is kept in the new
generation.

Advantages
Good solutions are not lost due to ‘random’ selection
strategies

Disadvantages.
If the best individual’s characters become dominant, this
may lead to premature convergence.
Genetic operators: Crossover

Offspring (i.e., children) is generated by recombining genetic


material of individuals comprised in the mating pool. This is
called crossover or recombination.

Crossover generates, as does sexual reproduction in nature,


new individuals whose genetic code derives partly from one
parent and partly from the other one.
Genetic operators: Crossover
SINGLE-POINT CROSSOVER
1110001101001010 1000100111001010 PARENTS

1110000111001010 1000101101001010 OFFSPRING

A point within the genome is randomly chosen and the right


or left sections are swapped
TWO-POINT CROSSOVER
1110001101001010 1000100111001010 PARENTS

1110100111001010 1000001101001010 OFFSPRING

The string is circular. Two ‘cuts’ are made and the inner or
outer sections are swapped
Genetic operators: Crossover

UNIFORM CROSSOVER
1110001101001010 1000100111001010 PARENTS

1010000111001010 1100101101001010 OFFSPRING


Each bit is randomly selected from one of the two parents for
the first child and from the other parent for the second one.
The same operators can be used if integer vectors are used
for representation.
Genetic operators: Crossover

If floating point vectors are used for the representation, the


operators are conceptually similar.
However, instead of defining the representation for the
offspring by copying elements from one of the two parents
x = <x1, x2,.., xN> and y = <y1, y2,.., yN> they perform a
weighted sum of their values.
Genetic operators: Crossover

Simple Recombination: a point k is selected and a<1


Child1:
< x1, x2,.., xk , a yk+1 + (1-a) xk+1, .., a yN + (1-a) xN >
Child2, same as Child1 but x and y are swapped

Single Recombination: a point k is chosen and a<1


Child1: < x1, x2, … , a yk + (1-a) xk, xk+1 …. , xN >
Child2, same as Child1 but x and y are swapped

Full recombination
Child1: a y + (1-a) x Child2: a x + (1-a) y
Crossover for permutations
Partially-mapped crossover (PMX)
1. Two points are chosen and the values within them are
copied into C1
P1 : 123456789 P2: 937826514
C1: ...4567..
2. Starting from the first point, the elements of P2 ,
comprised between the two selected points, which have
not been copied yet are considered
3. For each of them (i) the element (j) of C1 which occupies
the corresponding position is considered
Crossover for permutations
Partially-mapped crossover (PMX) (cont.):
4. i is moved into the position occupied by j in P2
C1: ...4567.8
5. If the position occupied by j in P2 has already been taken in
C1 by k, i is moved into the position occupied by k in P2
C1: ..24567.8
6. The other elements of C1 are directly copied from P2
C1: 932456718 .
C2 is created similarly, swapping the parents.
Genetic operators: mutation
Mutation is aimed at maintaining genetic diversity, to try and
explore also regions in the search space which are not
‘occupied’ by the present population.
Mutation for binary representations
A bit is chosen randomly and is inverted.
1001010010101 1000010010101
Mutation for integer representations
It is possible to substitute a gene with a valid random value,
or add a positive or negative quantity to it, from a probability
distribution having its maximum in zero.
Genetic operators: mutation
Mutation for floating point representations
From <x1,x2,. . ., xn>, xi[Li,Ui],
<x’1,x’2,. . ., x’n>, x’i[Li,Ui] is generated by substituting values
randomly
Uniform Mutation
All elements are substituted by a random value belonging to
the same interval.
Non-uniform Mutation with fixed distribution
Each element of the new vector is generated by adding a
random number from a distribution centered in zero and
decreasing with the absolute value (e.g., a Gaussian
distribution G(0,s) ).
Genetic operators: mutation
Mutation for permutations
Two random points are chosen and ….
Swap
123456789 153426789
Insertion
123456789 125346789
Shuffle
123456789 153246789
Inversion
123456789 154326789
Survivors’ selection (substitution)

Once the mating pool is selected and offspring is generated


by recombination, a number of individuals are temporarily
available which is higher than the (constant) population size.
If m is the population size and l the number of children, the m
individuals for the next generation are selected among the
m + l parents and offspring.
If l = m (the previous generation may be completely
substituted by their children) we call it a generational
algorithm, if l < m (some individual will survive across
generations) we call it a steady state algorithm.
Survivors’ selection (substitution)
Survivors’ selection strategies may be either based on fitness
or independent of it.

Age-based strategies
Independently of fitness, each individual survives for a pre-set
number of generations. Implementation is trivial if l = m (the
whole population at time t+1 is made up of offspring of
generation t).
If l < m fitness should be taken into account (with a random
substitution strategy the probability to lose the best
individual is very high).
Survivors’ selection (substitution)
Fitness-based strategies
The same strategies used to select the mating pool can be
adopted (fitness-proportionate, rank-based, tournament).
It is also possible to consider age, requiring, for instance
(if l < m ) that all offspring make up the next generation,
along with the best m - l parents.
The replace-worst strategy replaces the worst l
individuals.
Elitist strategies require that the best individual of
generation t be present in generation t+1.
Parameters of a genetic algorithm
Along with representation, operators and selection strategies,
the following parameters must be set:
• Population size
• Termination criterion, usually set alternatively as
- maximum number of iterations or
- fitness threshold (evolution ends when a sufficiently
good solution is found)
• Frequency with which genetic operators are applied:
- clonation (survival) probability
- crossover probability
- mutation probability
Genetic Programming
Genetic Programming
A variant of genetic algorithms: same algorithm applied to a
semantically different representation.
Functions are evolved, usually represented as syntactic trees

Functions (tree nodes)

Terminal symbols (tree leaves)


Genetic Programming

Tree nodes are functions


Tree leaves are terminal symbols (constants, pointers or data)
Operators usually satisfy the closure requirement, which
requires that the same data type (defined over the same
domain) be used for the inputs and outputs of all nodes. This
way, any permutation of nodes and terminal symbols
represents a valid tree.
A typed variant also exists. In this case a type check must be
performed when building a tree.
Genetic Programming

The function is evaluated (decoded) by traversing the


syntactic tree.
If a tree is traversed in pre-order, LISP-like code (prefix
notation) is obtained; if it is traversed symmetrically the
function is represented in algebraic notation (infix
notation)
Genetic Programming
Operators must be adapted to fit the representation

Mutation
Genetic Programming

Crossover (between two parents) extracts two sub-


trees, each chosen randomly from a different parent, and
swaps them (see figure on the left in the previous slide)
Mutation (applied to a single individual) substitutes a
sub-tree chosen randomly with a new random-
generated tree (see figure on the right in the previous
slide).
Genetic Programming

The properties of genetic operators are very different


from those of the corresponding operator applied to
strings
• The result of mutation may be a tree whose depth
is higher than the original depth
• The result of crossover can be a tree whose depth
is higher than both parents’ depth
Genetic Programming

Genetic Programming is a genetic algorithm, anyway and is


controlled by the same parameters.
However, Genetic Programming works at a higher level of
abstraction with respect to genetic algorithms:
• In GAs the representation has always symbols (bits, most
frequently) as atomic elements. It is only necessary to
define the semantics of representation
• In GP the atomic elements need to be defined as well, i.e.,
the sets of terminal symbols and functions that may be
used to build the trees
Genetic Programming

It is necessary to define:
• A function set F (tree nodes) for each of which arity
(number of arguments) must be specified
• A terminal symbol set T (tree leaves)
that meet the following requirements:
• All elements of T are correct expressions
• If fF is a function with arity n and (e1,…., en) are correct
expressions, then also f(e1,….,en) is correct
• There are no other possible correct expressions
These conditions are equivalent to the closure requirement.
Genetic Programming
The final problem to be solved is the definition of
constants
A possible solution (Ephemeral Random Constants)
consists of using a constant terminal symbol defined
within a certain interval;
- When a new tree is generated (initialization), i.e., the
first time an ERC is used, it is assigned a random value
within its domain.
- For every subsequent use, an ERC behaves as a
constant, keeping the same value at which it has been
initialized
Genetic Programming

T may contain an arbitrary number of ERCs, which may be


defined within different intervals.

It is also possible to define, within T, more than one constant


over the same interval, to bias the probability for such a
constant to be selected as a terminal when a tree is
initialized or mutation is applied.
Genetic Programming
Population initialization
The so-called ramped half-and-half initialization is
generally used
A maximum depth Dmax for the trees is set, then the
population is initialized using one of the following methods
with equal probability:
• Full method: each branch has depth Dmax; each element is
taken either from F, if depth D < Dmax, or from T otherwise.
• Grow method: trees can be unbalanced, so each element is
taken either from F U T, if D < Dmax, or from T otherwise.
Genetic Programming

Selection
The same strategies described for GAs may be used.
However, since large populations are usually generated, an
over-selection strategy is also used:
• Population is ordered by fitness and divided into two
groups, the former containing x% of the population,
the latter the remaining (100-x)%
• 80% of the individuals is selected from the first group,
the 20% from the second one.
Genetic Programming
Bloat
Since GP uses a variable-length representation, tree depth
tends to increase with time
This is called bloat or, as a joke, “survival of the fattest” (as
opposed to “survival of the fittest”).
Possible remedies:
• Operations which produce individuals with depth D >
Dmax are forbidden
• A term is added to the fitness function, which penalizes
the largest trees, e.g.,
F’ = F + 0.0001 * Size (parsimony pressure)

You might also like