0% found this document useful (0 votes)
60 views

Genetic Algorithms: by Volkan TUNALI

Genetic algorithms are a type of evolutionary algorithm inspired by biological evolution. They work by generating an initial population of random solutions, then using selection, crossover, and mutation to iteratively improve the population. Genetic algorithms have been successfully applied to optimization problems like university timetabling and modeling problems like predicting loan applicant creditworthiness. They represent solutions as chromosomes that can undergo variation and selection to evolve toward better solutions.

Uploaded by

meryemoy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Genetic Algorithms: by Volkan TUNALI

Genetic algorithms are a type of evolutionary algorithm inspired by biological evolution. They work by generating an initial population of random solutions, then using selection, crossover, and mutation to iteratively improve the population. Genetic algorithms have been successfully applied to optimization problems like university timetabling and modeling problems like predicting loan applicant creditworthiness. They represent solutions as chromosomes that can undergo variation and selection to evolve toward better solutions.

Uploaded by

meryemoy
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 53

GENETIC ALGORITHMS

by

Volkan TUNALI
Content
 Evolutionary Computation (EC)
 Positioning of EC
 Some terminology
 Problem types
 Evolutionary Algorithms (EA)
 Genetic Algorithms (GA)
 Original GA by Holland
 Example
 Sample Application – Travelling Salesman
Positioning of EC
 EC is part of computer science

 EC is not part of life sciences/biology

 Biology delivered inspiration and


terminology

 EC can be applied in biological research


Main EC Metaphor
EVOLUTION PROBLEM SOLVING

Environment Problem
Individual Candidate Solution
Fitness Quality

 Fitness  chance for survival and reproduction


 Quality  chance for seeding new solutions
Darwinian Evolution 1:
Survival of the Fittest
 All environments have finite resources
 (i.e., can only support a limited number of
individuals)

 Some kind of selection is inevitable

 Those individuals that compete for the


resources most effectively have
increased the chance of reproduction
Darwinian Evolution 2:
Diversity Drives Change
 Phenotypic traits
 Behaviour / physical differences that affect response to
environment
 Partly by inheritance, partly by factors during development
 Unique to each individual, partly result of random changes

 If phenotypic traits:
 Lead to higher chances of reproduction
 Can be inherited

Then they will tend to increase in subsequent generations

 leading to new combinations of traits..


Biological Terminology [1]
 Population: a group of individuals that may interact
with each other and occupy a given area at the same
time
 Adaptation: the evolution of features that make a
group of organisms better suited to live and reproduce
in their environment
 Fitness: the relative ability to leave offspring and
survive
 Natural Selection: a process of interaction between
organisms and their environment that results in a
differential rate of reproduction of different phenotypes
in a population (survival of the fittest)
 Inheritance: propagation of genetic material from
parent to offspring
Biological Terminology [2]
 Chromose: one of the bodies in the cell nucleus, along
which the genes are located (“blueprint” for the
organism)
 Gene: a functional block of DNA which encodes a
particular protein
 Genotype: the genetic constitution of a cell or and
organism
 Phenotype: observable properties of an organism
 Mutation: the inheritable change of a gene from one
allelic form to another
 Recombination: the formation of gene combinations
through mixing that differ from the combinations present
in the parents
 Crossing over: exchange of genetic material between
paired chromosomes
EAs  Real World Terminology
 Individual: one point in the search space of all
possible solutions
 Population: whole of the solution points currently
under consideration
 Gene: an encoding of a parameter or a part of a
solution
 Chromosome: an encoding of all the parameters
or the whole current solution candidate
 Crossing over: a recombinations operator used
during reproduction phase
 Mutation: abrupt change in gene value
EAs  Real World Terminology
 Phenotype: objects forming the possible
solutions within the original problem context
 Genotype: encoding of the phenotype that is
an individual within the EA
 Ex: Given an optimization problem on integers
 Given set of integers form the set of phenotypes
 18 is a phenotype & 10010 is a genotype
representing it.
 Fitness: how much the current solution meets
the requirements of the objective function
 Generation: one loop of the genetic algorithm
Problem Type 1: Optimization
 We have a model of our system and seek inputs
that give us a specified goal
 e.g. time tables for university, call center, or
hospital
Optimisation Example:
University Timetabling
 Enormously big search space

 Timetables must be good

 “Good” is defined by a number of competing


criteria

 Timetables must be feasible

 Vast majority of search space is infeasible


Problem Type 2: Modelling
 We have corresponding sets of inputs &
outputs and seek model that delivers correct
output for every known input
Modelling Example:
Loan Applicant Creditibility
 British bank evolved creditability
model to predict loan paying behavior
of new applicants

 Evolving: prediction models

 Fitness: model accuracy on historical


