You are on page 1of 46

Genetic algorithms

Shwetha GK
Assistant Professor-II,
Department of CSE
NMAMIT ,Nitte
History of GAs

• As early as 1962, John Holland's work on


adaptive systems laid the foundation for later
developments.

• By the 1975, the publication of the book


Adaptation in Natural and Artificial Systems,
by Holland and his students and colleagues.
History of GAs

• early to mid-1980s, genetic algorithms were


being applied to a broad range of subjects.

• In 1992 John Koza has used genetic algorithm


to evolve programs to perform certain tasks.
He called his method "genetic programming"
(GP).
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)s are categorized as global search heuristics.
• (GA)s 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

• 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 to form a new population.
What is GA

• The new population is used in the next iteration


of the algorithm.

• The algorithm terminates when either a


maximum number of generations has been
produced, or a satisfactory fitness level has
been reached for the population.

No convergence rule
or guarantee!
Vocabulary

• Individual - Any possible solution


• Population - Group of all individuals
• Fitness – Target function that we are optimizing (each
individual has a fitness)
Basic GeneticAlgorithm

• Start with a large “population” of randomly generated


“attempted solutions” to a problem
• Repeatedly do the following:
– Evaluate each of the attempted solutions
– (probabilistically) keep a subset of the best
solutions
– Use these solutions to generate a new population
• Quit when you have a satisfactory solution
Biological motivation
“Natural selection”

•The origin of species: “Preservation of favourable


variations and rejection of unfavourable variations.”
•There are more individuals born than can survive,
so there is a continuous struggle for life.
•Individuals with an advantage have a greater
chance for survive: so survival of the fittest.
Methods of Selection

There are many different strategies to select the


individuals to be copied over into the next
generation
Several possible crossover strategies

• Randomly select a single point for a crossover


• Two point crossover
• Uniform crossover
• Point mutation
Crossover

• Single point crossover

cross point

• Two point crossover (Multi point crossover)


Methods of Reproduction: Mutations

– Generating new offspring from single parent


Genetic Algorithm
GA( Fitness,FitnessThreshold,p,r,m )
 Initialize : P  p random hypotheses
 Evaluate : for each h in P, compute Fitness(h)
 While [ max h ,Fitness(h)]  FitnessThreshold
1. Select : probabilis tically select ( 1-r)p members of P to add to Ps
Fitness (hi )
Pr( hi ) 

p
j 1
Fitness (h j )
2. Crossover : Probabilis tically 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 mp 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
GAApplications
Domain Application Type

Control Gas pipeline, missile evasion

Design Aircraft design, keyboard configuration, communication networks

Game playing Poker, checkers

Security Encryption and Decryption

Robotics Trajectory planning


Benefits of GeneticAlgorithms

• Concept is easy to understand


• Modular, separate from application
• Supports multi-objective optimization
• Always an answer; answer gets better with time.
• Easy to exploit previous or alternate solutions
• Flexible building blocks for hybrid applications.
Operators for Genetic Algorithms

Parent Strings Offspring


101100101001 Single Point 101111100101
000011100101 Crossover 000000101001

101100101001 Two Point 101011101001


000011100101 Crossover 000100100101

101100101001 Uniform 100111100001


000011100101 Crossover 001000101101

Point
101100101001 101100100001
Mutation
Representing Hypotheses
Represent the given hypothesis
(Type=Car  Minivan)  (Tires = Blackwall)
by
Type Tires
011 10
where attribute type has three values and tires has two
values.

Represent the rule


IF (Type = SUV) THEN (NiceCar = yes)
by
Type Tires NiceCar
100 11 10
Representing Hypotheses

• In GAs, hypotheses are often represented by bit


strings so that they can be easily manipulated by
genetic operators such as mutation and crossover.
• Examples:
(Outlook = Overcast v Rain) ^ (Wind = Strong) <=>
011 10
IF Wind = Strong THEN PlayTennis = yes <=>
111 10 10
where group 1 = 3-valued outlook,
group 2 = 2-valued Wind
group 3 = 2-valued PlayTennis
An example:GABIL system (DeJong et al. 1993)

Learn disjunctive set of propositional rules.


