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

Lecture Notes (2)

The document provides an overview of Genetic Algorithms (GA), a subset of evolutionary algorithms inspired by biological processes for optimizing complex functions. It details the working principles of GA, including population initialization, fitness calculation, selection, crossover, and mutation, along with various encoding techniques and genetic operators. Additionally, it discusses parent selection methods and convergence criteria essential for the effective implementation of Genetic Algorithms.

Uploaded by

ashiyadav1040
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)
2 views

Lecture Notes (2)

The document provides an overview of Genetic Algorithms (GA), a subset of evolutionary algorithms inspired by biological processes for optimizing complex functions. It details the working principles of GA, including population initialization, fitness calculation, selection, crossover, and mutation, along with various encoding techniques and genetic operators. Additionally, it discusses parent selection methods and convergence criteria essential for the effective implementation of Genetic Algorithms.

Uploaded by

ashiyadav1040
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/ 78

Program: B.

Tech Semester 6th, Third Year


Soft Computing
Unit 5
Genetic Algorithm

Ms. Vanshita Gupta


Assistant Professor
CSA Department, SOET
Evolutionary Algorithms

•Evolutionary algorithms are those algorithms which follow


some biological and physical behaviours.

Biological behaviour:
•Genetics & Evolution → Genetic Algorithm (GA)
•Human Nervous System → Artificial Neural Network (ANN)
•Behaviour of ant colony → Ant Colony Optimization (ACO)

Physical behaviour:
•Learning → Fuzzy Logic (FL)
•Swarming of particles → Particle Swarming Optimization (PSO)
Genetic Algorithm

It is a subset of evolutionary algorithms that models biological


processes (Genetics & Evolution) to optimize highly complex
functions (very difficult to model mathematically or NP-hard
problems), which are computationally very expensive to solve
or involve a large number of parameters.
Genetic Algorithm

A Genetic Algorithm (GA) is an optimization technique inspired


by the process of natural selection (Darwin’s theory of
evolution). It is used to solve complex problems where finding
an exact solution is difficult.
Or
GA is a method that mimics the way living organisms evolve
over generations to find the best possible solution to a
problem.
Background of Genetic Algorithm (GA)

•Introduced by Prof. John Holland (Michigan University, USA)


in 1965.
•First article on GA was published in 1975.
•It is based on two fundamental biological processes:
• Genetics - G.J. Mendel (1865)
• Evolution - C. Darwin (1875)
Genetics
•Branch of biology that deals with the study of genes, gene variation & heredity.
Evolution
•Process by which a population of organism's changes over generations.
Genetic variations cause these changes.
Genetic Algorithm (Working Principle)

Genetics
•Cells (Basic building blocks in living bodies)
•Each cell has the same set of chromosomes
• Humans: 46 (Female: 23, Male: 23)
• Mice: 40
•Chromosomes are the string of DNA (0’s and 1’s)
•Genes → Alleles
•Chromosomes consist of several genes
•Genes encode a specific trait (e.g., hair color, eye color)
Evolution

1.Heredity:
1. Offspring inherits many of its characteristics from parents.
2.Diversity:
1. Variation in characteristics in the next generation.
3.Selection:
Selection determines which individuals(chromosomes) will pass
their genes to next generation.The goal is to choose the fittest
scores, ensuring better solutions evolve over generation.
4.Ranking:
in this method individuals are sorted based on their
fitness scores.
Intuition Behind Genetic Algorithm

•Consider a hypothetical situation:


• If a country wants only good people(Health, Intelligence & Skills,
Social Behaviour & Morality, Economic Stability , Reproductive
Fitness), we implement a policy like this:
• Select only the good people using a specific criteria and ask them to
extend there generation by having their children.
• Repeat this for a few generations.
• After some generations, we have an entire generation of good
people.
• The basic idea is to have some changes in the input (i.e., population) to get
better output (i.e., better society).
Genetic Algorithm (GA) key Points

•Optimization technique
•Finds the best set of inputs to get the best output values
•Used for highly complex problems by simulating biological
processes (Genetics and Evolution)
Key Differences: Genetic Algorithm vs Traditional
Algorithm
Basic Structure (Flow Chart) of Genetic Algorithm

Basic Terms
Population
•It is a subset of all the possible solutions to the given problem.
Chromosome
•A chromosome is one such solution to the given problem.
Gene
•A gene is one element position of a chromosome.
Population = Set of Chromosomes
Flow Chart of Genetic Algorithm or
Phases in Genetic Algorithm or
Basic Structure of Genetic Algorithm

