SlideShare a Scribd company logo
1 of 44
Genetic AlgorithmsGenetic Algorithms
Muhannad HarrimMuhannad Harrim
IntroductionIntroduction
 After scientists became disillusioned withAfter scientists became disillusioned with
classical and neo-classical attempts atclassical and neo-classical attempts at
modeling intelligence, they looked in othermodeling intelligence, they looked in other
directions.directions.
 Two prominent fields arose, connectionismTwo prominent fields arose, connectionism
(neural networking, parallel processing) and(neural networking, parallel processing) and
evolutionary computing.evolutionary computing.
 It is the latter that this essay deals with -It is the latter that this essay deals with -
genetic algorithms and genetic programming.genetic algorithms and genetic programming.
What is GAWhat is GA
 AA genetic algorithmgenetic algorithm (or(or GAGA) is a search technique) is a search technique
used in computing to find true or approximateused in computing to find true or approximate
solutions to optimization and search problems.solutions to optimization and search problems.
 Genetic algorithms are categorized as global searchGenetic algorithms are categorized as global search
heuristics.heuristics.
 Genetic algorithms are a particular class ofGenetic algorithms are a particular class of
evolutionary algorithms that use techniques inspiredevolutionary algorithms that use techniques inspired
by evolutionary biology such as inheritance,by evolutionary biology such as inheritance,
mutation, selection, and crossover (also calledmutation, selection, and crossover (also called
recombination).recombination).
What is GAWhat is GA
 Genetic algorithms are implemented as a computerGenetic algorithms are implemented as a computer
simulation in which a population of abstractsimulation in which a population of abstract
representations (called chromosomes or the genotyperepresentations (called chromosomes or the genotype
or the genome) of candidate solutions (calledor the genome) of candidate solutions (called
individuals, creatures, or phenotypes) to anindividuals, creatures, or phenotypes) to an
optimization problem evolves toward better solutions.optimization problem evolves toward better solutions.
 Traditionally, solutions are represented in binary asTraditionally, solutions are represented in binary as
strings of 0s and 1s, but other encodings are alsostrings of 0s and 1s, but other encodings are also
possible.possible.
What is GAWhat is GA
 The evolution usually starts from a population ofThe evolution usually starts from a population of
randomly generated individuals and happens inrandomly generated individuals and happens in
generations.generations.
 In each generation, the fitness of every individual inIn each generation, the fitness of every individual in
the population is evaluated, multiple individuals arethe population is evaluated, multiple individuals are
selected from the current population (based on theirselected from the current population (based on their
fitness), and modified (recombined and possiblyfitness), and modified (recombined and possibly
mutated) to form a new population.mutated) to form a new population.
What is GAWhat is GA
 The new population is then used in the nextThe new population is then used in the next
iteration of the algorithm.iteration of the algorithm.
 Commonly, the algorithm terminates whenCommonly, the algorithm terminates when
either a maximum number of generations haseither a maximum number of generations has
been produced, or a satisfactory fitness levelbeen produced, or a satisfactory fitness level
has been reached for the population.has been reached for the population.
 If the algorithm has terminated due to aIf the algorithm has terminated due to a
maximum number of generations, amaximum number of generations, a
satisfactory solution may or may not havesatisfactory solution may or may not have
been reached.been reached.
Key termsKey terms
 IndividualIndividual - Any possible solution- Any possible solution
 PopulationPopulation - Group of all- Group of all individualsindividuals
 Search SpaceSearch Space - All possible solutions to the problem- All possible solutions to the problem
 ChromosomeChromosome - Blueprint for an- Blueprint for an individualindividual
 TraitTrait - Possible aspect (- Possible aspect (features)features) of anof an individualindividual
 Allele -- Possible settings of trait (black, blond, etc.)
 LocusLocus - The position of a- The position of a genegene on theon the chromosomechromosome
 GenomeGenome - Collection of all- Collection of all chromosomeschromosomes for anfor an
individualindividual
Chromosome, Genes and
Genomes
Genotype and Phenotype
 Genotype:
– Particular set of genes in a genome
 Phenotype:
– Physical characteristic of the genotype
(smart, beautiful, healthy, etc.)
Genotype and Phenotype
GA RequirementsGA Requirements
 A typical genetic algorithm requires two things to be defined:A typical genetic algorithm requires two things to be defined:
 a genetic representation of the solution domain, anda genetic representation of the solution domain, and
 a fitness function to evaluate the solution domain.a fitness function to evaluate the solution domain.
 A standard representation of the solution is as an array of bits.A standard representation of the solution is as an array of bits.
Arrays of other types and structures can be used in essentiallyArrays of other types and structures can be used in essentially
the same way.the same way.
 The main property that makes these genetic representationsThe main property that makes these genetic representations
convenient is that their parts are easily aligned due to theirconvenient is that their parts are easily aligned due to their
fixed size, that facilitates simple crossover operation.fixed size, that facilitates simple crossover operation.
 Variable length representations may also be used, butVariable length representations may also be used, but
crossover implementation is more complex in this case.crossover implementation is more complex in this case.
 Tree-like representations are explored in GeneticTree-like representations are explored in Genetic
programming.programming.
RepresentationRepresentation
Chromosomes could be:Chromosomes could be:
 Bit strings (0101 ... 1100)Bit strings (0101 ... 1100)
 Real numbers (43.2 -33.1 ... 0.0 89.2)Real numbers (43.2 -33.1 ... 0.0 89.2)
 Permutations of element (E11 E3 E7 ... E1 E15)Permutations of element (E11 E3 E7 ... E1 E15)
 Lists of rules (R1 R2 R3 ... R22 R23)Lists of rules (R1 R2 R3 ... R22 R23)
 Program elements (genetic programming)Program elements (genetic programming)
 ... any data structure ...... any data structure ...
GA RequirementsGA Requirements
 The fitness function is defined over the genetic representationThe fitness function is defined over the genetic representation
and measures theand measures the qualityquality of the represented solution.of the represented solution.
 The fitness function is always problem dependent.The fitness function is always problem dependent.
 For instance, in theFor instance, in the knapsack problemknapsack problem we want to maximizewe want to maximize
the total value of objects that we can put in a knapsack ofthe total value of objects that we can put in a knapsack of
some fixed capacity.some fixed capacity.
 A representation of a solution might be an array of bits, whereA representation of a solution might be an array of bits, where
each bit represents a different object, and the value of the biteach bit represents a different object, and the value of the bit
(0 or 1) represents whether or not the object is in the knapsack.(0 or 1) represents whether or not the object is in the knapsack.
 Not every such representation is valid, as the size of objectsNot every such representation is valid, as the size of objects
may exceed the capacity of the knapsack.may exceed the capacity of the knapsack.
 TheThe fitnessfitness of the solution is the sum of values of all objects inof the solution is the sum of values of all objects in
the knapsack if the representation is valid, or 0 otherwise. Inthe knapsack if the representation is valid, or 0 otherwise. In
some problems, it is hard or even impossible to define thesome problems, it is hard or even impossible to define the
fitness expression; in these cases, interactive geneticfitness expression; in these cases, interactive genetic
algorithms are used.algorithms are used.
A fitness functionA fitness function
Basics of GABasics of GA
 The most common type of genetic algorithm works like this:The most common type of genetic algorithm works like this:
 a population is created with a group of individuals createda population is created with a group of individuals created
randomly.randomly.
 The individuals in the population are then evaluated.The individuals in the population are then evaluated.
 The evaluation function is provided by the programmer andThe evaluation function is provided by the programmer and
gives the individuals a score based on how well they performgives the individuals a score based on how well they perform
at the given task.at the given task.
 Two individuals are then selected based on their fitness, theTwo individuals are then selected based on their fitness, the
