Genetic Algorithms

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 43

Genetic Algorithms

Evolutionary Computation
 Computational procedures patterned after
biological evolution
 Search procedure that probabilistically applies
search operators to a set of points in the search
space
 Generate successor hypothesis by repeatedly
mutating and recombining parts of the best
currently known hypothesis
Genetic Algorithm… Overview
 A class of probabilistic optimization algorithms

 Inspired by the biological evolution process

 Uses concepts of “Natural Selection” and “Genetic


Inheritance” (Darwin 1859)

 Originally developed by John Holland (1975)

 Particularly well suited for hard problems where little is


known about the underlying search space

 Widely-used in business, science and engineering


Genetic Algorithm… Overview
Search Techniqes

Calculus Base Guided random search Enumerative


Techniqes techniqes Techniqes

Fibonacci Sort DFS Dynamic BFS


Programming

Tabu Search Hill Climbing Simulated Evolutionary


Anealing Algorithms

Genetic Genetic
Programming Algorithms
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.

 GA are categorized as global search heuristics.

 GA 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
 GA 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.

 Traditionally, solutions are represented in binary as


strings of 0s and 1s, but other encodings are also
possible.
The Metaphor

Genetic Algorithm Nature

Optimization problem Environment

Feasible solutions Individuals living in that


environment
Solutions quality (fitness Individual’s degree of
function) adaptation to its
surrounding environment
The Metaphor

Genetic Algorithm Nature

A set of feasible solutions A population of organisms


(species)
Stochastic operators Selection, recombination
and mutation in nature’s
evolutionary process
Iteratively applying a set Evolution of populations
of stochastic operators on to suit their environment
a set of feasible solutions
The Evolutionary Cycle
parents
selection modification
modified
offspring

initiate &
evaluate
population evaluation
evaluated offspring
deleted
members

discard
What is GA
 The evolution usually starts from a population of
randomly generated individuals and happens in
generations.

 In each generation, the fitness of every individual in the


population is evaluated, multiple individuals are
selected from the current population (based on their
fitness), and modified (recombined and possibly
mutated) to form a new population.
What is GA
 The new population is then used in the next
iteration of the algorithm.
 Commonly, the algorithm terminates when
either a maximum number of generations has
been produced, or a satisfactory fitness level has
been reached for the population.
 If the algorithm has terminated due to a
maximum number of generations, a satisfactory
solution may or may not have been reached.
Key terms
 Individual - Any possible solution
 Population - Group of all individuals
 Search Space - All possible solutions to the problem
 Chromosome - Blueprint for an individual
 Trait - Possible aspect (features) of an individual
 Allele - Possible settings of trait (black, blond, etc.)
 Locus - The position of a gene on the chromosome
 Genome - Collection of all chromosomes for an
individual
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 Requirements
 A typical Ga requires two things to be defined:
 a genetic representation of the solution domain, and
 a fitness function to evaluate the solution domain.

 A standard representation of the solution is as an array of bits.


Arrays of other types and structures can be used in essentially
the same way.
 The main property that makes these genetic representations
convenient is that their parts are easily aligned due to their fixed
size, that facilitates simple crossover operation.
 Variable length representations may also be used, but crossover
implementation is more complex in this case.
 Tree-like representations are explored in Genetic programming.
Representation
Chromosomes could be:
 Bit strings (0101 ... 1100)
 Real numbers (43.2 -33.1 ... 0.0 89.2)
 Permutations of element (E11 E3 E7 ... E1 E15)
 Lists of rules (R1 R2 R3 ... R22 R23)
 Program elements (genetic programming)
 ... any data structure ...
GA Requirements
 The fitness function is defined over the genetic representation and
measures the quality of the represented solution.
 The fitness function is always problem dependent.

 A representation of a solution might be an array of bits, where each

bit represents a different object, and the value of the bit (0 or 1)

represents whether or not the object is in the knapsack.


 Not every such representation is valid, as the size of objects may
exceed the capacity of the knapsack.
A fitness function
Basics of GA
 A population is created with a group of individuals created randomly.
 The individuals in the population are then evaluated.
 The evaluation function is provided by the programmer and gives the
individuals a score based on how well they perform at the given task.
 Two individuals are then selected based on their fitness, the higher the
fitness, the higher the chance of being selected.
 These individuals then "reproduce" to create one or more offspring,
after which the offspring are mutated randomly.
 This continues until a suitable solution has been found or a certain
number of generations have passed, depending on the needs of the
programmer.
General Algorithm for GA : Initialization
 Initially many individual solutions are randomly
generated to form an initial population. The population
size depends on the nature of the problem, but typically
contains several hundreds or thousands of possible
solutions.
 Traditionally, the population is generated randomly,
covering the entire range of possible solutions (the search
space).
 Occasionally, the solutions may be "seeded" in areas
where optimal solutions are likely to be found.
General Algorithm for GA : Selection
 The idea is to give preference to the individuals
with good fitness scores and allow them to pass
there genes to the successive generations.
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
 Crossover is applied as follows:
1) Select a random crossover point.

2) Break each chromosome into two parts, splitting at the