1) Population Initialization
•Population is initialized as a set of random solutions (random
chromosomes).
•Each individual solution is represented using a chromosome
(solution).
2) Fitness Function Calculation
•Fitness function determines how good a solution is.
•Each chromosome is assigned a fitness score.
•Best-scoring chromosomes are selected for reproduction to
create a new generation.
3) Selection
•The best or fittest individuals (based on fitness score) are
selected as parents.
•These parents pass their genes to the next generation.
4) Crossover
•Pairs of parents are selected.
•Their genes are combined using a crossover process.
•This produces offspring with characteristics from both
parents.
5) Mutation
•Some random changes occur in some genes.
•This helps maintain diversity and prevents premature
convergence.
Termination Check
•If the stopping criteria (e.g., optimal solution found) is met,
• Yes → Output the solution.
• No → Repeat the process.
Flowchart included showing the steps:
Genetic Operators

•Genetic operators are the operators used in genetic


algorithms to guide the algorithm towards a solution to a given
problem.
•These operators alter (change) the genetic composition of the
offspring (children).
•These operators work in conjunction with one another in
order for the algorithm to be successful.
Types of Genetic Operators

1)Selection
•The primary objective of the selection operator is to
emphasize good solutions and eliminate bad solutions in a
population while keeping the population size constant.
•Different solutions for choosing the best solution exist (e.g.,
Fitness-based Selection, Tournament Selection).
Crossover

•Crossover is the process of taking more than one parent