higher the fitness, the higher the chance of being selected.higher the fitness, the higher the chance of being selected.
 These individuals then "reproduce" to create one or moreThese individuals then "reproduce" to create one or more
offspring, after which the offspring are mutated randomly.offspring, after which the offspring are mutated randomly.
 This continues until a suitable solution has been found or aThis continues until a suitable solution has been found or a
certain number of generations have passed, depending on thecertain number of generations have passed, depending on the
needs of the programmer.needs of the programmer.
General Algorithm for GAGeneral Algorithm for GA
 InitializationInitialization
 Initially many individual solutions are randomlyInitially many individual solutions are randomly
generated to form an initial population. Thegenerated to form an initial population. The
population size depends on the nature of the problem,population size depends on the nature of the problem,
but typically contains several hundreds or thousandsbut typically contains several hundreds or thousands
of possible solutions.of possible solutions.
 Traditionally, the population is generated randomly,Traditionally, the population is generated randomly,
covering the entire range of possible solutions (thecovering the entire range of possible solutions (the
search spacesearch space).).
 Occasionally, the solutions may be "seeded" in areasOccasionally, the solutions may be "seeded" in areas
where optimal solutions are likely to be found.where optimal solutions are likely to be found.
General Algorithm for GAGeneral Algorithm for GA
 SelectionSelection
 During each successive generation, a proportion of the existingDuring each successive generation, a proportion of the existing
population is selected to breed a new generation.population is selected to breed a new generation.
 Individual solutions are selected through aIndividual solutions are selected through a fitness-basedfitness-based
process, where fitter solutions (as measured by a fitnessprocess, where fitter solutions (as measured by a fitness
function) are typically more likely to be selected.function) are typically more likely to be selected.
 Certain selection methods rate the fitness of each solution andCertain selection methods rate the fitness of each solution and
preferentially select the best solutions. Other methods ratepreferentially select the best solutions. Other methods rate
only a random sample of the population, as this process mayonly a random sample of the population, as this process may
be very time-consuming.be very time-consuming.
 Most functions are stochastic and designed so that a smallMost functions are stochastic and designed so that a small
proportion of less fit solutions are selected. This helps keepproportion of less fit solutions are selected. This helps keep
the diversity of the population large, preventing prematurethe diversity of the population large, preventing premature
convergence on poor solutions. Popular and well-studiedconvergence on poor solutions. Popular and well-studied
selection methods include roulette wheel selection andselection methods include roulette wheel selection and
tournament selection.tournament selection.
General Algorithm for GAGeneral Algorithm for GA
 In roulette wheel selection, individuals areIn roulette wheel selection, individuals are
given a probability of being selected that isgiven a probability of being selected that is
directly proportionate to their fitness.directly proportionate to their fitness.
 Two individuals are then chosen randomlyTwo individuals are then chosen randomly
based on these probabilities and producebased on these probabilities and produce
offspring.offspring.
General Algorithm for GAGeneral Algorithm for GA
Roulette Wheel’s Selection Pseudo Code:Roulette Wheel’s Selection Pseudo Code:
for all members of populationfor all members of population
sum += fitness of this individualsum += fitness of this individual
end forend for
for all members of populationfor all members of population
probability = sum of probabilities + (fitness / sum)probability = sum of probabilities + (fitness / sum)
sum of probabilities += probabilitysum of probabilities += probability
end forend for
loop until new population is fullloop until new population is full
do this twicedo this twice
number = Random between 0 and 1number = Random between 0 and 1
for all members of populationfor all members of population
if number > probability but less than next probability thenif number > probability but less than next probability then
you have been selectedyou have been selected
end forend for
endend
create offspringcreate offspring
end loopend loop
General Algorithm for GAGeneral Algorithm for GA
 ReproductionReproduction
 The next step is to generate a second generation population ofThe next step is to generate a second generation population of
solutions from those selected through genetic operators:solutions from those selected through genetic operators:
crossover (also called recombination), and/or mutation.crossover (also called recombination), and/or mutation.
 For each new solution to be produced, a pair of "parent"For each new solution to be produced, a pair of "parent"
solutions is selected for breeding from the pool selectedsolutions is selected for breeding from the pool selected
previously.previously.
 By producing a "child" solution using the above methods ofBy producing a "child" solution using the above methods of
crossover and mutation, a new solution is created whichcrossover and mutation, a new solution is created which
typically shares many of the characteristics of its "parents".typically shares many of the characteristics of its "parents".
New parents are selected for each child, and the processNew parents are selected for each child, and the process
continues until a new population of solutions of appropriatecontinues until a new population of solutions of appropriate
size is generated.size is generated.
General Algorithm for GAGeneral Algorithm for GA
 These processes ultimately result in the nextThese processes ultimately result in the next
generation population of chromosomes that isgeneration population of chromosomes that is
different from the initial generation.different from the initial generation.
 Generally the average fitness will haveGenerally the average fitness will have
increased by this procedure for the population,increased by this procedure for the population,
since only the best organisms from the firstsince only the best organisms from the first
generation are selected for breeding, alonggeneration are selected for breeding, along
with a small proportion of less fit solutions, forwith a small proportion of less fit solutions, for
reasons already mentioned above.reasons already mentioned above.
CrossoverCrossover
 the most common type is single point crossover. In singlethe most common type is single point crossover. In single
point crossover, you choose a locus at which you swap thepoint crossover, you choose a locus at which you swap the
remaining alleles from on parent to the other. This is complexremaining alleles from on parent to the other. This is complex
and is best understood visually.and is best understood visually.
 As you can see, the children take one section of theAs you can see, the children take one section of the
chromosome from each parent.chromosome from each parent.
 The point at which the chromosome is broken depends on theThe point at which the chromosome is broken depends on the
randomly selected crossover point.randomly selected crossover point.
 This particular method is called single point crossover becauseThis particular method is called single point crossover because
only one crossover point exists. Sometimes only child 1 oronly one crossover point exists. Sometimes only child 1 or
child 2 is created, but oftentimes both offspring are createdchild 2 is created, but oftentimes both offspring are created
and put into the new population.and put into the new population.
 Crossover does not always occur, however. Sometimes, basedCrossover does not always occur, however. Sometimes, based
on a set probability, no crossover occurs and the parents areon a set probability, no crossover occurs and the parents are
copied directly to the new population. The probability ofcopied directly to the new population. The probability of
crossover occurring is usually 60% to 70%.crossover occurring is usually 60% to 70%.
CrossoverCrossover
MutationMutation
 After selection and crossover, you now have a new populationAfter selection and crossover, you now have a new population
full of individuals.full of individuals.
 Some are directly copied, and others are produced bySome are directly copied, and others are produced by
crossover.crossover.
 In order to ensure that the individuals are not all exactly theIn order to ensure that the individuals are not all exactly the
same, you allow for a small chance of mutation.same, you allow for a small chance of mutation.
 You loop through all the alleles of all the individuals, and ifYou loop through all the alleles of all the individuals, and if
that allele is selected for mutation, you can either change it bythat allele is selected for mutation, you can either change it by
a small amount or replace it with a new value. The probabilitya small amount or replace it with a new value. The probability
of mutation is usually between 1 and 2 tenths of a percent.of mutation is usually between 1 and 2 tenths of a percent.
 Mutation is fairly simple. You just change the selected allelesMutation is fairly simple. You just change the selected alleles
based on what you feel is necessary and move on. Mutation is,based on what you feel is necessary and move on. Mutation is,
however, vital to ensuring genetic diversity within thehowever, vital to ensuring genetic diversity within the
population.population.
MutationMutation
General Algorithm for GAGeneral Algorithm for GA
 TerminationTermination
 This generational process is repeated until aThis generational process is repeated until a
