You are on page 1of 11

[GENETIC ALGORITHM] Unit 4

Introduction :
Genetic algorithm is a search based optimization technique based on the
principles of genetics and natural selection. GA was developed by Mr. John
Holland. GA are a subset of evolutionary computation. In GA, we have a
population of possible solutions of a given problem. Our job is to choose the
fittest solution from it. These solution then undergo recombination and mutation
producing new children. This process is repeated over various generations. In this
way, we keep evolving better solutions over next generations, till we reach a
stopping criteria.

Basic terminologies of Genetic Algorithm :


 Population: Population is the subset of all possible or probable
solutions, which can solve the given problem.
 Chromosomes: A chromosome is one of the solutions in the
population for the given problem, and the collection of gene
generate a chromosome.
 Gene: A chromosome is divided into a different gene, or it is an
element of the chromosome.
 Allele: Allele is the value provided to the gene within a particular
chromosome.
 Fitness Function: The fitness function is used to determine the
individual's fitness level in the population. It means the ability of an
individual to compete with other individuals. In every iteration,
individuals are evaluated based on their fitness function.
 Genetic Operators: In a genetic algorithm, the best individual mate
to regenerate offspring better than parents. Here genetic operators
play a role in changing the genetic composition of the next
generation.
 Selection: After calculating the fitness of every existent in the
population, a selection process is used to determine which of the
individualities in the population will get to reproduce and produce
the seed that will form the coming generation.

CST, 6TH SEM Page 1


[GENETIC ALGORITHM] Unit 4

Genetic Operators :
A genetic operator is an operator used in genetic algorithms to guide the
algorithm towards a solution for a given problem. There are three main types
of operators mutation, crossover and selection.

 Selection: Selection operators give preference to better solutions


(chromosomes), allowing them to pass on their genes to the next
generation of the algorithm. The best solutions are determined using
some form of objective function also known as a fitness function in
genetic algorithms, before being passed to the crossover operator.

 Crossover: Crossover is the process of taking more than one parent


solutions (chromosomes) and producing a child solution from them. By
recombining portions of good solutions, the genetic algorithm is more
likely to create a better solution. As with selection, there are a number
of different methods for combining the parent solutions, including ‘one-
point crossover’ and 'uniform crossover' methods etc.. The crossover
method is often chosen to closely match the chromosome's
representation of the solution.
 Mutation:The mutation operator encourages genetic diversity amongst
solutions and attempts to prevent the genetic algorithm converging to
a local minimum by stopping the solutions becoming too close to one
another. In mutating the current set of solutions, a given solution may
change entirely from the previous solution. By mutating the solutions, a
genetic algorithm can reach an improved solution solely through the
mutation operator.

CST, 6TH SEM Page 2


[GENETIC ALGORITHM] Unit 4

Steps of Genetic Algorithm :


I. Initial population: The process starts with a set of solutions called
population. An individual solution is represented by a set of
variables called genes. Genes are joins together to make a string of
bits called Chromosome.

1.1 Four solutions of a population.


II. Fitness function: The fitness function determines fitness of an
individual solution(Bit String).The fitness refers to the ability of an
individual solution to compete with other individuals. The
probability of an individual solution will be selected for
reproduction is based on its fitness score.
III. Selection of individual solution: Two pairs of individual solutions
are selected based on their fitness scores. The individuals with high
fitness value have more chances to be selected for reproduction
IV. Crossover: For each pair of parents to be mated, a crossover point
is selected at random. The new solutions after crossover is called
offspring.
V. Mutation: Some bits are flipped (i.e., 0 to 1 and 1 to 0) to maintain
diversity in the new offspring population.

CST, 6TH SEM Page 3


[GENETIC ALGORITHM] Unit 4

Flowchart of genetic algorithm:

Start

Initial population of solution

Selection

Crossover

Mutation

Terminate
? No
Yes
Best individual solution

Optimized solution as output

Stop

Types of Crossover in GA:


i. 1 – point crossover: A crossover points on parents strings is selected. All data
bits after this crossover point is swapped between two parent strings.

1 1 0 1 0 1 0 0 0
Parents
0 1 0 0 1 0 1 1 1

1 1 0 1 1 0 1 1 1
Children(offspring)
0 1 0 0 0 1 0 0 0

CST, 6TH SEM Page 4


[GENETIC ALGORITHM] Unit 4

ii. 2 – point and K-point crossover: In two-point crossover, two points are
selected randomly from the parent chromosomes. The bits in between the two
points are swapped between the parent chromosome.

1 1 1 1 1 1 1 1
parents
0 0 0 0 0 0 0 0

1 1 0 0 0 0 1 1
Children
0 0 1 1 1 1 0 0

iii. Uniform crossover: In uniform crossover, the bits are chosen


randomly from both parents with equal probability.
0 0 0 0 0 0 0 0
parents
1 1 1 1 1 1 1 1

1 0 0 0 1 1 0 1
children
0 1 1 1 0 0 1 0

Types of mutation operator:


1) Bit Flip mutation: In this method, we select one or more random bits and
flip them.
0 0 1 1 0 1 0 1
Bit flipped
0 0 1 0 0 1 0 1
2) Random setting : Random setting is extension of bit flip method, for
integer representation.

1 2 3 4 5 6 7

1 2 3 4 8 6 7

