ML RUSA Module 7 Genetic Algorithm
ML RUSA Module 7 Genetic Algorithm
Module 7
What is Genetic Algorithm
• GA is a heuristic search algorithm inspired by Darwin’s natural
evolution theory.
• The algorithm reflects the process of Natural Selection in which
the fittest individuals are selected for reproduction in order to
produce offspring of the next generation.
• Rather than search from general-to-specific hypotheses, or from
simple-to-complex, GA generate successor hypotheses by
repeatedly mutating and recombining parts of the best currently
known hypotheses.
• A collection of hypotheses called the current population
• Generate-and-test beam-search: present population is
updated by replacing some fraction of the population
by offspring of the most fit current hypotheses for
next generation.
• Widely used in many real-world applications such as
image processing, game programming, artificial
creativity.
THE GENETIC ALGORITHM (GA)
• The Genetic Algorithm is a computational approximation to how
evolution performs search, which is by producing modifications of
the parent genomes in their offspring and thus producing new
individuals with different fitness.
Genetic
Fitness Parent operations: Comput
computatio selection Crossover, e fitness
Mutation
n
If criteria
End
met?
Initial Population
0 1 Gene
• To begin GA process, we want a set of
individual chromosomes
• Each individual is called chromosome which A1 0 0 0 0 0 0
is a solution to the problem.
• Each individual is characterized by a set of
A2 1 1 1 1 1 1
parameters called “genes”
Chromosome
• Genes are combined in the form of string to
form Chromosome. A3 1 0 1 0 1 1
A4 1 1 0 1 1 0
Population
Fitness Function
0 1 Gene
• Determines how fit an individual is: that
means the ability of an individual to compete
with other individual. A1 0 0 0 0 0 0
• Fitness function gives a fitness score to each
individual.
A2 1 1 1 1 1 1
• The probability that an individual will be
selected for next generation is based on the Chromosome
fitness score. 1 0 1 0 1 1
A3
A4 1 1 0 1 1 0
Population
Population
• After the initial population is chosen randomly, the algorithm evolves
to produce each successive generation, with the hope being that
there will be progressively fitter individuals in the populations as the
number of generations increases.
• first generation usually being created randomly.
• The fitness of each string is then evaluated, and that first generation is
bred together to make a second generation, which is then used to
generate a third, and so on.
Generating Offspring: Parent Selection
For the current generation we need to select those strings that will be used to generate
new offspring.
Tournament Selection
Repeatedly pick four strings from the population, with replacement and put the fittest
two of them into the mating pool.
Truncation Selection
Pick some fraction f of the best strings and ignore the rest. For example, f = 0.5 is often
used, so the best 50% of the strings are put into the mating pool, each twice so that the
pool is the right size. The pool is randomly shuffled to make the pairs.
Fitness Proportional Selection
The better option is to select strings probabilistically, with the probability of a string being
selected being proportional to its fitness. The function that is generally used is (for string
α):
GENERATING OFFSPRING: GENETIC OPERATORS
There are two genetic operators that are generally used:
1. Cross Over
2. Mutation
Crossover :
Crossover is the operator that performs global exploration.
we generate the new string as part of the first parent and part of the second.
The crossover operator produces two new offspring from two parent strings, by copying
selected bits from each parent. The bit at position i in each offspring is copied from the bit
at position i in one of the two parents.
The choice of which parent contributes the bit for position i is determined by an additional
string called the crossover mask
Encoding:
• To map upto 31 use 5 bit encoding 0(00000) to
1(11111)
Select Initial Population
• At random 4
• Choose any four from the population
f(x)/Sum f(x)/AVG
= 144/1155 = 0.1247 = 144/288 = 0.4987