data
Problem Type 3: Simulation
 We have a given model and wish to know the outputs
that arise under different input conditions

 Often used to answer “what-if” questions in evolving dynamic environments


 e.g. Evolutionary economics, Artificial Life
What is an Evolutionary Algorithm?
 EAs fall into the category of “generate
and test” algorithms
 They are stochastic, population-based
algorithms
 Variation operators (recombination and
mutation) create the necessary diversity
and thereby facilitate novelty
 Selection reduces diversity and acts as a
force pushing quality
General Scheme of EAs
Pseudo-code for Typical EA
What are the Different Types of EAs
 Historically different flavours of EAs have been
associated with different representations
 Binary strings : Genetic Algorithms
 Real-valued vectors : Evolution Strategies
 Finite state Machines: Evolutionary Programming
 LISP trees: Genetic Programming
 These differences are largely irrelevant, best
strategy
 choose representation to suit problem
 choose variation operators to suit representation
 Selection operators only use fitness and so are
independent of representation
Representations
 Candidate solutions (individuals) exist in phenotype space
 They are encoded in chromosomes, which exist in genotype space
 Encoding : phenotype=> genotype (not necessarily one to one)
 Decoding : genotype=> phenotype (must be one to one)
 Chromosomes contain genes, which are in (usually fixed)
positions called loci (sing. locus) and have a value (allele)

In order to find the global optimum, every feasible solution


must be represented in genotype space
Evaluation (Fitness) Function
 Represents the requirements that the population
should adapt to
 a.k.a. quality function or objective function
 Assigns a single real-valued fitness to each
phenotype which forms the basis for selection
 So the more discrimination (different values) the

better
 Typically we talk about fitness being maximised
 Some problems may be best posed as

minimisation problems, but conversion is trivial


Population
 Holds (representations of) possible solutions
 Usually has a fixed size and is a multiset of
genotypes
 Some sophisticated EAs also assert a spatial
structure on the population (e.g. distance
measure or a neighborhood relation)
 Selection operators usually take whole
population into account i.e., reproductive
probabilities are relative to current generation
 Diversity of a population refers to the number of
different fitnesses / phenotypes / genotypes
present (**note not the same thing)
Parent Selection Mechanism
 Assigns variable probabilities of individuals acting as
parents depending on their fitnesses
 Usually probabilistic
 high quality solutions more likely to become

parents than low quality


 but not guaranteed

 even worst in current population usually has non-

zero probability of becoming a parent


 This stochastic nature can aid escape from local
optima
Variation Operators
 Role is to generate new candidate solutions
 Usually divided into two types according to
their arity (number of inputs):
 Arity 1 : mutation operators
 Arity >1 : Recombination operators
 Arity = 2 typically called crossover
 There has been much debate about relative
importance of recombination and mutation
 Nowadays most EAs use both
 Choice of particular variation operators is
representation dependant
Mutation
 Acts on one genotype and delivers
another
 Element of randomness is essential and
differentiates it from other unary
heuristic operators
 Importance depends on representation
and dialect
 May guarantee connectedness of search
space
Recombination
 Merges information from parents into
offspring
 Choice of what information to merge is
stochastic
 Most offspring may be worse, or the same
as the parents
 Hope is that some are better by
combining elements of genotypes that
lead to good traits
Survivor Selection
 a.k.a. replacement
 Most EAs use fixed population size so
need a way of going from (parents +
offspring) to next generation
 Often deterministic
 Fitness based : e.g., rank

parents+offspring and take best


 Age based: make as many offspring

as parents and delete all parents


 Sometimes do combination (elitism)
Initialisation / Termination
 Initialisation usually done at random,
 Need to ensure even spread and mixture of possible allele values
 Can include existing solutions, or use problem-specific heuristics,
to “seed” the population

 Termination condition checked every generation


 Reaching some (known/hoped for) fitness
 Reaching some maximum allowed number of generations
 Reaching some minimum level of diversity
 Reaching some specified number of generations without fitness
improvement
Example: 8 Queens Problem

Place 8 queens on an 8x8 chessboard in


such a way that they cannot check each other
8 Queens Problem: Representation

Phenotype:
a board configuration

Genotype: Obvious mapping


a permutation of
the numbers 1 - 8 1 3 5 2 6 4 7 8
8 Queens Problem: Fitness
Evaluation
 Quality q(p) of any phenotype p
 the number of queens she can check

 q(p) = 0 indicates a good solution


 Objective function to be minimized

 Fitness of a configuration:
 inverse of q(p) (= 1 / q(p))
 M - q(p) where M is sufficiently large number
8 Queens Problem: Mutation
Small variation in one permutation, e.g.:
swapping values of two randomly chosen positions,

