Enetic Lgorithm: Prepared by
Enetic Lgorithm: Prepared by
PREPARED BY:
NIDHI SHAH
1
Genetic Algorithm
A genetic algorithm (GA) is a search
technique used in computing to find exact
or approximate solutions to optimization
and search problems.
Searching is done from “search space”.
"search space" refers to some collection of
candidate solutions to a problem.
2
Eg :Suppose you want use a computer to
search for a protein.
protein—a sequence of amino acids
that folds up to a particular three-
dimensional shape so it can be used, say
to fight a specific virus.
Limiting length to less than100.
3
GA has a number of features:
Genetic algorithm is a population-based
search method.
GA uses recombination to mix
information of candidate solutions into a
new one (evolutionary).
GA is stochastic.
4
Diagrammatic Representation
Parent selection
Parents
Initialization
Recombination
/Cross over
Population
Mutation
Termination
Children
Survivor selection
5
ALGORITHM
Begin
INITIALIZE population with random candidate solutions;
EVALUATE each candidate;
repeat
SELECT parents;
RECOMBINE pairs of parents;
MUTATE the resulting children;
EVALUATE children;
SELECT individuals for the next generation
until TERMINATION-CONDITION is satisfied
End
6
COMPONENTS OF GENETIC
ALGORITHMS
The most important components in a GA
consist of:
Representation (definition of individuals)
Evaluation function (or fitness function)
Population
Variation operators (crossover and mutation)
Parent selection mechanism
Survivor selection mechanism (replacement)
7
Representation
Objects forming possible solution within
original problem context are called
phenotypes, their encoding, the individuals
within the GA, are called genotypes.
The representation step specifies the
mapping from the phenotypes onto a set of
genotypes.
8
Population
The role of the population is to hold possible
solutions.
A population is a multiset.
In almost all GA applications, the population
size is constant, not changing during the
evolutional search.
9
Variation Operators
The role of variation operators is to create
new individuals from old ones.
Variation operators form the
implementation of the elementary steps
with the search space.
Crossover Operator
Mutation Operator
10
Crossover Operator(Recombination)
The crossover operator is the most important in GA.
Crossover is a process yielding recombination of bit
strings.
Binary Variable.
The principle behind crossover is simple- Selecting
two candidates with different but desirable features,
we can produce an offspring which combines both of
those features.
There are many kinds of crossover
One-point Crossover
Two-point Cross Over
Uniform Crossover
11
One-point Crossover
The procedure of one-point crossover is to
randomly generate a number (less than or
equal to the string length) as the crossover
position.
Then, keep the bits before the number
unchanged and swap the bits after the
crossover position between the two
candidates.
12
Example: With the two candidates selected above, we
randomly generate a number (i.e. 2 )as the crossover
position:
Candidate1 : 7 3 7 6 1 3
Candidate2 : 1 7 4 5 2 2
Then we get two children:
Child 1 : 7 3| 4 5 2 2
Child 2 : 1 7| 7 6 1 3
13
Two-point Cross Over
The procedure of two-point crossover is
similar to that of one-point crossover except
that we must select two positions and only
the bits between the two positions are
swapped. This crossover method can
preserve the first and the last parts of a
chromosome and just swap the middle part.
14
Example: With the two candidates selected above,
we randomly generate two numbers 2 and 4 as the
crossover positions:
Candidate1 : 7 3 7 6 1 3
Candidate1 : 1 7 4 5 2 2
Then we get two children:
Child 1 : 7 3| 4 5| 1 3
Child 2 : 1 7| 7 6| 2 2
15
Uniform Crossover
The procedure of uniform crossover : each
gene of the first candidate has a 0.5
probability of swapping with the
corresponding gene of the second
candidate.
16
Example: For each position, we randomly generate
a number between 0 and 1, for example, 0.2, 0.7,
0.9, 0.4, 0.6, 0.1. If the number generated for a
given position is less than 0.5, then child1 gets the
gene from parent1, and child2 gets the gene from
parent2. Otherwise, vice versa.
0.2 0.7 0.9 0.4 0.6 0.1
Candidate1: 7 * 3 * 7 6 *1 3
Candidate2: 1 *7 *4 5 * 2 2
Then we get two children:
Child 1 : 7 7 4 6 2 3
Child 2 : 1 3 7 5 1 2
17
Mutation Operator
A unary variation operator is called
mutation.
In general, mutation is supposed to cause a
random unbiased change.
In the bitstring approach mutation is simpy
the flipping of one of the bits.
Advantage:
Mutation prevents the algorithm to be
trapped in a local minimum.
18
Example:
1 1
0 1
0 0
1 1
1 1
0 0
1 1 19
Parent Selection Mechanism
The role of parent selection is to distinguish
among individuals based on their quality to allow
the better individuals to become parents of the
next generation.
Parent selection is probabilistic.
Thus, high quality individuals get a higher chance
to become parents than those with low quality.
Nevertheless, low quality individuals are often
given a small, but positive chance, otherwise the
whole search could become too greedy and get
stuck in a local optimum.
20
The chance of each parent being selected is
in some way related to its fitness.
Fitness-based selection
Rank-based selection
Tournament-based selection
21
Fitness-based selection
The standard, original method for parent
selection is Roulette Wheel selection or
fitness-based selection.
In this kind of parent selection, each
candidate has a chance of selection that is
directly proportional to its fitness.
The effect of this depends on the range of
fitness values in the current population.
22
Candidate4
Candidate3 Candidate1
Candidate2
23
Rank-based selection
In the rank-based selection method,
selection probabilities are based on a
Candidate’s relative rank or position in the
population, rather than absolute fitness.
24
Tournament-based selection
Two individuals are chosen at random from
the population.
The fitter of the two individuals is selected
to be a parent.
25
Survivor selection mechanism
The role of survivor selection is to
distinguish among individuals based on their
quality.
In GA, the population size is (almost always)
constant, thus a choice has to be made on
which individuals will be allowed in the next
generation.
This decision is based on their fitness
values, favoring those with higher quality.
Selecting the top segment (fitness biased).
26
Termination Condition
Notice that GA is stochastic and mostly
there are no guarantees to reach an
optimum.
Commonly used conditions for terminations
are the following:
1. the maximally allowed CPU times elapses
2. The total number of fitness evaluations
reaches a given limit.
3. for a given period of time, the fitness
improvement remains under a threshold
value.
27
4. The population diversity drops under a
given threshold.
28
ALGORITHM (Revisited)
Begin
INITIALIZE population with random candidate solution
EVALUATE each candidate;
repeat
SELECT parents;
RECOMBINE pairs of parents;
MUTATE the resulting children;
EVALUATE children;
SELECT individuals for the next generation
until TERMINATION-CONDITION is satisfied
End
29
Thank you….
30