solution (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.
•Example:
• Parent 1: A B C D E F G H
• Parent 2: E G B C D H A F
• Offspring: A B C D D H A F
Mutation

•The mutation operator encourages genetic diversity among


solutions and attempts to prevent the genetic algorithm from
getting very close to one solution.
•It helps to give solutions that are different from the previous
generation.
•A better mutation can change solutions entirely, helping the
algorithm find a much better solution.
•Example:
• Before Mutation: A B C D D D H A F
• After Mutation: A B C D D D H A P
GA Elements

Genetic Algorithm uses a metaphor consisting of two distinct


elements:
1.Individual
2.Population
An individual is a single solution, while a population is a set of
individuals at an instant of the searching process.
Encoding techniques

Encoding is a process of representing solutions. The encoding


depends mainly on the problem.
There are many ways of encoding:
•Binary encoding: Representing a gene in terms of bits (0s and
1s).
•Real value encoding: Representing a gene in terms of values
or symbols or string.
•Permutation (or Order) encoding: Representing a sequence of
elements.
•Tree encoding: Representing in the form of a tree of objects.
Genetic Algorithms - Binary Representation

•Param1 value = 1000 = 8


•Param2 value = 1011 = 11
•Etc.
Example: 0-1 Knapsack problem
Example: 0-1 Knapsack problem
Minimization Problem
Limitation of using Binary Representation encoding
Example 2
Real Value Encoding

•"The real-coded GA is most suitable for optimization in a


continuous search space."
•"Uses the direct representations of the design parameters."
Genotype representation:
x y
Phenotype representation:
5.28 -475.36
Label: "Real-value representation"
Order Encoding

"Let us have a look into the following instance of the Traveling


Salesman Problem (TSP)."
TSP:
•Visit all the cities
•One city once only
•Starting and ending city is the same
Tree Encoding
TSP
Parent Selection

Parent selection in a Genetic Algorithm (GA) is the process of


choosing individuals from the current population to pass their
genes to the next generation. The selection aims to ensure that
fitter individuals have a higher chance of reproduction,
maintaining diversity while guiding evolution toward optimal
solutions.
Several techniques are commonly used:
1. Fitness Proportionate Selection
2. Tournament Selection
3. Rank Selection
4. Random Selection
Fitness Proportionate Selection
Fitness Proportionate Selection is one of the most
popular ways of parent selection. In this every
individual can become a parent with a probability
which is proportional to its fitness. Therefore, fitter
individuals have a higher chance of mating and
propagating their features to the next generation.
Therefore, such a selection strategy applies a selection
pressure to the more fit individuals in the population,
evolving better individuals over time.
Consider a circular wheel. The wheel is divided
into n pies, where n is the number of individuals
in the population. Each individual gets a portion of
the circle which is proportional to its fitness value.
Roulette Wheel Selection

The circular wheel is divided as described before. A


fixed point is chosen on the wheel circumference
as shown and the wheel is rotated. The region of
the wheel which comes in front of the fixed point is
chosen as the parent. For the second parent, the
same process is repeated.
It is clear that a fitter individual has a greater pie
on the wheel and therefore a greater chance of
landing in front of the fixed point when the wheel
is rotated. Therefore, the probability of choosing
an individual depends directly on its fitness.
Implementation wise, we use the following
steps −
•Calculate S = the sum of a finesses.
•Generate a random number between 0 and S.
•Starting from the top of the population, keep
adding the finesses to the partial sum P, till P<S.
•The individual for which P exceeds S is the chosen
individual.
Roulette wheel selection Example

Individual Chromosome Fitness


A 101010 12
B 111000 5
C 000111 8
D 110011 15

Consider a population of 4 individuals with the following fitness values:


Using the roulette wheel selection method,
calculate the selection probability for each individual.
Then, if a random number r = 0.65 is generated, which individual will be
selected?
Practice Problem 1

A population of 5 individuals with the following fitness values


genetic algorithm has a
Practice Problem 2
Stochastic Universal Sampling (SUS)

Stochastic Universal Sampling is quite similar to


Roulette wheel selection, however instead of
having just one fixed point, we have multiple fixed
points as shown in the following image. Therefore,
all the parents are chosen in just one spin of the
wheel. Also, such a setup encourages the highly fit
individuals to be chosen at least once.
Tournament Selection
Rank Selection
•Works with Negative Fitness Values – Unlike fitness proportionate selection, rank selection
can handle individuals with negative, fitness scores.
•Useful When Fitness Values Are Close – It is mainly used when the population members
have similar fitness values,which often happens in later generations of the genetic algorithm.
•Reduces Selection Pressure – Since each individual has an approximately equal chance of
being selected,
it reduces the focus on fitter individuals.
•Minimizes the Risk of Premature Convergence – By giving even low-fitness individuals a
chance,
rank selection helps maintain genetic diversity.
•Can Lead to Poor Parent Selection – Due to the loss of selection pressure, less fit
individuals might get selected, slowing down convergence towards an optimal solution.
•Works by Assigning Ranks Instead of Using Raw Fitness Values – The selection
probability is based on an individual’s rank rather than its absolute fitness value.
In this, we remove the concept of a fitness value
while selecting a parent. However, every individual
in the population is ranked according to their
fitness. The selection of the parents depends on
the rank of each individual and not the fitness. The
higher ranked individuals are preferred more than
the lower ranked ones.
Random Selection

In this strategy we randomly select parents from


the existing population. There is no selection
pressure towards fitter individuals and therefore
this strategy is usually avoided.
Crossover

•Crossover is the process of taking more than one parent


solution (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.
Crossover Operation 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)
• Half-uniform crossover (HUX)
• Shuffle crossover
• Three parent crossover
Single Point Crossover
Single Point Crossover: Illustration
Two Point Crossover: Illustration
Multipoint Crossover
Uniform Crossover
Uniform Crossover (UX): Illustration
Uniform Crossover with Crossover Mask:
Illustration
Half Uniform Crossover (HUX)
Half Uniform Crossover: Illustration
Shuffle Crossover
Shuffle Crossover: Illustration
Three Parents Crossover: Illustration
Mutation

Mutation is performed after crossover. Mutation is a genetic


operator used to maintain genetic diversity from one
generation of a population of chromosomes to the next.
•Mutation alters one or more gene values in a chromosome
from its initial value.
•With new gene values, the genetic algorithm may be able to
arrive at a better solution.
•Mutation is an important part of the search.
Types of Mutation

1.Flip Bit Method (Flipping)


In this, a mutation chromosome is created for a 1 mutation
chromosome, the corresponding bit in the offspring
chromosome is flipped (0 to 1 or 1 to 0) and mutated
chromosome is produced.
Example:
Offspring chromosome: 1 0 1 1 0 1
Mutation chromosome: 1 0 0 1 0 1
Mutated chromosome: 0 0 1 0 0 0
2. Boundary Method
The mutation operator replaces the value of the chosen gene
with either the upper or lower bound for that gene (chosen
randomly).
Example:
Offspring chromosome: 1 2 5 4 3 6 7 3
Mutation at upper bound →
Mutated chromosome: 1 7 5 4 3 6 7 3
3. Interchange Method
Two positions of the child's chromosome are chosen randomly,
and the bits corresponding to these positions are interchanged.
Example:
Offspring chromosome: 10110010
Interchange at two positions →
Mutated chromosome: 11100010
4. Reversing Method
A position is chosen at random, and the bit next to that
position is reversed to produce a mutated child.
Example:
Offspring chromosome: 01100100
Mutation applied →
Mutated chromosome: 01101011
Convergence in GA

For any problem, if GA is correctly implemented, the


population (set of solutions) evolves over successive
generations, with fitness values increasing toward the global
optimum.
So, convergence is the progression toward increasing
uniformity.
A population (set of solutions) is said to have converged when
95% of the individuals (solutions) constituting the population
have the same fitness value.
Convergence (Termination) Criteria

Each iteration should be tested with some convergence test.


Various convergence (termination) conditions are:
•A solution is found that satisfies the objective criteria.

•A fixed number of generations is executed.

•The allocated budget (computation time) is reached.

•The highest-ranking solution fitness is reaching or has reached a point


where successive iterations no longer produce better results.

• Manual inspection.
• Combination of the above .

You might also like