1 3 5 2 6 4 7 8 1 3 7 2 6 4 5 8
8 Queens Problem: Recombination
Combining two permutations into two new permutations:
 choose random crossover point
 copy first parts into children
 create second part by inserting values from other
parent:
 in the order they appear there
 beginning after crossover point
 skipping values already in child

1 3 5 2 6 4 7 8 1 3 5 4 2 8 7 6
8 7 6 5 4 3 2 1 8 7 6 2 4 1 3 5
8 Queens Problem: Selection

 Parent selection:
 Pick 5 parents and take best two to
undergo crossover
 Survivor selection (replacement)
 Merge the population and offspring
 Rank them according to fitness
 Delete the worst two
8 Queens Problem: Summary

Note that is only one possible


set of choices of operators and parameters
Typical Behaviour of an EA

Phases in optimising on a 1-dimensional fitness landscape

Early phase:
quasi-random population distribution

Mid-phase:
population arranged around/on hills

Late phase:
population concentrated on high hills
Typical Run: Progression of Fitness
Best fitness in population

Time (number of generations)

Typical run of an EA shows so-called “anytime behavior”


Are Long Runs Beneficial?
Best fitness in population

Progress in 2nd half

Progress in 1st half

Time (number of generations)


• Answer:
- it depends how much you want the last bit of progress
- it may be better to do more shorter runs
Is It Worth Expending Effort on
Smart Initialisation?
Best fitness in population

F F: fitness after smart initialisation

T: time needed to reach level F after random initialisation

T
Time (number of generations)
• Answer : it depends:
- possibly, if good solutions/methods exist
Genetic Algorithms
 Developed: USA in the 1970’s
 Early names: J. Holland, K. DeJong, D. Goldberg
 Typically applied to:
 discrete optimization
 Attributed features:
 not too fast
 good heuristic for combinatorial problems
 Special Features:
 Traditionally emphasizes combining information from
good parents (crossover)
 many variants, e.g., reproduction models, operators
Genetic Algorithms
 Holland’s original GA is now known as the
simple genetic algorithm (SGA)
 Other GAs use different:
 Representations
 Mutations
 Crossovers
 Selection mechanisms
SGA Technical Summary
Representation Binary strings
Recombination N-point or uniform
Mutation Bitwise bit-flipping
with fixed probability

Parent selection Fitness-Proportionate

Survivor selection All children replace


parents
Speciality Emphasis on
Representation

Phenotype space Genotype space =


Encoding {0,1}L
(representation) 10010001
10010010
010001001
011101001
Decoding
(inverse representation)
SGA Reproduction Cycle

1. Select parents for the mating pool


(size of mating pool = population size)
2. Shuffle the mating pool
3. For each consecutive pair apply crossover with
probability pc , otherwise copy parents
4. For each offspring apply mutation (bit-flip with
probability pm independently for each bit)
5. Replace the whole population with the resulting
offspring
SGA Operators: 1-point Crossover
 Choose a random point on the two parents
 Split parents at this crossover point
 Create children by exchanging tails
 Pc typically in range (0.6, 0.9)
SGA Operators: Mutation
 Alter each gene independently with a probability pm
 pm is called the mutation rate
 Typically between 1/pop_size and 1/ chromosome_length
SGA Operators: Selection
 Main idea: better individuals get higher chance
 Chances proportional to fitness
 Implementation: roulette wheel technique
 Assign to each individual a part of the roulette wheel
 Spin the wheel n times to select n individuals

1/6 = 17%

A B fitness(A) = 3
C fitness(B) = 1
3/6 = 50% 2/6 = 33%
fitness(C) = 2
An Example After Goldberg ‘89
 Simple problem: max x2 over {0,1,…,31}
 GA approach:
 Representation: binary code, e.g. 01101 ↔ 13
 Population size: 4
 1-point xover, bitwise mutation
 Roulette wheel selection
 Random initialisation
 We show one generational cycle done by hand
x2 Example: Selection
x2 Example: Crossover
x2 Example: Mutation
The Simple GA
 Has been subject of many (early) studies
 Still often used as benchmark for novel GAs
 Shows many shortcomings, e.g.
 Representation is too restrictive
 Mutation & crossovers only applicable for bit-
string & integer representations
 Selection mechanism sensitive for converging
populations with close fitness values
 Generational population model (step 5 in SGA
repr. cycle) can be improved with explicit
survivor selection
Conclusion with a Sample
Application
 Travelling Salesman Problem
 visit a number of cities once
 minimize the overall distance travelled
 As the number of cities grow, the time
required to find the solution grows
exponentially = O(2n)
 See the demonstration...

You might also like