0% found this document useful (0 votes)
13 views26 pages

GA Lec5 Operators Selection Replacement

Uploaded by

20208046
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views26 pages

GA Lec5 Operators Selection Replacement

Uploaded by

20208046
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Genetic Algorithms

Various Operators

Sabah Sayed
Department of Computer Science
Faculty of Computers and Artificial Intelligence
Cairo University
Egypt

3/8/2024 1
Remember: Mechanism Of GAs
Begin

Initialize population

T =0

Evaluate Solutions

Optimum N
Solution?
Selection
Y

T=T+1 Stop Crossover

Mutation

Replacement

2
Various Strategies for the Genetic Operators

• Different GAs use different ……… strategies.


– Representation (encoding/decoding)
– Crossover
– Mutation
– Selection
– Replacement
Various Representations
Character Array?
String Array?
Floating Point?
Integer?
Permutation?

Phenotype space Genotype space =


Encoding {0,1}L
(representation) 10010001
10010010
010001001
011101001
Decoding
(inverse representation)
3/8/2024 4
English Word Generation Example
Objective fn
Problem: Generate valid English word of
length 5 characters
Crossover

t t w w Dictionary
h h o o
r f r f
e s e s
s . . . e . . s . . . . e
Chr 1 Chr N
English Word Generation Example
Problem: Generate valid English word of Objective fn

length 5 characters
Mutation

t t w w Dictionary
h h o o
r e r f
e s d s
s . . . e . . s . . . . e
Chr 1 Chr N
Integer Representation
• Some problems naturally have integer variables,
e.g. image processing parameters

• Others take categorical values from a fixed set e.g.


{blue, green, yellow, pink}

• N-point / uniform crossover operators work

• Extend bit-flipping mutation to make


• Random choice (categorical variables)

3/8/2024 7
Uniform Crossover for Integers
• Assign 'heads' to one parent, 'tails' to the other
• Flip a coin for each gene of the first child
• Make an inverse copy of the gene for the second
child

• Example:

Suppose H for Parent1 and T for Parent 2


H H T H T H
Parent 1 3 5 9 12 18 1 3 5 1
8 112 0 151 1 Offspring 1

Parent 2 4 6 8 10 15 7 9 010 1 180 7


4 6 0 Offspring 2

8
Uniform Crossover for Integers
• Inheritance is independent of position
• Applicable for binary representation
• How to implement it (programming)
• N-point crossover ???

3/8/2024 9
Permutation Representations
• Ordering/sequencing problems form a special type
• Task is (or can be solved by) arranging some objects
in a certain order
– Example: sort algorithm: important thing is which
elements occur before others (order)
– Example: Travelling Salesman Problem (TSP) : important
thing is which elements occur next to each other
(adjacency)
• These problems are generally expressed as a
permutation:
– if there are n variables then the representation is as a list
of n integers, each of which occurs exactly once

3/8/2024 10
Crossover for Permutations
• Normal crossover operators will often lead to
inadmissible solutions

12345 12321
54321 54345

• Many specialised operators have been devised


which focus on combining order or adjacency
information from the two parents

3/8/2024 11
Mutation operators for permutations

• Normal mutation operators lead to inadmissible


solutions
– e.g. bit-wise mutation : let gene i have value j
– changing to some other value k would mean that k
occurred twice and j no longer occurred
• Therefore must change at least two values
• Mutation parameter now reflects the probability
that some operator is applied once to the whole
string, rather than individually in each position

3/8/2024 12
Insert Mutation for permutations
• Pick two allele (gene) values at random
• Move the second to follow the first, shifting
the rest along to accommodate
• Note that this preserves most of the order and
the adjacency information

3/8/2024 13
Swap mutation for permutations
• Pick two alleles (genes) at random and swap
their positions
• Preserves most of adjacency information (4
links broken)
• disrupts order more

3/8/2024 14
Inversion mutation for permutations
• Pick two alleles at random and then invert the
substring between them.
• Preserves most adjacency information (only
breaks two links) but disruptive of order
information

3/8/2024
Floating-point (real values) Representation
• Many problems occur as real valued problems, e.g.
continuous parameter optimization f :  n → 

