Genetic Algorithms
Genetic Algorithms
Algorithms
Classic Example of
Jonathon
Step 1 Create Sample
Population
Step 2: Design a fitness
Function
Step 3: Select the
Fittest
Step 4: Crossover &
Mutation
Crossover
Problem ???
Mutation
Jonathon at Work!!!
Introduction
After scientists became disillusioned with classical and neo-classical
attempts at modeling intelligence, they looked in other directions.
Two prominent fields arose, connectionism (neural networking, parallel
processing) and evolutionary computing.
1. Objective to survive
2. These algorithms are considered as a subfield of Computational Intelligence (CI) and Artificial Intelligence (AI)
3. Optimization problems, mostly having a black-box objective function (Maximization and Minimization Problems)
Genetic
Algorithm
What is GA
A genetic algorithm (or GA) is a search technique used
in computing to find true or approximate solutions to
optimization and search problems.
Genetic algorithms are categorized as global search
heuristics.
Genetic algorithms are a particular class of evolutionary
algorithms that use techniques inspired by evolutionary
biology such as inheritance, mutation, selection, and
crossover (also called recombination).
What is GA
Genetic algorithms are implemented as a computer
simulation in which a population of abstract
representations (called chromosomes or the genotype
or the genome) of candidate solutions (called
individuals, creatures, or phenotypes) to an
optimization problem evolves toward better solutions.
Phenotype:
– Physical characteristic of the genotype (smart, beautiful, healthy, etc.)
Genotype and Phenotype
Genetic Algorithms
An Example Genetic Algorithm
Procedure GA{
t = 0;
Initialize P(t);
Evaluate P(t);
Parents(t) = Select_Parents(P(t));
Offspring(t) = Procreate(Parents(t));
Evaluate(Offspring(t));
P(t+1)= Select_Survivors(P(t),Offspring(t));
t = t + 1;
}
Genetic Algorithms
Representation of Candidate Solutions
GAs on primarily two types of representations:
◦ Binary-Coded
◦ Real-Coded
Binary-Coded GAs must decode a chromosome into a CS,
evaluate the CS and return the resulting fitness back to the
binary-coded chromosome representing the evaluated CS.
Genetic Algorithms:
Binary-Coded Representations
For Example, let’s say that we are trying to optimize the
following function,
◦ f(x) = x2
◦ for 2 x 1
Individual Individual
Individual Individual
f(1.16) = 1.35
t = 0;
Initialize P(t);
Evaluate P(t);
Parents(t) = Select_Parents(P(t));
Offspring(t) = Procreate(Parents(t));
Evaluate(Offspring(t));
P(t+1)= Select_Survivors(P(t),Offspring(t));
t = t + 1;
}
Genetic Algorithms:
Parent Selection Methods
GA researchers have used a number of parent selection
methods. Some of the more popular methods are:
◦ Proportionate Selection
◦ Linear Rank Selection
◦ Tournament Selection
Genetic Algorithms:
Proportionate Selection
In Proportionate Selection, individuals are assigned a
probability of being selected based on their fitness:
◦ pi = fi / fj
◦ Where pi is the probability that individual i will be selected,
◦ fi is the fitness of individual i, and
◦ fj represents the sum of all the fitnesses of the individuals with the
population.
This type of selection is similar to using a roulette wheel
where the fitness of an individual is represented as
proportionate slice of wheel. The wheel is then spun and
the slice underneath the wheel when it stops determine
which individual becomes a parent.
Genetic Algorithms:
Proportionate Selection
There are a number of disadvantages associated with using
proportionate selection:
◦ Cannot be used on minimization problems,
◦ Loss of selection pressure (search direction) as population converges,
◦ Susceptible to Super Individuals
Genetic Algorithms:
Linear Rank Selection
In Linear Rank selection, individuals are assigned subjective
fitness based on the rank within the population:
◦ sfi = (P-ri)(max-min)/(P-1) + min
◦ Where ri is the rank of indvidual i,
◦ P is the population size,
◦ Max represents the fitness to assign to the best individual,
◦ Min represents the fitness to assign to the worst individual.
t = 0;
Initialize P(t);
Evaluate P(t);
Parents(t) = Select_Parents(P(t));
Offspring(t) = Procreate(Parents(t));
Evaluate(Offspring(t));
P(t+1)= Select_Survivors(P(t),Offspring(t));
t = t + 1;
}
Genetic Algorithms:
Genetic Procreation Operators
Genetic Algorithms typically use two types of operators:
◦ Crossover (Sexual Recombination), and
◦ Mutation (Asexual)
Parent1 1 0 0 0 0 1 0
Parent2 1 1 1 0 0 0 1
Child1 1 0 0 1 0 0 1
Child2 0 1 1 0 1 1 0
t = 0;
Initialize P(t);
Evaluate P(t);
Parents(t) = Select_Parents(P(t));
Offspring(t) = Procreate(Parents(t));
Evaluate(Offspring(t));
P(t+1)= Select_Survivors(P(t),Offspring(t));
t = t + 1;
}
Genetic Algorithms:
Selection Who Survives
Basically, there are two types of GAs commonly used.
These GAs are characterized by the type of replacement
strategies they use.
A Generational GA uses a (,) replacement strategy where
the offspring replace the parents.
A Steady-State GA usually will select two parents, create 1-2
offspring which will replace the 1-2 worst individuals in the
current population even if the offspring are worse than the
individuals they replace.
This slightly different than (+1) or (+2) replacement.
Genetic Algorithm:
Example by Hand
Now that we have an understanding of the various parts of
a GA let’s evolve a simple GA (SGA) by hand.
A SGA is :
◦ binary-coded,
◦ Uses proportionate selection
◦ uses single-point crossover (with a crossover usage rate between
0.6-1.0),
◦ uses a small mutation rate, and
◦ is generational.
Genetic Algorithms:
Example
The SGA for our example will use:
◦ A population size of 6,
◦ A crossover usage rate of 1.0, and
◦ A mutation rate of 1/7.
Is Replaced by:
Two individuals are then chosen randomly based on these probabilities and
produce offspring.
General Algorithm for
GA
Roulette Wheel’s Selection Pseudo Code:
end for
end for
do this twice
end for
end
create offspring
end loop
General Algorithm for
GA
Reproduction
The next step is to generate a second generation population of
solutions from those selected through genetic operators:
crossover (also called recombination), and/or mutation.
For each new solution to be produced, a pair of "parent"
solutions is selected for breeding from the pool selected
previously.
By producing a "child" solution using the above methods of
crossover and mutation, a new solution is created which typically
shares many of the characteristics of its "parents". New parents
are selected for each child, and the process continues until a new
population of solutions of appropriate size is generated.
General Algorithm for
GA
These processes ultimately result in the next generation population of
chromosomes that is different from the initial generation.
Generally the average fitness will have increased by this procedure for the
population, since only the best organisms from the first generation are
selected for breeding, along with a small proportion of less fit solutions, for
reasons already mentioned above.
Crossover
the most common type is single point crossover. In single point
crossover, you choose a locus at which you swap the remaining
alleles from on parent to the other. This is complex and is best
understood visually.
As you can see, the children take one section of the chromosome
from each parent.
The point at which the chromosome is broken depends on the
randomly selected crossover point.
This particular method is called single point crossover because
only one crossover point exists. Sometimes only child 1 or child 2
is created, but oftentimes both offspring are created and put into
the new population.
Crossover does not always occur, however. Sometimes, based on
a set probability, no crossover occurs and the parents are copied
directly to the new population. The probability of crossover
occurring is usually 60% to 70%.
Crossover
Mutation
After selection and crossover, you now have a new population
full of individuals.
Some are directly copied, and others are produced by crossover.
In order to ensure that the individuals are not all exactly the
same, you allow for a small chance of mutation.
You loop through all the alleles of all the individuals, and if that
allele is selected for mutation, you can either change it by a small
amount or replace it with a new value. The probability of
mutation is usually between 1 and 2 tenths of a percent.
Mutation is fairly simple. You just change the selected alleles
based on what you feel is necessary and move on. Mutation is,
however, vital to ensuring genetic diversity within the
population.
Mutation
General Algorithm for
GA
Termination
Al Biles uses genetic algorithms to filter out 'good' and 'bad' riffs for jazz
improvisation.
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
Checkboard example
Cont’d
◦ Chromosomes represent the way the checkboard is colored.
◦ Chromosomes are not represented by bitstrings but by
bitmatrices
◦ The bits in the bitmatrix can have one of the four values 0, 1, 2
or 3, depending on the color.
◦ Crossing-over involves matrix manipulation instead of point
wise operating.
◦ Crossing-over can be combining the parential matrices in a
horizontal, vertical, triangular or square way.
◦ Mutation remains bitwise changing bits in either one of the
other numbers.
Checkboard example
Cont’d
• This problem can be seen as a graph with n nodes and (n-1) edges,
so the fitness f(x) is defined as:
f(x) = 2 · (n-1) ·n
Checkboard example
Cont’d
• Fitnesscurves for different cross-over rules:
170 170
160 160
Fitness
150 150
140 140
130 130
0 100 200 300 400 500 0 200 400 600 800
170 170
160 160
Fitness
150 150
140 140
130 130
0 200 400 600 800 0 500 1000 1500
Generations Generations
Questions
??
THANK YOU