Fitness:
Fitness(h)=(correct(h))2
Representation: For the two rules given below,
IF a1=Ta2=F THEN c=T; IF a2=T THEN c = F
Rules are represented as:
a 1 a2 c a1 a2 c
10 01 1 11 10 0
Genetic operators: ???
• want variable length rule sets
• want only well-formed bitstring hypotheses
Crossover with Variable-Length Bitstrings
Start with two hypothesis:
a1 a2 c a 1 a2 c
h1 : 10 01 1 11 10 0
h2 : 01 11 0 10 01 0
1. Choose crossover points for h1, e.g., after bits
1,8
h1 : 1[0 01 1 11 1]0 0
2. Now restrict points in h2 to those that produce
bitstrings with well-defined semantics, e.g.,
<1,3>, <1,8>, <6,8> (taken randomly)
If we choose <1,3> as a cross over point:
h2 : 0[1 1]1 0 10 01 0
Result is:
a1 a2 c a 1 a2 c a1 a2 c
h3 : 11 10 0
h4 : 00 01 1 11 11 0 10 01 0
GABIL Extensions
Add new genetic operators, an areapplied
probabilistically
1. AddAlternative: generalize constraint on ai by
changing a 0 to 1
2. DropCondition: generalize constraint on ai by
changing every 0 to 1
And, add new field to bit string to determine
whether to allow these:
a1 a2 c a1 a2 c AA DC
10 01 1 11 10 0 1 0
So now the learning strategy also evolves!
Fitness Function and Selection
• A simple measure for modeling the probability that a
hypothesis will be selected is given by the fitness
proportionate selection (or roulette wheel
selection):
Pr(hi)= Fitness(hi)/j=1p Fitness(hj)
• Other methods: Tournament Selection and Rank
Selection.
• In classification tasks, the Fitness function typically
has a component that scores the classification
accuracy over a set of provided training examples.
Other criteria can be added (e.g., complexity or
generality of the rule)
Hypothesis Space Search (I)
• GA search can move very abruptly (as compared to
Backpropagation, for example), replacing a parent
hypothesis by an offspring that may be radically different
from the parent.
• The problem of Crowding: when one individual is more fit
than others, this individual and closely related ones will
take up a large fraction of the population.
• Solutions:
– Use tournament or rank selection instead of roulette
selection.
– Fitness sharing
– restrict ion on the kinds of individuals allowed to
recombine to form offsprings.
Hypothesis Space Search (II): The Schema Theorem

• Definition: A schema is any string composed of


0s, 1s and *s where * means ‘don’t care’.
• Example: schema 0*10 represents strings 0010
and 0110.
• The Schema Theorem: More fit schemas will tend
to grow in influence, especially schemas
containing a small number of defined bits (i.e.,
containing a large number of *s), and especially
when these defined bits are near one another
within the bit string.
Selecting Most Fit Hypothesis
or Hypothesis Space Search
Fitness proportion ate selection :
Fitness(hi )
Pr (hi )  p
 j 1 Fitness(h j )
... can lead to crowding
Tournament selection :
 Pick h1, h2 at random with uniform probabilit y
 With probabilit y p, select the more fit
Rank selection :
 Sort all hypotheses by fitness
 Probabilit y of selection is proportion al to rank
Schemas
How to characterize evolution of population in
GA?
Schema=string containing 0, 1, * (“don’t care”)
• Typical schema: 10**0*
• Instances of above schema: 101101, 100000,
…etc
Characterize population by number of instances
representing each possible schema, Where
• m(s,t)=number of instances of schema s in
population at time t
Consider Just Selection

 f(t)  average fitness of population at time t


 m(s,t)  instances of schema s in population at time t
 uˆ(s,t)  average fitness of instances of s at time t
Probabilit y of selecting h in one selection step
f ( h) f ( h)
Pr (h)  n 
 f (hi ) nf (t )
i 1

Probabilit y of selecting an instances of s in one step


f (h) uˆ ( s, t )
Pr( h  s )    m( s , t )
hs  pt nf (t ) nf (t )
Expected number of instances of s after n selections
uˆ ( s, t )
E[m( s, t  1)]  m( s , t )
f (t )
Schema Theorem

uˆ ( s, t )  d (s) 
E[m( s, t  1)]  m( s, t )1  pc  (1  p ) o( s)

l 1 
m
f (t ) 
 m(s,t)  instances of schema s in population at time t
 f(t)  average fitness of population at time t
 uˆ(s,t)  average fitness of instances of s at time t
 pc  probabilit y of single point crossover operator
 pm  probabilit y of mutation operator
 l  length of single bit strings
 o(s)  number of defined (non "*" ) bits in s
 d(s)  distance between left-, right - most defined bits in s
Genetic Programming

Population of programs
+
represented by trees
Example:
sin sqrt
sin( x)  x 2  y
x +

^ y

x 2
Crossover

+ +

sin ^ sin sqrt

x 2 + x +

x y 2 y

+ +

sin ^ + sqrt

x 2 sin x y +

x 2 y
Block Problem
n
e
s
r v u l a i

Goal: spell UNIVERSAL

Terminals:
• CS (“current stack”) = name of top block on stack, or False
• TB (“top correct block”) = name of topmost correct block
on stack
• NN (“next necessary”) = name of next block needed above
TB in the stack
Block Problem Primitives

