Genetic Algorithm
Genetic Algorithm
Module -3
Soft computing (CSE-6004)
Lecture # 1
Index
• Lecture 1
– Brief about Genetic Algorithm
• Lecture 2
– GA Terminology
– GA Encoding Schemes
• Lecture 3
– Selection Techniques
• Lecture 4
– Crossover Techniques
• Lecture 5
– Bit Wise Operator
CSE-6004 2
What is GA
• A genetic algorithm (or GA) is a search technique
used in computing to find true or approximate
solutions to optimization and search problems.
• Genetic algorithms are categorized as global search
heuristics.
• Genetic algorithms are a particular class of
evolutionary algorithms that use techniques inspired
by evolutionary biology such as inheritance,
mutation, selection, and crossover (also called
recombination).
CSE-6004 Dr. Aprna Tripathi3
What is GA
• Genetic algorithms are implemented as a computer
simulation in which a population of abstract
representations (called chromosomes or the genotype
or the genome) of candidate solutions (called
individuals, creatures, or phenotypes) to an
optimization problem evolves toward better solutions.
Lecture # 2
Index
• Lecture 1
– Brief about Genetic Algorithm
• Lecture 2
– GA Terminology
– GA Encoding Schemes
• Lecture 3
– Selection Techniques
• Lecture 4
– Crossover Techniques
• Lecture 5
– Bit Wise Operator
CSE-6004 24
Search Space
• If we are solving some problem, we are usually looking
for some solution, which will be the best among others.
• The space of all feasible solutions (it means objects
among those the desired solution is) is called search
space (also state space).
• Each point in the search space represent one feasible
solution.
• Each feasible solution can be "marked" by its value or
fitness for the problem.
• We are looking for our solution, which is one point (or
more) among feasible solutions - that is one point in the
search space.
Lecture # 3
Index
• Lecture 1
– Brief about Genetic Algorithm
• Lecture 2
– GA Terminology
– GA Encoding Schemes
• Lecture 3
– Selection Techniques
• Lecture 4
– Crossover Techniques
• Lecture 5
– Bit Wise Operator
CSE-6004 50
GA Selection
Lecture # 4
Index
• Lecture 1
– Brief about Genetic Algorithm
• Lecture 2
– GA Terminology
– GA Encoding Schemes
• Lecture 3
– Selection Techniques
• Lecture 4
– Crossover Techniques
• Lecture 5
– Bit Wise Operator
CSE-6004 83
Crossover operation
• Once, a pool of mating pair are selected, they
undergo through crossover operations.
• In crossover, there is an exchange of properties
between two parents and as a result of which two
offspring solutions are produced.
• The crossover point(s) (also called k‐point(s))
is(are) decided using a random number
generator generating integer(s) in between 1 and
L, where L is the length of the chromosome.
• Then we perform exchange of gene values with
respect to the k‐point(s)
CSE-6004 Dr. Aprna Tripathi84
Crossover operations in Binary-coded
GAs
• There exists a large number of crossover
schemes, few important of them are listed in
the following.
– Single point crossover
– Two‐point crossover
– Multi‐point crossover (also called n‐point
crossover)
– Uniform crossover (UX)
– Matrix crossover (Tow‐dimensional crossover)
1 2 3 4 5 6 7
1 0 0 0 1 1 0
CSE-6004 102
Linear + end - inversion
• Linear + end inversion performs linear inversion
with a specified probability.
• If linear inversion is not performed, end inversion
would be performed with equal probability at
either the left or right end of the string.
• Under end inversion, the left or right end of the
string is picked as one inversion point and a
second inversion point is picked uniformly at
random from points no farther away than one-half
of the string length
CSE-6004 103
Continuous & Mass Inversion
• In continuous inversion mode, inversion is
applied with a specified inversion probability
to each new individual.
• In mass inversion mode, no inversion takes
place until a new population is created.
• One-half of the population undergoes identical
inversion using the same two point inversion.
CSE-6004 104
Deletion and duplication
• Duplication and deletion are low level
operators suggested for artificial search.
• Any two or three bits at random in order are
selected and the previous bits are duplicated.
0 0 1 1 0 0 1 0 1 0
0 0 1 1 0 - - - 1 0
0 0 1 1 0 1 1 0 1 0
CSE-6004 105
Duplication and Regeneration
• Genes between two cross sites are deleted and
regenerated randomly.
0 0 1 1 0 0 1 0 1 0
0 0 - - - - - - 1 0
0 0 1 1 0 1 1 0 1 0
CSE-6004 106
Segregation
• The bits of the parents are segregated and then
cross over to produce offspring.
CSE-6004 107
Crossover and Inversion
• Crossover and inversion operator is the
combination of both.
• In this two random sites are selected, the
content enclosed in boundary( included) is
exchanged between two parents and the end
points of these are exchanged.
CSE-6004 108
Crossover and Inversion- Example
CSE-6004 109
Mutation
• After crossover, the strings are subjected to
mutation.
• Mutation prevents the algorithm to be trapped
in a local minimum.
• Mutation plays the role of recovering the lost
genetic materials as well as for randomly
disturbing genetic information. Mutation of a
bit involves flipping a bit, changing 0 to 1 and
vice-versa.
CSE-6004 110
Flipping
• Flipping of a bit involves changing 0 to 1 and
1 to 0 based on a mutation chromosome
generated.
CSE-6004 111
Interchanging
• Two random positions of the string are chosen
and the bits corresponding to those positions
are interchanged
CSE-6004 112
Mutation Probability
• The important parameter in the mutation technique is the
mutation probability (Pm).
• The mutation probability decides how often parts of
chromosome will be mutated.
• If there is no mutation, offspring are generated immediately
after crossover (or directly copied) without any change.
• If mutation is performed, one or more parts of a
chromosome are changed.
• If mutation probability is 100%, whole chromosome is
changed, if it is 0%, nothing is changed.
• Mutation should not occur very often, because then GA will
in fact change to random search.
CSE-6004 113
Reversing
• A random position is chosen and the bits next
to that position are reversed and child
chromosome is produced.
CSE-6004 114
Replacement
• Replacement is the last stage of any breeding cycle.
• Two parents are drawn from a fixed size population,
they breed two children, but not all four can return to
the population, so two must be replaced i.e., once off
springs are produced,
• The technique used to decide which individual stay in a
population and which are replaced in on a par with the
selection in influencing convergence .
• Basically, there are two kinds of methods for
maintaining the population; generational updates and
steady state updates.
CSE-6004 115
• In a steady state update, new individuals are
inserted in the population as soon as they are
created, as opposed to the generational update
where an entire new generation is produced at
each time step.
• The insertion of a new individual usually
necessitates the replacement of another
population member.
CSE-6004 116
Random Replacement
CSE-6004 117
Weak Parent Replacement
CSE-6004 119
Index
• Lecture 1
– Brief about Genetic Algorithm
• Lecture 2
– GA Terminology
– GA Encoding Schemes
• Lecture 3
– Selection Techniques
• Lecture 4
– Crossover Techniques
• Lecture 5
– Bit Wise Operator
CSE-6004 120
Genetic Algorithm
Lecture # 5
One's Complement Operator
• This Operator is Known as unary operator(~).
• It causes the bits of its operand to be inverted.
CSE-6004 122
Logical bitwise operator
• This operator can further classified in to
– bitwise AND
– bitwise exclusive(X)-OR
– bitwise OR.
CSE-6004 123
Logical bitwise operator
CSE-6004 124
Shift Operator
• There are two types of Shift operator 2:
– Shift Left(<<) operator.
– Shift Right(>>) operator.
CSE-6004 125
Shift Operator
• Left Shift
• Right Shift
CSE-6004 126
Masking Operator
• Transform a given bit pattern in to another
form with the help of Logical bitwse operation.
There is a mask operand is used.
CSE-6004 127
Elitism
• The first best chromosome or the few best
chromosomes are copied to the new
population.
• The rest is done in a classical way. Such
individuals can be lost if they are not selected
to reproduce or if crossover or mutation
destroys them.
• This significantly improves the GA’s
performance.
CSE-6004 128
Effectiveness of any selection scheme
• There are two issues to decide the
effectiveness of any selection scheme.
– Population diversity
– Selection pressure
CSE-6004 129
Population Diversity
• This is similar to the concept of exploration.
• The population diversity means that the genes
from the already discovered good individuals
are exploited while permitting the new area of
search space continue to be explored.
CSE-6004 130
Selective Pressure
• This is similar to the concept of exploitation.
• It is defined as the degree to which the better
individuals are favored.
CSE-6004 131
If selection pressure is HIGH
1. The search focuses only on good individuals
(in terms of fitness) at the moment.
2. It loses the population diversity.
3. Higher rate of convergence. Often leads to
pre‐mature convergence of the solution to a
sub‐optimal solution.
CSE-6004 132
If the selection pressure is LOW
1. 1. May not be able to drive the search
properly and consequently the stagnation may
occurs.
2. The convergence rate is low and GA takes
unnecessary long time to find optimal
solution.
3. Accuracy of solution increases (as more
genes are usually explored in the search).
CSE-6004 133
Analysis of different selection
strategies
CSE-6004 134
Hamming cliff problem
• There is a issue with binary coding
• A one‐bit change can make a large (or a small)
jump.
• A multi‐bits can make a small (or a large gap).
• For example, 1000 ⇒ 0111
(Here, Hamming distance = 4, but distance
between phenotype is 1)
• Similarly, 0000 ⇒ 1000
(Here, Hamming distance = 1, but distance
between phenotype is 8)
CSE-6004 135
Convergence of GA
• The termination condition of a Genetic Algorithm is important in
determining when a GA run will end.
• It has been observed that initially, the GA progresses very fast with
better solutions coming in every few iterations, but this tends to
saturate in the later stages where the improvements are very small.
• We usually want a termination condition such that our solution is
close to the optimal, at the end of the run.
• Usually, we keep one of the following termination conditions −
– When there has been no improvement in the population for X
iterations.
– When we reach an absolute number of generations.
– When the objective function value has reached a certain pre-defined
value.
CSE-6004 136
GA Cycle
CSE-6004 137
Applications of Genetic Algorithms
• Traveling Salesman Problem
• Decoding A Secret Message
• Robot Trajectory Planning
• Optimizing Artificial Neural Nets
CSE-6004 138
Domain-wise GA Applications
CSE-6004 139
Issues for Genetic Algorithm
• Choosing basic implementation issues such as
– Representation
– Population size and mutation rate
– Selection, deletion policies
– Cross over and mutation operators
• Termination criterion
• Performance and scalability
• Solution is only as good as evaluation
functions.
CSE-6004 140
Advantages of GAs
• GAs have various advantages which have made them
immensely popular. These include −
– Does not require any derivative information (which may not be
available for many real-world problems).
– Is faster and more efficient as compared to the traditional
methods.
– Has very good parallel capabilities.
– Optimizes both continuous and discrete functions and also multi-
objective problems.
– Provides a list of “good” solutions and not just a single solution.
– Always gets an answer to the problem, which gets better over the
time.
– Useful when the search space is very large and there are a large
number of parameters involved.
CSE-6004 141
Benefits of Genetic Algorithms
• Easy to understand
• Supports multi-objective optimization
• Good for noisy environment
• We always get answer and answer gets better with
time
• Inherently parallel and easily distributed
• Easy to exploit for precious or alternate solutions
• Flexible in forming building blocks for hybrid
applications
• Has substantial history and range of use
CSE-6004 142
Limitations of GA
• Like any technique, GAs also suffer from a few
limitations. These include −
– GAs are not suited for all problems, especially
problems which are simple and for which derivative
information is available.
– Fitness value is calculated repeatedly which might be
computationally expensive for some problems.
– Being stochastic, there are no guarantees on the
optimality or the quality of the solution.
– If not implemented properly, the GA may not converge
to the optimal solution.
CSE-6004 143
References
• https://www.tutorialspoint.com/genetic_algorit
hms
• http://shodhganga.inflibnet.ac.in
• http://www.nid.iitkgp.ernet.in/DSamanta
• http://www.ics.uci.edu/~kibler/ics171/RNLect
ures/GAs.pdf
CSE-6004 144