CST, 6TH SEM Page 5


[GENETIC ALGORITHM] Unit 4

3) Swap mutation: In swap mutation, we select two positions on the


chromosome at random. Then we interchange the values.

1 2 3 4 5 6 7 8

1 6 9 4 5 2 7 8

Here position 2 and 6 are swapped.

4) Scramble mutation: In this method, a subset of genes is chosen and their


values are shuffled randomly.
1 2 3 4 5 6 7

1 2 5 3 4 6 7
5) Inversion mutation: In this method, a subset of genes is chosen and their
values are inverted as a string.
1 2 3 4 5 6 7 8

1 2 5 4 3 6 7 8

Hypothesis space search:


In the hypothesis space search method, we can see that the gradient
descent search moves smoothly from one hypothesis to another. On the
other hand, the genetic algorithm search can move much more abruptly.
It replaces the parent hypotheses with an offspring that can be very
different from the parent. Due to this reason, genetic algorithm search
has lower chances of it falling into the same kind of local minima that
plaques the gradient descent methods.

CST, 6TH SEM Page 6


[GENETIC ALGORITHM] Unit 4

There is one practical difficulty that is often encountered in genetic


algorithms, it is crowding. Crowding can be defined as the phenomenon in
which some individuals that are more fit in comparison to others,
reproduce quickly, therefore the copies of this individual take over a
larger fraction of the population. Most of the strategies used in the
genetic algorithms are inspired by biological evolution. One such other
strategy used is fitness sharing, in which the measured fitness of an
individual is decreased by the presence of another individual of a similar
kind. The third method is to restrict all the individuals to combine to form
offspring.

Genetic Programming
In genetic programming, Programs or problems are expressed as tree rather
than as lines of code. For example, the simple expression
max(x ∗ x, x + 3 ∗ y)
In genetic algorithm it can be expressed as following figure,

Steps of Genetic Programming:


Genetic programming starts from a high-level statement of the
requirements of a problem and attempts to produce a computer program
that solves the problem .The human user communicates the high-level
statement of the problem to the genetic programming algorithm by
performing certain well defined preparatory steps.

The five major preparatory steps for the basic version of genetic
programming require the human user to specify:

CST, 6TH SEM Page 7


[GENETIC ALGORITHM] Unit 4

step1: the set of terminals (e.g., the independent variables of the problem,
zero-argument functions, and random constants) for each branch
of the to-be-evolved program.
step2: the set of primitive functions for each branch of the to-be-evolved
program.
step3: Measure fitness (for explicitly or implicitly measuring the fitness
of individuals in the population).
step4: certain parameters for controlling the run.
step5: the termination criterion and method for designating the result of
the run.

Advantages of GA are following,


 It has wide solution space.
 It is easier to discover global optimum.
 Multiple GA can run together in same CPU.

Disadvantages of GA are following,


 The fitness function calculation is a limitation.
 Convergence of GA can be too fast or too slow.
 Limit of selecting parameters.

Application of genetic algorithm:


 Optimization: genetic algorithm are most commonly used optimization
problems. In an optimization problem, we have maximize a given
objective function under a set of constraints.
 Artificial Neural Network in machine learning: Genetic algorithm are
used to train the ANN in machine learning.
CST, 6TH SEM Page 8
[GENETIC ALGORITHM] Unit 4

 Image processing in deep learning: The genetic algorithm are used for
various digital image processing tasks like dense pixel matching.
 Engineering design: The genetic algorithm are used in computer
modelling and simulation to make design cycle fast and economical.
 Robot trajectory generation: Gas are used to decide the path of robotic
arm to move from one place to other place.
 DNA analysis: Gas are used for determining the DNA structure using
spectrometer data and evolving better solutions.

CST, 6TH SEM Page 9


[GENETIC ALGORITHM] Unit 4

Previous year question:


1. Explain Fitness function, selection and crossover.
 Fitness function: The fitness function determines fitness of an
individual solution (Bit String).The fitness refers to the ability of
an individual solution to compete with other individuals. The
probability of an individual solution will be selected for
reproduction is based on its fitness score.

 Selection: Two pairs of individual solutions are selected based


on their fitness scores. The individuals with high fitness value
have more chances to be selected for reproduction. Selection
give preference to better solutions (chromosomes), allowing
them to pass on their genes to the next generation of the
algorithm. The best solutions are determined using some form
of objective function also known as a fitness function in genetic
algorithms, before being passed to the crossover operator.

 Crossover: For each pair of parents to be mated, a crossover


point is selected at random. The new solutions after crossover
is called offspring. Crossover is the process of taking more than
one parent solutions (chromosomes) and producing a child
solution from them. By recombining portions of good
solutions, the genetic algorithm is more likely to create a
better solution. As with selection, there are a number of
different methods for combining the parent solutions,
including ‘one-point crossover’ and 'uniform crossover'
methods etc.. The crossover method is often chosen to closely
match the chromosome's representation of the solution.

CST, 6TH SEM Page 10


[GENETIC ALGORITHM] Unit 4

Questions:
1. Write down the steps of genetic algorithm.
2. Discuss different types of crossover and mutation operator.
3. Advantage, disadvantage and application of genetic algorithm.
4. Explain genetic programming with example..

CST, 6TH SEM Page 11

You might also like