Primitive functions:
• (MS x): (“move to stack”), if block x is on the table, moves x to
the top of the stack and returns True. Otherwise, does
nothing and returns False
• (MT x): (“move to table”), if block x is somewhere in the stack,
moves the block at the top of the stack to the table and
returns True. Otherwise, returns False
• (EQ x y): (“equal”), returns True if x equals y, False otherwise
• (NOT x): returns True if x = False, else return False
• (DU x y): (“do until”) executes the expression x repeatedly
until expression y returns the value True
Learned Program

Trained to fit 166 test problems

Using population of 300 programs, found this


after 10 generations:

(EQ (DU (MT CS) (NOT CS))


(DU (MS NN) (NOT NN)))
Genetic Programming

More interesting example: design electronic


filter circuits
• Individuals are programs that transform the
beginning circuit to a final circuit by
adding/subtracting components and
connections
• Use population of 640,000, run on 64 node
parallel process
• Discovers circuits competitive with best
human designs
GP for Classifying Images

Fitness: based on coverage and accuracy


Representation:
• Primitives include Add, Sub, Mult, Div, Not, Max, Min, Read,
Write, If-Then-Else, Either, Pixel, Least, Most, Ave, Variance,
Difference, Mini, Library
• Mini refers to a local subroutine that is separately co-evolved
• Library refers to a global library subroutine (evolved by
selecting the most useful minis)
Genetic operators:
• Crossover, mutation
• Create “mating pools” and use rank proportionate
reproduction
Models of Evolution and Learning I: Lamarckian
Evolution [Late 19th C]
• Proposition: Experiences of a single organism directly
affect the genetic makeup of their offsprings.
• Assessment: This proposition is wrong: the genetic
makeup of an individual is unaffected by the lifetime
experience of one’s biological parents.
• However: Lamarckian processes can sometimes
improve the effectiveness of computerized genetic
algorithms.
Models of Evolution and Learning II: Baldwin Effect
[1896]

• If a species is evolving in a changing environment, there


will be evolutionary pressure to favor individuals with the
capability to learn during their lifetime.
• Those individuals who are able to learn many traits will
rely less strongly on their genetic code to “hard-wire”
traits. As a result, these individuals can support a more
diverse gene pool, relying on individual learning of the
“missing” or “sub-optimized” traits in the genetic code.
This more diverse gene pool can, in turn, support more
rapid evolutionary adaptation. Thus the capability of
learning can accelerate the rate of evolutionary
adaptation of a population.
Biological Evolution

Lamarck (19th century)


• Believed individual genetic makeup was
altered by lifetime experience
• Current evidence contradicts this view

What is the impact of individual learning on


population evolution?
Baldwin Effect

Assume
• Individual learning has no direct influence on individual DNA
• But ability to learn reduces the need to “hard wire” traits in
DNA
Then
• Ability of individuals to learn will support more diverse gene
pool
– Because learning allows individuals with various “hard wired” traits to
be successful
• More diverse gene pool will support faster evolution of gene
pool
individual learning (indirectly) increases rate of evolution
Baldwin Effect (Example)

Consider an example:
1. New predator appears in environment
2. Individuals who can learn (to avoid it) will be
selected
3. Increase in learning individuals will support
more diverse gene pool
4. Resulting in faster evolution
5. Possibly resulting in new non-learned traits
such as instinctive fear of predator
Computer Experiments on Baldwin
Effect
Evolve simple neural networks:
• Some network weights fixed during lifetime, others trainable
• Genetic makeup determines which are fixed, and their weight
values
Results:
• With no individual learning, population failed to improve over
time
• When individual learning allowed
– Early generations: population contained many individuals with many
trainable weights
– Later generations: there was higher fitness or improve fitness
Evolutionary Programming
Summary
• Approach to learning as optimization problem
(optimizes fitness)
• Concepts as chromosomes
– representation issues:
• near values should have near chromosomes (grey
coding)
• variable length encodings (GABIL, Genetic
Programming)
• Genetic algorithm (GA) basics
– population
– fitness function
– fitness proportionate reproduction
Evolutionary Programming
Summary

• Genetic algorithm (GA) basics


– reproduction operators
• crossover
• single, multi, uniform
• Mutation
• Genetic Programming (GP)
– programs as trees
– genetic operations applied to pairs of trees
Evolutionary Programming
Summary
• Other evolution issues
– adaptation of chromosome during lifetime
(Lamarck)
– Baldwin effect (ability to learn indirectly supports
better populations)
• Schema theorem
– good ideas are schemas (some features set, others
*)
– over time good schemas are concentrated in
population

You might also like