crossover point.

3) Recombine the broken chromosomes by combining the


front of one with the back of the other, and vice versa,
to produce two new chromosomes.
Crossover
Crossover
Other Types of Crossover
 Usually, crossover is applied with one crossover point,
but can be applied with more, such as in the following
case which has two crossover points:
Other Types of Crossover
 Uniform crossover involves using a probability to
select which genes to use from chromosome 1, and
which from chromosome 2.
Mutation
 A unary operator – applies to one chromosome.
 Randomly selects some bits (genes) to be
“flipped”
 1 => 0 and 0 =>1
 Mutation is usually applied with a low
probability, such as 1 in 1000.
Mutation
General Algorithm for GA : Termination
 This generational process is repeated until a termination
condition has been reached.
 Common terminating conditions are:
 A solution is found that satisfies minimum criteria
 Fixed number of generations reached
 Allocated budget (computation time/money) reached
 The highest ranking solution's fitness is reaching or has
reached a plateau such that successive iterations no longer
produce better results
 Manual inspection
 Any Combinations of the above
GA Pseudo-code
Choose initial population
Evaluate the fitness of each individual in the population
Repeat
Select best-ranking individuals to reproduce
Breed new generation through crossover and mutation
(genetic operations) and give birth to offspring
Evaluate the individual fitnesses of the offspring
Replace worst ranked part of population with offspring
Until <terminating condition>
GA Pseudo-code : The Parameters
GA(Fitness, Fitness_threshold, p, r, m)

 Fitness - function evaluates how good a hypothesis is

 Fitness_threshold - minimum acceptable hypothesis

 p - size of the population

 r - fraction of population to be replaced

 m - mutation rate
GA Pseudo-code : The Parameters
GA(Fitness, Fitness_threshold, p, r, m)
 Initialize: P ← p random hypotheses
 Evaluate: for each h in P, compute Fitness(h)
 While [maxh Fitness(h)] < Fitness_threshold
1. Select: Select (1 – r) members of P to add to PS based on fitness
2. Crossover: Probabilistically select pairs of hypotheses from P. For
each pair, <h1, h2>, produce two offspring by applying the Crossover
operator. Add all offspring to PS
3. Mutate: Invert a randomly selected bit in m · p random members of PS
4. Update: P ← PS
5. Evaluate: for each h in P, compute Fitness(h)

 Return the hypothesis from P that has the highest fitness


Fitness
 Fitness is an important concept in genetic algorithms.

 The fitness of a chromosome determines how likely it is


that it will reproduce.

 Fitness is usually measured in terms of how well the


chromosome solves some goal problem.
 E.g., if the genetic algorithm is to be used to sort numbers, then
the fitness of a chromosome will be determined by how close to
a correct sorting it produces.

 Fitness can also be subjective (aesthetic)


Symbolic AI VS. Genetic Algorithms
 Most symbolic AI systems are very static.

 Most of them can usually only solve one given specific problem,
since their architecture was designed for whatever that specific
problem was in the first place.

 Thus, if the given problem were somehow to be changed, these


systems could have a hard time adapting to them, since the
algorithm that would originally arrive to the solution may be
either incorrect or less efficient.

 Genetic algorithms (or GA) were created to combat these


problems; they are basically algorithms based on natural
Symbolic AI VS. Genetic Algorithms
 The architecture of systems that implement GA are more able to adapt
to a wide range of problems.
 A GA functions by generating a large set of possible solutions to a
given problem.
 It then evaluates each of those solutions, and decides on a "fitness
level" (you may recall the phrase: "survival of the fittest") for each
solution set.
 These solutions then breed new solutions.
 The parent solutions that were more "fit" are more likely to reproduce,
while those that were less "fit" are more unlikely to do so.
 In essence, solutions are evolved over time. This way you evolve your
search space scope to a point where you can find the solution.
 Genetic algorithms can be incredibly efficient if programmed correctly.
Application Areas
 GA can be applied to virtually any problem that has a large
search space.

 The military uses GAs to evolve equations to differentiate


between different radar returns.

 Stock companies use GA-powered programs to predict the stock


market.

 In Control systems, Gas pipeline, missile evasion

 In Design Aircraft design, keyboard configuration,


communication networks

 In Security Encryption and Decryption


Example
 f(x) = {MAX(x2): 0 <= x <= 32 }
 Encode Solution: Just use 5 bits (1 or 0).
 Generate initial population.
A 0 1 1 0 1
B 1 1 0 0 0
C 0 1 0 0 0
D 1 0 0 1 1

 Evaluate each solution against objective.


Sol. String Fitness % of Total
A 01101 169 14.4
B 11000 576 49.2
C 01000 64 5.5
D 10011 361 30.9
Example Cont’d
 Create next generation of solutions
 Probability of “being a parent” depends on the fitness.
 Ways for parents to create next generation
 Reproduction
 Use a string again unmodified.
 Crossover
 Cut and paste portions of one string to another.
 Mutation
 Randomly flip a bit.
 COMBINATION of all of the above.
Questions

??
THANK YOU

You might also like