Genetic Algorithm
Genetic Algorithm
1
Genetic Algorithm
• The genetic algorithm is a method for solving both constrained and unconstrained optimization
problems that is based on natural selection, the process that drives biological evolution.
• The genetic algorithm repeatedly modifies a population of individual solutions. At each step, the
genetic algorithm selects individuals from the current population to be parents and uses them to
produce the children for the next generation. Over successive generations, the population "evolves"
toward an optimal solution.
• You can apply the genetic algorithm to solve a variety of optimization problems that are not well
suited for standard optimization algorithms, including problems in which the objective function is
discontinuous, nondifferentiable, stochastic, or highly nonlinear.
2
What are
Genetic
Algorithms Search based
algorithms based on
Used to find optimal
or near-optimal
? the concepts of solutions to difficult
natural selection and problems which
genetics otherwise would take
a lifetime to solve
Developed by John
Holland and his Most notably
students and developed David E.
colleagues at the Goldberg
University of
Michigan
3
What are
Genetic • In GAs, we have a pool or a population of possible
Algorithms solutions to the given problem.
? • These solutions then undergo recombination and
mutation (like in natural genetics), producing new
children, and the process is repeated over various
generations.
• Each individual (or candidate solution) is assigned a
fitness value (based on its objective function value) and
the fitter individuals are given a higher chance to mate
and yield more “fitter” individuals.
• This is in line with the Darwinian Theory of “Survival of
the Fittest”.
4
Algorithmic steps of GA
5
• The genetic algorithm uses three main types of rules at each step to create the next
generation from the current population:
• Selection rules select the individuals, called parents, that contribute to the
population at the next generation. The selection is generally stochastic and can
depend on the individuals' scores.
• Crossover rules combine two parents to form children for the next generation.
6
Why use
GAs? • GA can solve NP-Hard problems for which even the
most powerful computing systems take a very long time
(even years!) to solve.
• Can give good solution fast
• Failure of Gradient Based Methods:
7
• Fitness Function: A fitness function simply defined is a function which takes the
solution as input and produces the suitability of the solution as the output. The fitness
function is the function you want to optimize. For standard optimization algorithms, this
is known as the objective function.
• Individuals: An individual is any point to which you can apply the fitness function. The
value of the fitness function for an individual is its score.
Basic • Population: It is a subset of all the possible (encoded) solutions to the given problem.
Terminology The population for a GA is analogous to the population for human beings except that
instead of human beings, we have Candidate Solutions representing human beings. Thus,
A population is an array of individuals. For example, if the size of the population is 100
and the number of variables in the fitness function is 3, you represent the population by a
100-by-3 matrix.
• Parents and Children :To create the next generation, the genetic algorithm selects
certain individuals in the current population, called parents, and uses them to create
individuals in the next generation, called children. Typically, the algorithm is more likely to
select parents that have better fitness values.
• Chromosomes: A chromosome is one such solution to the given problem.
• Gene: A gene is one element position of a chromosome.
• Allele: It is the value a gene takes for a particular chromosome.
8
Basic
Terminology
9
Basic
Terminology • Genotype: Genotype is the population in the
computation space. In the computation space, the
solutions are represented in a way which can be easily
understood and manipulated using a computing system.
• Phenotype: Phenotype is the population in the actual
real world solution space in which solutions are
represented in a way they are represented in real world
situations.
• Decoding and Encoding: Decoding is a process of
transforming a solution from the genotype to the
phenotype space, while encoding is a process of
transforming from the phenotype to genotype space.
Decoding should be fast as it is carried out repeatedly in
a GA during the fitness value calculation.
• Genetic Operators: These alter the genetic
composition of the offspring. These include crossover,
mutation, selection, etc.
10
Basic
Terminology
11
How the Genetic Algorithm Works
• The genetic algorithm uses the following options to determine when to stop
• MaxGenerations — The algorithm stops when the number of generations reaches MaxGenerations.
• MaxTime — The algorithm stops after running for an amount of time in seconds equal to MaxTime.
• FitnessLimit — The algorithm stops when the value of the fitness function for the best point in the current population
is less than or equal to FitnessLimit.
• MaxStallGenerations — The algorithm stops when the average relative change in the fitness function value over
MaxStallGenerations is less than Function tolerance.
• MaxStallTime — The algorithm stops if there is no improvement in the objective function during an interval of time
in seconds equal to MaxStallTime.
• FunctionTolerance — The algorithm runs until the average relative change in the fitness function value over
MaxStallGenerations is less than Function tolerance.
• ConstraintTolerance — The ConstraintTolerance is not used as stopping criterion. It is used to determine the
feasibility with respect to nonlinear constraints. Also, max(sqrt(eps),ConstraintTolerance) determines feasibility with
respect to linear constraints.
13
How do we
use GAs to
optimize the
parameters 01 Choose parameters to
optimize
Generate initial
03 population of individuals
(chromosomes)
14
15
GA
Population • Things to be kept in mind when dealing with GA
population
• The diversity of the population should be maintained
otherwise it might lead to premature convergence.
• The population size should not be kept very large as it
can cause a GA to slow down, while a smaller
population might not be enough for a good mating
pool.
• Therefore, an optimal population size needs to be
decided by trial and error.
16
Fitness
Function • Function which takes a candidate solution to the
problem as input and produces as output how “fit” our
how “good” the solution is with respect to the problem in
consideration.
• Characteristics of a good fitness function:
• The fitness function should be sufficiently fast to
compute.
• It must quantitatively measure how fit a given
solution is or how fit individuals can be produced
from the given solution.
17
Knapsack
Problem &
Given a set of items, each with a weight and a value,
its fitness determine the number of each item to include in a
calculation collection so that the total weight is less than or equal to
a given limit and the total value is as large as possible.
18
Knapsack
Problem & Fitness function sums the profit values of the items being
its fitness picked (which have a 1), scanning the elements from left to
right till the knapsack is full.
calculation
19
GA: Parent
selection • Process of selecting parents which mate and recombine
to create off-springs for the next generation. Parent
selection is very crucial to the convergence rate.
• Different possible models are:
• Fitness Proportionate Selection
• Tournament Selection
• Rank Selection
• Random Selection : Randomly select parents from
the existing population
20
Fitness
Proportionate
Selection • It 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.
• It has possible implementations:
• Roulette Wheel Selection
• Stochastic Universal Sampling (SUS)
21
Roulette
Wheel • The wheel is spun until two parents are selected
Selection • Probability of parenthood is proportional to fitness
• If two individuals have a much higher fitness, they
could be the parents for every child in the next
generation.
• Fitness cannot take negative value
• Fitness values cannot be close enough
22
Stochastic
Universal • Similar to Roulette wheel selection
Sampling • Instead of having just one fixed point, we have multiple
(SUS) fixed points
• All the parents are chosen in just one spin of the wheel
23
Tournament
Selection • Four individuals (A,B,C,D) are randomly selected from
the population.
• Two are eliminated and two become the parents of a
child in the next generation
24
Rank
Selection • Mostly used when the individuals in the population have
very close fitness values.
• 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.
25
GA Crossover
• Crossover operator is analogous to reproduction and
biological crossover.
• Popularly used crossover operators
• One Point Crossover
• Multi Point Crossover
• Uniform Crossover
• Whole Arithmetic Recombination
• Davis’ Order Crossover (OX1)
26
One
Point
• A random crossover point is selected and the tails of its
Crossover two parents are swapped to get new off-springs
27
Multi
Point • Alternating segments are swapped to get new off-
springs.
Crossover
28
Uniform
Crossover • Each gene treated separately.
• In this, we essentially flip a coin for each chromosome to
decide whether or not it’ll be included in the off-spring.
29
Whole
Arithmetic • Used for integer representations and works by taking
Recombinatio the weighted average of the two parents by using the
n following formulae:
• Child1 = α.x + (1-α).y
• Child2 = α.y + (1-α).x
• If α=0.5, then both the children will be identical
30
GA:
Mutation • Mutation may be defined as a small random tweak in the
chromosome, to get a new solution.
• Popular Operators:
• Bit Flip Mutation
• Random Resetting
• Swap Mutation
• Scramble Mutation
• Inversion Mutation
31
Bit Flip
Mutation
32
Swap
Mutation
33
Scramble
Mutation
• From the entire chromosome, a subset of genes is chosen
and their values are scrambled or shuffled randomly.
34
Inversion
Mutation
35
GA: Survival
Selection/Elit
• The Survivor Selection Policy determines which
ism individuals are to be moved out and which are to be kept
in the next generation
• Elitism refers to the safeguarding of the chromosome of
the most fit individual in a given generation.
• This ensures that the best chromosome is never lost in
the optimization process due to random events.
36
GA:
Termination
Condition • The termination condition of a Genetic Algorithm is
important in determining when a GA run will end.
• Usual 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
37
Advantages
of GAs • 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
• Optimizes both continuous and discrete functions
and also multi-objective problems.
• Useful when the search space is very large and there
are a large number of parameters involved.
• Provides a list of “good” solutions and not just a
single solution.
38
Limitations
of GAs GAs are not suited for all problems, especially
problems which are simple and for which 01
derivative information is available.
39
Application
Areas of GA • Optimization
• Economics
• Neural Networks
• Vehicle Routing Problems
• Scheduling Applications
• Machine Learning
• Robot Trajectory Generation
• Parametric Design of Aircraft
• Travelling Salesman Problem & its applications
40