termination condition has been reached.termination condition has been reached.
 Common terminating conditions are:Common terminating conditions are:
 A solution is found that satisfies minimum criteriaA solution is found that satisfies minimum criteria
 Fixed number of generations reachedFixed number of generations reached
 Allocated budget (computation time/money) reachedAllocated budget (computation time/money) reached
 The highest ranking solution's fitness is reaching or hasThe highest ranking solution's fitness is reaching or has
reached a plateau such that successive iterations no longerreached a plateau such that successive iterations no longer
produce better resultsproduce better results
 Manual inspectionManual inspection
 Any Combinations of the aboveAny Combinations of the above
GA Pseudo-codeGA Pseudo-code
Choose initial populationChoose initial population
Evaluate the fitness of each individual in the populationEvaluate the fitness of each individual in the population
RepeatRepeat
Select best-ranking individuals to reproduceSelect best-ranking individuals to reproduce
Breed new generation through crossover and mutation (geneticBreed new generation through crossover and mutation (genetic
operations) and give birth to offspringoperations) and give birth to offspring
Evaluate the individual fitnesses of the offspringEvaluate the individual fitnesses of the offspring
Replace worst ranked part of population with offspringReplace worst ranked part of population with offspring
Until <terminating condition>Until <terminating condition>
Symbolic AI VS. GeneticSymbolic AI VS. Genetic
AlgorithmsAlgorithms
 Most symbolic AI systems are very static.Most symbolic AI systems are very static.
 Most of them can usually only solve one givenMost of them can usually only solve one given
specific problem, since their architecture wasspecific problem, since their architecture was
designed for whatever that specific problem was indesigned for whatever that specific problem was in
the first place.the first place.
 Thus, if the given problem were somehow to beThus, if the given problem were somehow to be
changed, these systems could have a hard timechanged, these systems could have a hard time
adapting to them, since the algorithm that wouldadapting to them, since the algorithm that would
originally arrive to the solution may be eitheroriginally arrive to the solution may be either
incorrect or less efficient.incorrect or less efficient.
 Genetic algorithms (or GA) were created to combatGenetic algorithms (or GA) were created to combat
these problems; they are basically algorithms basedthese problems; they are basically algorithms based
on natural biological evolution.on natural biological evolution.
Symbolic AI VS. GeneticSymbolic AI VS. Genetic
AlgorithmsAlgorithms
 The architecture of systems that implement genetic algorithmsThe architecture of systems that implement genetic algorithms
(or GA) are more able to adapt to a wide range of problems.(or GA) are more able to adapt to a wide range of problems.
 A GA functions by generating a large set of possible solutionsA GA functions by generating a large set of possible solutions
to a given problem.to a given problem.
 It then evaluates each of those solutions, and decides on aIt then evaluates each of those solutions, and decides on a
"fitness level" (you may recall the phrase: "survival of the"fitness level" (you may recall the phrase: "survival of the
fittest") for each solution set.fittest") for each solution set.
 These solutions then breed new solutions.These solutions then breed new solutions.
 The parent solutions that were more "fit" are more likely toThe parent solutions that were more "fit" are more likely to
reproduce, while those that were less "fit" are more unlikely toreproduce, while those that were less "fit" are more unlikely to
do so.do so.
 In essence, solutions are evolved over time. This way youIn essence, solutions are evolved over time. This way you
evolve your search space scope to a point where you can findevolve your search space scope to a point where you can find
the solution.the solution.
 Genetic algorithms can be incredibly efficient if programmedGenetic algorithms can be incredibly efficient if programmed
correctly.correctly.
Genetic ProgrammingGenetic Programming
 In programming languages such as LISP, the mathematicalIn programming languages such as LISP, the mathematical
notation is not written in standard notation, but in prefixnotation is not written in standard notation, but in prefix
notation. Some examples of this:notation. Some examples of this:
 + 2 1+ 2 1 :: 2 + 12 + 1
 * + 2 1 2* + 2 1 2 :: 2 * (2+1)2 * (2+1)
 * + - 2 1 4 9 :* + - 2 1 4 9 : 9 * ((2 - 1) + 4)9 * ((2 - 1) + 4)
 Notice the difference between the left-hand side to the right?Notice the difference between the left-hand side to the right?
Apart from the order being different, no parenthesis! TheApart from the order being different, no parenthesis! The
prefix method makes it a lot easier for programmers andprefix method makes it a lot easier for programmers and
compilers alike, because order precedence is not an issue.compilers alike, because order precedence is not an issue.
 You can build expression trees out of these strings that thenYou can build expression trees out of these strings that then
can be easily evaluated, for example, here are the trees for thecan be easily evaluated, for example, here are the trees for the
above three expressions.above three expressions.
Genetic ProgrammingGenetic Programming
Genetic ProgrammingGenetic Programming
 You can see how expression evaluation is thus a lotYou can see how expression evaluation is thus a lot
easier.easier.
 What this have to do with GAs? If for example youWhat this have to do with GAs? If for example you
have numerical data and 'answers', but no expressionhave numerical data and 'answers', but no expression
to conjoin the data with the answers.to conjoin the data with the answers.
 A genetic algorithm can be used to 'evolve' anA genetic algorithm can be used to 'evolve' an
expression tree to create a very close fit to the data.expression tree to create a very close fit to the data.
 By 'splicing' and 'grafting' the trees and evaluatingBy 'splicing' and 'grafting' the trees and evaluating
the resulting expression with the data and testing it tothe resulting expression with the data and testing it to
the answers, the fitness function can return how closethe answers, the fitness function can return how close
the expression is.the expression is.
Genetic ProgrammingGenetic Programming
 The limitations of genetic programming lie inThe limitations of genetic programming lie in
thethe hugehuge search space the GAs have to searchsearch space the GAs have to search
for - an infinite number of equations.for - an infinite number of equations.
 Therefore, normally before running a GA toTherefore, normally before running a GA to
search for an equation, the user tells thesearch for an equation, the user tells the
program which operators and numerical rangesprogram which operators and numerical ranges
to search under.to search under.
 Uses of genetic programming can lie in stockUses of genetic programming can lie in stock
market prediction, advanced mathematics andmarket prediction, advanced mathematics and
military applications .military applications .
Evolving Neural NetworksEvolving Neural Networks
 Evolving the architecture of neural network isEvolving the architecture of neural network is
slightly more complicated, and there haveslightly more complicated, and there have
been several ways of doing it. For small nets, abeen several ways of doing it. For small nets, a
simple matrix represents which neuronsimple matrix represents which neuron
connects which, and then this matrix is, inconnects which, and then this matrix is, in
turn, converted into the necessary 'genes', andturn, converted into the necessary 'genes', and
various combinations of these are evolved.various combinations of these are evolved.
Evolving Neural NetworksEvolving Neural Networks
 Many would think that a learning function could beMany would think that a learning function could be
evolved via genetic programming. Unfortunately,evolved via genetic programming. Unfortunately,
genetic programming combined with neural networksgenetic programming combined with neural networks
could becould be incrediblyincredibly slow, thus impractical.slow, thus impractical.
 As with many problems, you have to constrain whatAs with many problems, you have to constrain what
you are attempting to create.you are attempting to create.
 For example, in 1990, David Chalmers attempted toFor example, in 1990, David Chalmers attempted to
evolve a function as good as the delta rule.evolve a function as good as the delta rule.
 He did this by creating a general equation based uponHe did this by creating a general equation based upon
the delta rule with 8 unknowns, which the geneticthe delta rule with 8 unknowns, which the genetic
algorithm then evolved.algorithm then evolved.
Other AreasOther Areas
 Genetic Algorithms can be applied to virtually any problemGenetic Algorithms can be applied to virtually any problem
that has a large search space.that has a large search space.
 Al Biles uses genetic algorithms to filter out 'good' and 'bad'Al Biles uses genetic algorithms to filter out 'good' and 'bad'