• The chromosome will be an array of floating point variables

• This can serve in optimization of a multi-variate function


y=f(x1, x2, … xm)

• Crossover is the same as in bit-string chromosomes.


• Mutation is different

3/8/2024 16
Crossover over FP Chromosomes

x1 x2 x3 ... xm-1 xm x'1 x'2 x'3 ... x'm-1 x'm

x1 x2 x'3 ... x'm-1 x'm x'1 x'2 x3 ... xm-1 xm

3/8/2024 17
Mutation over FP Chromosomes
• General scheme of floating point mutations
x = x1 , ..., xl → x  = x1, ..., xl
xi , xi  LBi ,UBi 

• Two kinds of FP mutations:


– Uniform
– Non-uniform

3/8/2024 18
Uniform FP Mutation
xi drawn randomly (uniform) from LBi ,UBi 

x1 x2 … xi … xm-1 xm

Given the above chromosome X in a particular generation G:


• Each gene (variable) has a range
• Gene xi is a FP value inside chromosome X at generation G
• To mutate gene xi LB UBi
i
1. Generate random number ri1 ϵ [0, 1] xi
• ∆ = ∆L if ri1 ≤ 0.5
• ∆ = ∆U if ri1 > 0.5
• This means equal chance to go left or right ∆L ∆U
2. Generate random number ri2 ϵ [0, ∆]
• if ∆ = ∆L then xi-new = xi - ri2 ∆L = xi - LBi
• if ∆ = ∆U then xi-new = xi + ri2
∆U = UBi - xi
3/8/2024 19
Non-uniform FP Mutation
Some methods proposed such as time-varying range of change

x1 x2 … xi … xm-1 xm

Given the above chromosome X in a particular generation G:


• Each gene (variable) has a range
• Gene xi is a FP value inside chromosome X at generation G
• To mutate gene xi
1. Generate random number ri1 ϵ [0, 1]
• y = ∆L if ri1 ≤ 0.5 LBi UBi
• y = ∆U if ri1 > 0.5
xi
2. Let ∆(t,y)
= value of mutation at generation t
= y(1-r(1-t/T)^b) ∆L ∆U
where:
• r = random number ϵ [0, 1]
• t = current generation ∆L = xi - LBi
• T = maximum number of generations
• b = dependency factor ≈ 1…5 ∆U = UBi - xi
3/8/2024 20
Non-uniform FP Mutation
• Analysis of Equation:
∆(t,y) = value of mutation at generation t
= y(1-r(1-t/T)^b)
where:
– r = random number ϵ [0, 1]
– t = current generation
– T = maximum number of
generations
– b = dependency factor ≈ 1…5
(Controls the curve of mutation)

– At t=0:
∆(t,y) = Maximum value of mutation
– At t=T:
∆(t,y) = 0 (No mutation)

3/8/2024 21
Crossover or Mutation?
• Decades of long debate: which one is better or
necessary?

• Answer (at least, rather wide agreement):


– it depends on the problem, but
– in general, it is good to have both
– both have different roles
– mutation-only-GA is possible, crossover-only-GA would not
work. Why??
Mutation
• Causes movement in the search space
(local or global)
• Restores lost information to the population
• Mutation is necessary because some
important genes might be missing from all the
initial population.

3/8/2024
Crossover
• It greatly accelerates search early in evolution
of a population
• It leads to effective combination of schemata
(subsolutions on different chromosomes)

3/8/2024
Crossover or Mutation?
✓ Exploration: Discovering promising areas in the search space,
i.e. gaining information on the problem
✓ Exploitation: Optimising within a promising area, i.e. using
information
There is co-operation AND competition between them
• Crossover is explorative: it makes a big jump to an area
somewhere “in between” two (parent) areas
• Mutation is exploitative: it creates random small diversions,
thereby staying near (in the area of ) the parent
Crossover OR mutation?
• Only crossover can combine information from two parents
• Only mutation can introduce new information (alleles)
• Crossover does not change the allele frequencies of the
population (thought experiment: 50% 0’s on first bit in the
population, ?% after performing n crossovers)
• To hit the optimum you often need a ‘lucky’ mutation

You might also like