Unit 2 - Genetic Algorithms
Unit 2 - Genetic Algorithms
Shwetha GK
Assistant Professor-II,
Department of CSE
NMAMIT ,Nitte
History of GAs
No convergence rule
or guarantee!
Vocabulary
cross point
Methods of Reproduction: Mutations
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
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.
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
+ +
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
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
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