riffs for jazz improvisation.riffs for jazz improvisation.
 The military uses GAs to evolve equations to differentiateThe military uses GAs to evolve equations to differentiate
between different radar returns.between different radar returns.
 Stock companies use GA-powered programs to predict theStock companies use GA-powered programs to predict the
stock market.stock market.
ExampleExample
 f(x) = {MAX(xf(x) = {MAX(x22
): 0 <= x <= 32 }): 0 <= x <= 32 }
 Encode Solution: Just use 5 bits (1 or 0).Encode Solution: Just use 5 bits (1 or 0).
 Generate initial population.Generate initial population.
 Evaluate each solution against objective.Evaluate each solution against objective.
Sol.Sol. StringString FitnessFitness % of Total% of Total
AA 0110101101 169169 14.414.4
BB 1100011000 576576 49.249.2
CC 0100001000 6464 5.55.5
DD 1001110011 361361 30.930.9
AA 00 11 11 00 11
BB 11 11 00 00 00
CC 00 11 00 00 00
DD 11 00 00 11 11
Example Cont’dExample Cont’d
 Create next generation of solutionsCreate next generation of solutions
 Probability of “being a parent” depends on the fitness.Probability of “being a parent” depends on the fitness.
 Ways for parents to create next generationWays for parents to create next generation
 ReproductionReproduction
 Use a string again unmodified.Use a string again unmodified.
 CrossoverCrossover
 Cut and paste portions of one string to another.Cut and paste portions of one string to another.
 MutationMutation
 Randomly flip a bit.Randomly flip a bit.
 COMBINATION of all of the above.COMBINATION of all of the above.
Checkboard example
 We are given an n by n checkboard in which every field
can have a different colour from a set of four colors.
 Goal is to achieve a checkboard in a way that there are no
neighbours with the same color (not diagonal)
1 2 3 4 5 6 7 8 9 10
1
2
3
4
5
6
7
8
9
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:
0 100 200 300 400 500
130
140
150
160
170
180
Fitness
Lower-Triangular Crossing Over
0 200 400 600 800
130
140
150
160
170
180
Square Crossing Over
0 200 400 600 800
130
140
150
160
170
180
Generations
Fitness
Horizontal Cutting Crossing Over
0 500 1000 1500
130
140
150
160
170
180
Generations
Verical Cutting Crossing Over
QuestionsQuestions
????
THANK YOUTHANK YOU

More Related Content

What's hot

Genetic Algorithms - Artificial Intelligence
Genetic Algorithms - Artificial IntelligenceGenetic Algorithms - Artificial Intelligence
Genetic Algorithms - Artificial IntelligenceSahil Kumar
 
Genetic Algorithms
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithmsadil raja
 
Genetic algorithms
Genetic algorithmsGenetic algorithms
Genetic algorithmszamakhan
 
Genetic Algorithm by Example
Genetic Algorithm by ExampleGenetic Algorithm by Example
Genetic Algorithm by ExampleNobal Niraula
 
Genetic programming
Genetic programmingGenetic programming
Genetic programmingMeghna Singh
 
Genetic_Algorithm_AI(TU)
Genetic_Algorithm_AI(TU)Genetic_Algorithm_AI(TU)
Genetic_Algorithm_AI(TU)Kapil Khatiwada
 
Genetic algorithm raktim
Genetic algorithm raktimGenetic algorithm raktim
Genetic algorithm raktimRaktim Halder
 
Introduction to Genetic Algorithms and Evolutionary Computation
Introduction to Genetic Algorithms and Evolutionary ComputationIntroduction to Genetic Algorithms and Evolutionary Computation
Introduction to Genetic Algorithms and Evolutionary ComputationAleksander Stensby
 
F043046054
F043046054F043046054
F043046054inventy
 
Genetic algorithm ppt
Genetic algorithm pptGenetic algorithm ppt
Genetic algorithm pptMayank Jain
 
Introduction to Genetic Algorithms
Introduction to Genetic AlgorithmsIntroduction to Genetic Algorithms
Introduction to Genetic AlgorithmsAhmed Othman
 
Genetic Algorithms
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithmsanas_elf
 
Genetic Algorithm
Genetic AlgorithmGenetic Algorithm
Genetic AlgorithmSHIMI S L
 
Survival of the Fittest: Using Genetic Algorithm for Data Mining Optimization
Survival of the Fittest: Using Genetic Algorithm for Data Mining OptimizationSurvival of the Fittest: Using Genetic Algorithm for Data Mining Optimization
Survival of the Fittest: Using Genetic Algorithm for Data Mining OptimizationOr Levi
 

What's hot (19)

Introduction to Genetic Algorithms
Introduction to Genetic AlgorithmsIntroduction to Genetic Algorithms
Introduction to Genetic Algorithms
 
Genetic Algorithms - Artificial Intelligence
Genetic Algorithms - Artificial IntelligenceGenetic Algorithms - Artificial Intelligence
Genetic Algorithms - Artificial Intelligence
 
Genetic Algorithms
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithms
 
Genetic Algorithms
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithms
 
Genetic algorithms
Genetic algorithmsGenetic algorithms
Genetic algorithms
 
Genetic Algorithms
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithms
 
Genetic Algorithm by Example
Genetic Algorithm by ExampleGenetic Algorithm by Example
Genetic Algorithm by Example
 
Genetic programming
Genetic programmingGenetic programming
Genetic programming
 
Genetic_Algorithm_AI(TU)
Genetic_Algorithm_AI(TU)Genetic_Algorithm_AI(TU)
Genetic_Algorithm_AI(TU)
 
Genetic algorithm raktim
Genetic algorithm raktimGenetic algorithm raktim
Genetic algorithm raktim
 
Introduction to Genetic Algorithms and Evolutionary Computation
Introduction to Genetic Algorithms and Evolutionary ComputationIntroduction to Genetic Algorithms and Evolutionary Computation
Introduction to Genetic Algorithms and Evolutionary Computation
 
Genetic Algorithm
Genetic AlgorithmGenetic Algorithm
Genetic Algorithm
 
F043046054
F043046054F043046054
F043046054
 
Genetic algorithm ppt
Genetic algorithm pptGenetic algorithm ppt
Genetic algorithm ppt
 
Genetic Algorithm
Genetic AlgorithmGenetic Algorithm
Genetic Algorithm
 
Introduction to Genetic Algorithms
Introduction to Genetic AlgorithmsIntroduction to Genetic Algorithms
Introduction to Genetic Algorithms
 
Genetic Algorithms
Genetic AlgorithmsGenetic Algorithms
Genetic Algorithms
 
Genetic Algorithm
Genetic AlgorithmGenetic Algorithm
Genetic Algorithm
 
Survival of the Fittest: Using Genetic Algorithm for Data Mining Optimization
Survival of the Fittest: Using Genetic Algorithm for Data Mining OptimizationSurvival of the Fittest: Using Genetic Algorithm for Data Mining Optimization
Survival of the Fittest: Using Genetic Algorithm for Data Mining Optimization
 

Similar to Genetic algorithms

Genetic-Algorithms.ppt
Genetic-Algorithms.pptGenetic-Algorithms.ppt
Genetic-Algorithms.pptNipun85
 
AI_PPT_Genetic-Algorithms.ppt
AI_PPT_Genetic-Algorithms.pptAI_PPT_Genetic-Algorithms.ppt
AI_PPT_Genetic-Algorithms.pptHotTea
 
Genetic-Algorithms-computersciencepptnew.ppt
Genetic-Algorithms-computersciencepptnew.pptGenetic-Algorithms-computersciencepptnew.ppt
Genetic-Algorithms-computersciencepptnew.pptFitnessfreaksfam
 
Genetic-Algorithms forv artificial .ppt
Genetic-Algorithms forv artificial  .pptGenetic-Algorithms forv artificial  .ppt
Genetic-Algorithms forv artificial .pptneelamsanjeevkumar
 
Genetic-Algorithms for machine learning and ai.ppt
Genetic-Algorithms for machine learning and ai.pptGenetic-Algorithms for machine learning and ai.ppt
Genetic-Algorithms for machine learning and ai.pptneelamsanjeevkumar
 
Genetic-Algorithms.ppt
Genetic-Algorithms.pptGenetic-Algorithms.ppt
Genetic-Algorithms.pptssuser2e437f
 
4.Genetic-Algorithms.ppt
4.Genetic-Algorithms.ppt4.Genetic-Algorithms.ppt
4.Genetic-Algorithms.pptRamjiChaurasiya
 
Data Science - Part XIV - Genetic Algorithms
Data Science - Part XIV - Genetic AlgorithmsData Science - Part XIV - Genetic Algorithms
Data Science - Part XIV - Genetic AlgorithmsDerek Kane
 
A Review On Genetic Algorithm And Its Applications
A Review On Genetic Algorithm And Its ApplicationsA Review On Genetic Algorithm And Its Applications
A Review On Genetic Algorithm And Its ApplicationsKaren Gomez
 
F043046054
F043046054F043046054
F043046054inventy
 
F043046054
F043046054F043046054
F043046054inventy
 
Swarm assignment 1
Swarm assignment 1Swarm assignment 1
Swarm assignment 1OmKushwaha7
 
Explanation and example of genetic algorithm
Explanation and example of genetic algorithmExplanation and example of genetic algorithm
Explanation and example of genetic algorithmMarkKhan23
 
A Genetic Algorithm Problem Solver For Archaeology
A Genetic Algorithm Problem Solver For ArchaeologyA Genetic Algorithm Problem Solver For Archaeology
A Genetic Algorithm Problem Solver For ArchaeologyAmy Cernava
 
Parallel evolutionary approach paper
Parallel evolutionary approach paperParallel evolutionary approach paper
Parallel evolutionary approach paperPriti Punia
 
generic optimization techniques lecture slides
generic optimization techniques  lecture slidesgeneric optimization techniques  lecture slides
generic optimization techniques lecture slidesSardarHamidullah
 
Genetic Algorithm 2 -.pptx
Genetic Algorithm 2 -.pptxGenetic Algorithm 2 -.pptx
Genetic Algorithm 2 -.pptxTAHANMKH
 
Info to Genetic Algorithms - DC Ruby Users Group 11.10.2016
Info to Genetic Algorithms - DC Ruby Users Group 11.10.2016Info to Genetic Algorithms - DC Ruby Users Group 11.10.2016
Info to Genetic Algorithms - DC Ruby Users Group 11.10.2016Geoff Harcourt
 

Similar to Genetic algorithms (20)

Genetic algorithms
Genetic algorithms Genetic algorithms
Genetic algorithms
 
Genetic-Algorithms.ppt
Genetic-Algorithms.pptGenetic-Algorithms.ppt
Genetic-Algorithms.ppt
 
AI_PPT_Genetic-Algorithms.ppt
AI_PPT_Genetic-Algorithms.pptAI_PPT_Genetic-Algorithms.ppt
AI_PPT_Genetic-Algorithms.ppt
 
Genetic-Algorithms-computersciencepptnew.ppt
Genetic-Algorithms-computersciencepptnew.pptGenetic-Algorithms-computersciencepptnew.ppt
Genetic-Algorithms-computersciencepptnew.ppt
 
Genetic-Algorithms forv artificial .ppt
Genetic-Algorithms forv artificial  .pptGenetic-Algorithms forv artificial  .ppt
Genetic-Algorithms forv artificial .ppt
 
Genetic-Algorithms for machine learning and ai.ppt
Genetic-Algorithms for machine learning and ai.pptGenetic-Algorithms for machine learning and ai.ppt
Genetic-Algorithms for machine learning and ai.ppt
 
Genetic-Algorithms.ppt
Genetic-Algorithms.pptGenetic-Algorithms.ppt
Genetic-Algorithms.ppt
 
4.Genetic-Algorithms.ppt
4.Genetic-Algorithms.ppt4.Genetic-Algorithms.ppt
4.Genetic-Algorithms.ppt
 
Data Science - Part XIV - Genetic Algorithms
Data Science - Part XIV - Genetic AlgorithmsData Science - Part XIV - Genetic Algorithms
Data Science - Part XIV - Genetic Algorithms
 
A Review On Genetic Algorithm And Its Applications
A Review On Genetic Algorithm And Its ApplicationsA Review On Genetic Algorithm And Its Applications
A Review On Genetic Algorithm And Its Applications
 
F043046054
F043046054F043046054
F043046054
 
F043046054
F043046054F043046054
F043046054
 
Swarm assignment 1
Swarm assignment 1Swarm assignment 1
Swarm assignment 1
 
Explanation and example of genetic algorithm
Explanation and example of genetic algorithmExplanation and example of genetic algorithm
Explanation and example of genetic algorithm
 
Genetic algorithms
Genetic algorithmsGenetic algorithms
Genetic algorithms
 
A Genetic Algorithm Problem Solver For Archaeology
A Genetic Algorithm Problem Solver For ArchaeologyA Genetic Algorithm Problem Solver For Archaeology
A Genetic Algorithm Problem Solver For Archaeology
 
Parallel evolutionary approach paper
Parallel evolutionary approach paperParallel evolutionary approach paper
Parallel evolutionary approach paper
 
generic optimization techniques lecture slides
generic optimization techniques  lecture slidesgeneric optimization techniques  lecture slides
generic optimization techniques lecture slides
 
Genetic Algorithm 2 -.pptx
Genetic Algorithm 2 -.pptxGenetic Algorithm 2 -.pptx
Genetic Algorithm 2 -.pptx
 
Info to Genetic Algorithms - DC Ruby Users Group 11.10.2016
Info to Genetic Algorithms - DC Ruby Users Group 11.10.2016Info to Genetic Algorithms - DC Ruby Users Group 11.10.2016
Info to Genetic Algorithms - DC Ruby Users Group 11.10.2016
 

Recently uploaded

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

Genetic algorithms

  • 2. IntroductionIntroduction  After scientists became disillusioned withAfter scientists became disillusioned with classical and neo-classical attempts atclassical and neo-classical attempts at modeling intelligence, they looked in othermodeling intelligence, they looked in other directions.directions.  Two prominent fields arose, connectionismTwo prominent fields arose, connectionism (neural networking, parallel processing) and(neural networking, parallel processing) and evolutionary computing.evolutionary computing.  It is the latter that this essay deals with -It is the latter that this essay deals with - genetic algorithms and genetic programming.genetic algorithms and genetic programming.
  • 3. What is GAWhat is GA  AA genetic algorithmgenetic algorithm (or(or GAGA) is a search technique) is a search technique used in computing to find true or approximateused in computing to find true or approximate solutions to optimization and search problems.solutions to optimization and search problems.  Genetic algorithms are categorized as global searchGenetic algorithms are categorized as global search heuristics.heuristics.  Genetic algorithms are a particular class ofGenetic algorithms are a particular class of evolutionary algorithms that use techniques inspiredevolutionary algorithms that use techniques inspired by evolutionary biology such as inheritance,by evolutionary biology such as inheritance, mutation, selection, and crossover (also calledmutation, selection, and crossover (also called recombination).recombination).
  • 4. What is GAWhat is GA  Genetic algorithms are implemented as a computerGenetic algorithms are implemented as a computer simulation in which a population of abstractsimulation in which a population of abstract representations (called chromosomes or the genotyperepresentations (called chromosomes or the genotype or the genome) of candidate solutions (calledor the genome) of candidate solutions (called individuals, creatures, or phenotypes) to anindividuals, creatures, or phenotypes) to an optimization problem evolves toward better solutions.optimization problem evolves toward better solutions.  Traditionally, solutions are represented in binary asTraditionally, solutions are represented in binary as strings of 0s and 1s, but other encodings are alsostrings of 0s and 1s, but other encodings are also possible.possible.
  • 5. What is GAWhat is GA  The evolution usually starts from a population ofThe evolution usually starts from a population of randomly generated individuals and happens inrandomly generated individuals and happens in generations.generations.  In each generation, the fitness of every individual inIn each generation, the fitness of every individual in the population is evaluated, multiple individuals arethe population is evaluated, multiple individuals are selected from the current population (based on theirselected from the current population (based on their fitness), and modified (recombined and possiblyfitness), and modified (recombined and possibly mutated) to form a new population.mutated) to form a new population.
  • 6. What is GAWhat is GA  The new population is then used in the nextThe new population is then used in the next iteration of the algorithm.iteration of the algorithm.  Commonly, the algorithm terminates whenCommonly, the algorithm terminates when either a maximum number of generations haseither a maximum number of generations has been produced, or a satisfactory fitness levelbeen produced, or a satisfactory fitness level has been reached for the population.has been reached for the population.  If the algorithm has terminated due to aIf the algorithm has terminated due to a maximum number of generations, amaximum number of generations, a satisfactory solution may or may not havesatisfactory solution may or may not have been reached.been reached.
  • 7. Key termsKey terms  IndividualIndividual - Any possible solution- Any possible solution  PopulationPopulation - Group of all- Group of all individualsindividuals  Search SpaceSearch Space - All possible solutions to the problem- All possible solutions to the problem  ChromosomeChromosome - Blueprint for an- Blueprint for an individualindividual  TraitTrait - Possible aspect (- Possible aspect (features)features) of anof an individualindividual  Allele -- Possible settings of trait (black, blond, etc.)  LocusLocus - The position of a- The position of a genegene on theon the chromosomechromosome  GenomeGenome - Collection of all- Collection of all chromosomeschromosomes for anfor an individualindividual
  • 9. Genotype and Phenotype  Genotype: – Particular set of genes in a genome  Phenotype: – Physical characteristic of the genotype (smart, beautiful, healthy, etc.)
  • 11. GA RequirementsGA Requirements  A typical genetic algorithm requires two things to be defined:A typical genetic algorithm requires two things to be defined:  a genetic representation of the solution domain, anda genetic representation of the solution domain, and  a fitness function to evaluate the solution domain.a fitness function to evaluate the solution domain.  A standard representation of the solution is as an array of bits.A standard representation of the solution is as an array of bits. Arrays of other types and structures can be used in essentiallyArrays of other types and structures can be used in essentially the same way.the same way.  The main property that makes these genetic representationsThe main property that makes these genetic representations convenient is that their parts are easily aligned due to theirconvenient is that their parts are easily aligned due to their fixed size, that facilitates simple crossover operation.fixed size, that facilitates simple crossover operation.  Variable length representations may also be used, butVariable length representations may also be used, but crossover implementation is more complex in this case.crossover implementation is more complex in this case.  Tree-like representations are explored in GeneticTree-like representations are explored in Genetic programming.programming.
  • 12. RepresentationRepresentation Chromosomes could be:Chromosomes could be:  Bit strings (0101 ... 1100)Bit strings (0101 ... 1100)  Real numbers (43.2 -33.1 ... 0.0 89.2)Real numbers (43.2 -33.1 ... 0.0 89.2)  Permutations of element (E11 E3 E7 ... E1 E15)Permutations of element (E11 E3 E7 ... E1 E15)  Lists of rules (R1 R2 R3 ... R22 R23)Lists of rules (R1 R2 R3 ... R22 R23)  Program elements (genetic programming)Program elements (genetic programming)  ... any data structure ...... any data structure ...
  • 13. GA RequirementsGA Requirements  The fitness function is defined over the genetic representationThe fitness function is defined over the genetic representation and measures theand measures the qualityquality of the represented solution.of the represented solution.  The fitness function is always problem dependent.The fitness function is always problem dependent.  For instance, in theFor instance, in the knapsack problemknapsack problem we want to maximizewe want to maximize the total value of objects that we can put in a knapsack ofthe total value of objects that we can put in a knapsack of some fixed capacity.some fixed capacity.  A representation of a solution might be an array of bits, whereA representation of a solution might be an array of bits, where each bit represents a different object, and the value of the biteach bit represents a different object, and the value of the bit (0 or 1) represents whether or not the object is in the knapsack.(0 or 1) represents whether or not the object is in the knapsack.  Not every such representation is valid, as the size of objectsNot every such representation is valid, as the size of objects may exceed the capacity of the knapsack.may exceed the capacity of the knapsack.  TheThe fitnessfitness of the solution is the sum of values of all objects inof the solution is the sum of values of all objects in the knapsack if the representation is valid, or 0 otherwise. Inthe knapsack if the representation is valid, or 0 otherwise. In some problems, it is hard or even impossible to define thesome problems, it is hard or even impossible to define the fitness expression; in these cases, interactive geneticfitness expression; in these cases, interactive genetic algorithms are used.algorithms are used.
  • 14. A fitness functionA fitness function
  • 15. Basics of GABasics of GA  The most common type of genetic algorithm works like this:The most common type of genetic algorithm works like this:  a population is created with a group of individuals createda population is created with a group of individuals created randomly.randomly.  The individuals in the population are then evaluated.The individuals in the population are then evaluated.  The evaluation function is provided by the programmer andThe evaluation function is provided by the programmer and gives the individuals a score based on how well they performgives the individuals a score based on how well they perform at the given task.at the given task.  Two individuals are then selected based on their fitness, theTwo individuals are then selected based on their fitness, the higher the fitness, the higher the chance of being selected.higher the fitness, the higher the chance of being selected.  These individuals then "reproduce" to create one or moreThese individuals then "reproduce" to create one or more offspring, after which the offspring are mutated randomly.offspring, after which the offspring are mutated randomly.  This continues until a suitable solution has been found or aThis continues until a suitable solution has been found or a certain number of generations have passed, depending on thecertain number of generations have passed, depending on the needs of the programmer.needs of the programmer.
  • 16. General Algorithm for GAGeneral Algorithm for GA  InitializationInitialization  Initially many individual solutions are randomlyInitially many individual solutions are randomly generated to form an initial population. Thegenerated to form an initial population. The population size depends on the nature of the problem,population size depends on the nature of the problem, but typically contains several hundreds or thousandsbut typically contains several hundreds or thousands of possible solutions.of possible solutions.  Traditionally, the population is generated randomly,Traditionally, the population is generated randomly, covering the entire range of possible solutions (thecovering the entire range of possible solutions (the search spacesearch space).).  Occasionally, the solutions may be "seeded" in areasOccasionally, the solutions may be "seeded" in areas where optimal solutions are likely to be found.where optimal solutions are likely to be found.
  • 17. General Algorithm for GAGeneral Algorithm for GA  SelectionSelection  During each successive generation, a proportion of the existingDuring each successive generation, a proportion of the existing population is selected to breed a new generation.population is selected to breed a new generation.  Individual solutions are selected through aIndividual solutions are selected through a fitness-basedfitness-based process, where fitter solutions (as measured by a fitnessprocess, where fitter solutions (as measured by a fitness function) are typically more likely to be selected.function) are typically more likely to be selected.  Certain selection methods rate the fitness of each solution andCertain selection methods rate the fitness of each solution and preferentially select the best solutions. Other methods ratepreferentially select the best solutions. Other methods rate only a random sample of the population, as this process mayonly a random sample of the population, as this process may be very time-consuming.be very time-consuming.  Most functions are stochastic and designed so that a smallMost functions are stochastic and designed so that a small proportion of less fit solutions are selected. This helps keepproportion of less fit solutions are selected. This helps keep the diversity of the population large, preventing prematurethe diversity of the population large, preventing premature convergence on poor solutions. Popular and well-studiedconvergence on poor solutions. Popular and well-studied selection methods include roulette wheel selection andselection methods include roulette wheel selection and tournament selection.tournament selection.
  • 18. General Algorithm for GAGeneral Algorithm for GA  In roulette wheel selection, individuals areIn roulette wheel selection, individuals are given a probability of being selected that isgiven a probability of being selected that is directly proportionate to their fitness.directly proportionate to their fitness.  Two individuals are then chosen randomlyTwo individuals are then chosen randomly based on these probabilities and producebased on these probabilities and produce offspring.offspring.
  • 19. General Algorithm for GAGeneral Algorithm for GA Roulette Wheel’s Selection Pseudo Code:Roulette Wheel’s Selection Pseudo Code: for all members of populationfor all members of population sum += fitness of this individualsum += fitness of this individual end forend for for all members of populationfor all members of population probability = sum of probabilities + (fitness / sum)probability = sum of probabilities + (fitness / sum) sum of probabilities += probabilitysum of probabilities += probability end forend for loop until new population is fullloop until new population is full do this twicedo this twice number = Random between 0 and 1number = Random between 0 and 1 for all members of populationfor all members of population if number > probability but less than next probability thenif number > probability but less than next probability then you have been selectedyou have been selected end forend for endend create offspringcreate offspring end loopend loop
  • 20. General Algorithm for GAGeneral Algorithm for GA  ReproductionReproduction  The next step is to generate a second generation population ofThe next step is to generate a second generation population of solutions from those selected through genetic operators:solutions from those selected through genetic operators: crossover (also called recombination), and/or mutation.crossover (also called recombination), and/or mutation.  For each new solution to be produced, a pair of "parent"For each new solution to be produced, a pair of "parent" solutions is selected for breeding from the pool selectedsolutions is selected for breeding from the pool selected previously.previously.  By producing a "child" solution using the above methods ofBy producing a "child" solution using the above methods of crossover and mutation, a new solution is created whichcrossover and mutation, a new solution is created which typically shares many of the characteristics of its "parents".typically shares many of the characteristics of its "parents". New parents are selected for each child, and the processNew parents are selected for each child, and the process continues until a new population of solutions of appropriatecontinues until a new population of solutions of appropriate size is generated.size is generated.
  • 21. General Algorithm for GAGeneral Algorithm for GA  These processes ultimately result in the nextThese processes ultimately result in the next generation population of chromosomes that isgeneration population of chromosomes that is different from the initial generation.different from the initial generation.  Generally the average fitness will haveGenerally the average fitness will have increased by this procedure for the population,increased by this procedure for the population, since only the best organisms from the firstsince only the best organisms from the first generation are selected for breeding, alonggeneration are selected for breeding, along with a small proportion of less fit solutions, forwith a small proportion of less fit solutions, for reasons already mentioned above.reasons already mentioned above.
  • 22. CrossoverCrossover  the most common type is single point crossover. In singlethe most common type is single point crossover. In single point crossover, you choose a locus at which you swap thepoint crossover, you choose a locus at which you swap the remaining alleles from on parent to the other. This is complexremaining alleles from on parent to the other. This is complex and is best understood visually.and is best understood visually.  As you can see, the children take one section of theAs you can see, the children take one section of the chromosome from each parent.chromosome from each parent.  The point at which the chromosome is broken depends on theThe point at which the chromosome is broken depends on the randomly selected crossover point.randomly selected crossover point.  This particular method is called single point crossover becauseThis particular method is called single point crossover because only one crossover point exists. Sometimes only child 1 oronly one crossover point exists. Sometimes only child 1 or child 2 is created, but oftentimes both offspring are createdchild 2 is created, but oftentimes both offspring are created and put into the new population.and put into the new population.  Crossover does not always occur, however. Sometimes, basedCrossover does not always occur, however. Sometimes, based on a set probability, no crossover occurs and the parents areon a set probability, no crossover occurs and the parents are copied directly to the new population. The probability ofcopied directly to the new population. The probability of crossover occurring is usually 60% to 70%.crossover occurring is usually 60% to 70%.
  • 24. MutationMutation  After selection and crossover, you now have a new populationAfter selection and crossover, you now have a new population full of individuals.full of individuals.  Some are directly copied, and others are produced bySome are directly copied, and others are produced by crossover.crossover.  In order to ensure that the individuals are not all exactly theIn order to ensure that the individuals are not all exactly the same, you allow for a small chance of mutation.same, you allow for a small chance of mutation.  You loop through all the alleles of all the individuals, and ifYou loop through all the alleles of all the individuals, and if that allele is selected for mutation, you can either change it bythat allele is selected for mutation, you can either change it by a small amount or replace it with a new value. The probabilitya small amount or replace it with a new value. The probability of mutation is usually between 1 and 2 tenths of a percent.of mutation is usually between 1 and 2 tenths of a percent.  Mutation is fairly simple. You just change the selected allelesMutation is fairly simple. You just change the selected alleles based on what you feel is necessary and move on. Mutation is,based on what you feel is necessary and move on. Mutation is, however, vital to ensuring genetic diversity within thehowever, vital to ensuring genetic diversity within the population.population.
  • 26. General Algorithm for GAGeneral Algorithm for GA  TerminationTermination  This generational process is repeated until aThis generational process is repeated until a termination condition has been reached.termination condition has been reached.  Common terminating conditions are:Common terminating conditions are:  A solution is found that satisfies minimum criteriaA solution is found that satisfies minimum criteria  Fixed number of generations reachedFixed number of generations reached  Allocated budget (computation time/money) reachedAllocated budget (computation time/money) reached  The highest ranking solution's fitness is reaching or hasThe highest ranking solution's fitness is reaching or has reached a plateau such that successive iterations no longerreached a plateau such that successive iterations no longer produce better resultsproduce better results  Manual inspectionManual inspection  Any Combinations of the aboveAny Combinations of the above
  • 27. GA Pseudo-codeGA Pseudo-code Choose initial populationChoose initial population Evaluate the fitness of each individual in the populationEvaluate the fitness of each individual in the population RepeatRepeat Select best-ranking individuals to reproduceSelect best-ranking individuals to reproduce Breed new generation through crossover and mutation (geneticBreed new generation through crossover and mutation (genetic operations) and give birth to offspringoperations) and give birth to offspring Evaluate the individual fitnesses of the offspringEvaluate the individual fitnesses of the offspring Replace worst ranked part of population with offspringReplace worst ranked part of population with offspring Until <terminating condition>Until <terminating condition>
  • 28. Symbolic AI VS. GeneticSymbolic AI VS. Genetic AlgorithmsAlgorithms  Most symbolic AI systems are very static.Most symbolic AI systems are very static.  Most of them can usually only solve one givenMost of them can usually only solve one given specific problem, since their architecture wasspecific problem, since their architecture was designed for whatever that specific problem was indesigned for whatever that specific problem was in the first place.the first place.  Thus, if the given problem were somehow to beThus, if the given problem were somehow to be changed, these systems could have a hard timechanged, these systems could have a hard time adapting to them, since the algorithm that wouldadapting to them, since the algorithm that would originally arrive to the solution may be eitheroriginally arrive to the solution may be either incorrect or less efficient.incorrect or less efficient.  Genetic algorithms (or GA) were created to combatGenetic algorithms (or GA) were created to combat these problems; they are basically algorithms basedthese problems; they are basically algorithms based on natural biological evolution.on natural biological evolution.
  • 29. Symbolic AI VS. GeneticSymbolic AI VS. Genetic AlgorithmsAlgorithms  The architecture of systems that implement genetic algorithmsThe architecture of systems that implement genetic algorithms (or GA) are more able to adapt to a wide range of problems.(or GA) are more able to adapt to a wide range of problems.  A GA functions by generating a large set of possible solutionsA GA functions by generating a large set of possible solutions to a given problem.to a given problem.  It then evaluates each of those solutions, and decides on aIt then evaluates each of those solutions, and decides on a "fitness level" (you may recall the phrase: "survival of the"fitness level" (you may recall the phrase: "survival of the fittest") for each solution set.fittest") for each solution set.  These solutions then breed new solutions.These solutions then breed new solutions.  The parent solutions that were more "fit" are more likely toThe parent solutions that were more "fit" are more likely to reproduce, while those that were less "fit" are more unlikely toreproduce, while those that were less "fit" are more unlikely to do so.do so.  In essence, solutions are evolved over time. This way youIn essence, solutions are evolved over time. This way you evolve your search space scope to a point where you can findevolve your search space scope to a point where you can find the solution.the solution.  Genetic algorithms can be incredibly efficient if programmedGenetic algorithms can be incredibly efficient if programmed correctly.correctly.
  • 30. Genetic ProgrammingGenetic Programming  In programming languages such as LISP, the mathematicalIn programming languages such as LISP, the mathematical notation is not written in standard notation, but in prefixnotation is not written in standard notation, but in prefix notation. Some examples of this:notation. Some examples of this:  + 2 1+ 2 1 :: 2 + 12 + 1  * + 2 1 2* + 2 1 2 :: 2 * (2+1)2 * (2+1)  * + - 2 1 4 9 :* + - 2 1 4 9 : 9 * ((2 - 1) + 4)9 * ((2 - 1) + 4)  Notice the difference between the left-hand side to the right?Notice the difference between the left-hand side to the right? Apart from the order being different, no parenthesis! TheApart from the order being different, no parenthesis! The prefix method makes it a lot easier for programmers andprefix method makes it a lot easier for programmers and compilers alike, because order precedence is not an issue.compilers alike, because order precedence is not an issue.  You can build expression trees out of these strings that thenYou can build expression trees out of these strings that then can be easily evaluated, for example, here are the trees for thecan be easily evaluated, for example, here are the trees for the above three expressions.above three expressions.
  • 32. Genetic ProgrammingGenetic Programming  You can see how expression evaluation is thus a lotYou can see how expression evaluation is thus a lot easier.easier.  What this have to do with GAs? If for example youWhat this have to do with GAs? If for example you have numerical data and 'answers', but no expressionhave numerical data and 'answers', but no expression to conjoin the data with the answers.to conjoin the data with the answers.  A genetic algorithm can be used to 'evolve' anA genetic algorithm can be used to 'evolve' an expression tree to create a very close fit to the data.expression tree to create a very close fit to the data.  By 'splicing' and 'grafting' the trees and evaluatingBy 'splicing' and 'grafting' the trees and evaluating the resulting expression with the data and testing it tothe resulting expression with the data and testing it to the answers, the fitness function can return how closethe answers, the fitness function can return how close the expression is.the expression is.
  • 33. Genetic ProgrammingGenetic Programming  The limitations of genetic programming lie inThe limitations of genetic programming lie in thethe hugehuge search space the GAs have to searchsearch space the GAs have to search for - an infinite number of equations.for - an infinite number of equations.  Therefore, normally before running a GA toTherefore, normally before running a GA to search for an equation, the user tells thesearch for an equation, the user tells the program which operators and numerical rangesprogram which operators and numerical ranges to search under.to search under.  Uses of genetic programming can lie in stockUses of genetic programming can lie in stock market prediction, advanced mathematics andmarket prediction, advanced mathematics and military applications .military applications .
  • 34. Evolving Neural NetworksEvolving Neural Networks  Evolving the architecture of neural network isEvolving the architecture of neural network is slightly more complicated, and there haveslightly more complicated, and there have been several ways of doing it. For small nets, abeen several ways of doing it. For small nets, a simple matrix represents which neuronsimple matrix represents which neuron connects which, and then this matrix is, inconnects which, and then this matrix is, in turn, converted into the necessary 'genes', andturn, converted into the necessary 'genes', and various combinations of these are evolved.various combinations of these are evolved.
  • 35. Evolving Neural NetworksEvolving Neural Networks  Many would think that a learning function could beMany would think that a learning function could be evolved via genetic programming. Unfortunately,evolved via genetic programming. Unfortunately, genetic programming combined with neural networksgenetic programming combined with neural networks could becould be incrediblyincredibly slow, thus impractical.slow, thus impractical.  As with many problems, you have to constrain whatAs with many problems, you have to constrain what you are attempting to create.you are attempting to create.  For example, in 1990, David Chalmers attempted toFor example, in 1990, David Chalmers attempted to evolve a function as good as the delta rule.evolve a function as good as the delta rule.  He did this by creating a general equation based uponHe did this by creating a general equation based upon the delta rule with 8 unknowns, which the geneticthe delta rule with 8 unknowns, which the genetic algorithm then evolved.algorithm then evolved.
  • 36. Other AreasOther Areas  Genetic Algorithms can be applied to virtually any problemGenetic Algorithms can be applied to virtually any problem that has a large search space.that has a large search space.  Al Biles uses genetic algorithms to filter out 'good' and 'bad'Al Biles uses genetic algorithms to filter out 'good' and 'bad' riffs for jazz improvisation.riffs for jazz improvisation.  The military uses GAs to evolve equations to differentiateThe military uses GAs to evolve equations to differentiate between different radar returns.between different radar returns.  Stock companies use GA-powered programs to predict theStock companies use GA-powered programs to predict the stock market.stock market.
  • 37. ExampleExample  f(x) = {MAX(xf(x) = {MAX(x22 ): 0 <= x <= 32 }): 0 <= x <= 32 }  Encode Solution: Just use 5 bits (1 or 0).Encode Solution: Just use 5 bits (1 or 0).  Generate initial population.Generate initial population.  Evaluate each solution against objective.Evaluate each solution against objective. Sol.Sol. StringString FitnessFitness % of Total% of Total AA 0110101101 169169 14.414.4 BB 1100011000 576576 49.249.2 CC 0100001000 6464 5.55.5 DD 1001110011 361361 30.930.9 AA 00 11 11 00 11 BB 11 11 00 00 00 CC 00 11 00 00 00 DD 11 00 00 11 11
  • 38. Example Cont’dExample Cont’d  Create next generation of solutionsCreate next generation of solutions  Probability of “being a parent” depends on the fitness.Probability of “being a parent” depends on the fitness.  Ways for parents to create next generationWays for parents to create next generation  ReproductionReproduction  Use a string again unmodified.Use a string again unmodified.  CrossoverCrossover  Cut and paste portions of one string to another.Cut and paste portions of one string to another.  MutationMutation  Randomly flip a bit.Randomly flip a bit.  COMBINATION of all of the above.COMBINATION of all of the above.
  • 39. Checkboard example  We are given an n by n checkboard in which every field can have a different colour from a set of four colors.  Goal is to achieve a checkboard in a way that there are no neighbours with the same color (not diagonal) 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
  • 40. 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.
  • 41. 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
  • 42. Checkboard example Cont’d • Fitnesscurves for different cross-over rules: 0 100 200 300 400 500 130 140 150 160 170 180 Fitness Lower-Triangular Crossing Over 0 200 400 600 800 130 140 150 160 170 180 Square Crossing Over 0 200 400 600 800 130 140 150 160 170 180 Generations Fitness Horizontal Cutting Crossing Over 0 500 1000 1500 130 140 150 160 170 180 Generations Verical Cutting Crossing Over