Docstoc

GENETIC ALGORITHMS

Document Sample
GENETIC ALGORITHMS Powered By Docstoc
					                   By
      Prafulla S. Kota
Raghavan Vangipuram
 Genetic  Algorithms are a form of local search
 that use methods based on evolution to make
 small changes to a population of chromosomes
 in an attempt to identify an optimal solution.

 We discuss:
  • Representations used for genetic algorithm.
  • Idea of schemata.
  • Genetic operators, crossover and mutations.
  • Procedures used to run Genetic algorithms.


                                                   2
 Genetic  programming can be used to
  evolve S-expressions, which can be used
  as LISP programs to solve problems.
 A string of bits is known as a
  chromosome.
 Each bit is known as a gene.
 Chromosomes can be combined
  together to form creatures.
 We will see how genetic algorithms can
  be used to solve mathematical problems.
                                            3
1.    Generate a random population of
     chromosomes.
2.   If the termination criteria are satisfied, stop.
     Else, continue with step 3.
3.   Determine the fitness of each chromosome.
4.   Apply crossover and mutation to selected
     chromosomes from the current generation, to
     generate a new population of chromosomes –
     the next generation.
5.   Return to step 2.

                                                        4
 The  size of the population should be
  determined in advance.
 The size of each chromosome must
  remain the same for crossover to be
  applied.
 Fittest chromosomes are selected in each
  generation to produce offspring which
  replace the previous generation.
 Each pair of parents produces two
  offspring.

                                             5
 When    we use traditional genetic
  algorithm, a metric is needed whereby
  the fitness of a chromosome can be
  objectively determined.
 When we consider real creatures, fitness
  measure is based on the extent to which
  the physical form (phenotype)
  represented by the genetic information
  (genotype) met certain criteria.
                                             6
 The crossover operator is applied to two
 chromosomes of the same length 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.

                                                       7
    example, consider the following two
 For
 chromosomes:

           110100110001001
           010101000111101

A crossover point might be chosen
 between the sixth and seventh genes.

        110100 | 110001001
        010101 | 000111101

                                          8
 Now the chromosome parts are
 recombined as follows:

 110100 | 000111101 => 110100000111101

 010101 | 110001001 => 010101110001001

       point crossover is the most
 Single
 commonly used form, but it is also
 possible to apply crossover with two or
 more crossover positions.

                                           9
   two point crossover, two points are
 In
 chosen that divide the chromosomes into
 two sections, with the outer sections
 considered to be joined together to turn
 the chromosome into a ring. The two
 sections are swapped with each other.
       100110001        10 1100 001


       011100110        01 0110 110


                                            10
Uniform Crossover:

  • Here, a probability, p, is used to determine
    whether a given bit from parent 1 will be used,
    or from parent 2.
  • In other words, a child can receive any random
    bits from each of its parents.
Parent 1: 100011001
Parent 2: 001101110
   100110001             1   1   0   10   0   1   01


   011100110             0   0   1   11   0   0   10



                                                       11
 Similarto Hill-Climbing, which involves
 generating a possible solution to the
 problem and moving toward a better
 solution than the current one until a
 solution is found from which no better
 solution can be found.

 Mutation is a unary operator (it is applied
 to just one argument – a single gene) that
 is usually applied with a low probability.
                                                12
 Mutation  simply involves reversing the
  value of a bit in a chromosome.
 For example, with a mutation rate of 0.01, it
  might be expected that one gene in a
  chromosome of 100 genes might be
  reversed.

             010101110001001


             010101110101001
                                                  13
 There  are typically two ways in which a run
  of a genetic algorithm is terminated.
 Usually, a limit is put on the number of
  generations, after which the run is
  considered to have finished.
 The run can stop when a particular solution
  has been reached, or when the highest
  fitness level in the population has reached a
  particular value.
 In some cases, genetic algorithms are used
  to generate interesting pictures.
 In these cases, human judgment must be
  used to determine when to terminate.
                                                  14
 Use of Genetic Algorithm to maximize
  value of a mathematic function.
 Maximize the function:
           f(x)=sin(x)
     over the range of ‘x’ from 1 to 15.
           ‘x’ is in radians.
 Each chromosome represents a possible
  value of ‘x’ using four bits.


                                           15
16
 Wewill use a population size of four
 chromosomes.
 • The first step is to generate a random
   population, which is our first generation:
           c1=1001
           c2=0011
           c3=1010
           c4=0101
 • To calculate the fitness of a chromosome, we
   need to first convert it to a decimal integer and
   then calculate f(x) for this integer.

                                                       17
• We will assign a fitness numeric value from 0 to
  100, where 0 is the least fit and 100 is the most fit.
• f(x) generates real numbers between -1 and 1.
• We will assign a fitness of 100 to f(x)=1 and
  fitness of 0 to f(x)= -1.
• Fitness of 50 will be assigned to f(x)=0.
           f’(x)= 50[f(x)+1]
                = 50[Sin(x)+1]



                                                           18
 The fitness ratio of a chromosome is that
 chromosome’s fitness as a percentage of
 the total fitness of the population.
   Chromosome   Genes Integer   F(x)    Fitness   Fitness
                      value             F’(x)     ratio
   C1           1001   9        0.41    70.61     46.3%
   C2           0011   3        0.14    57.06     37.4%
   C3           1010   10       -0.54   22.80     14.9%
   C4           0101   5        -0.96   2.05      1.34%

          Fitness values of First generation

                                                            19
 Nowwe need to run a single step of our
 genetic algorithm to produce the next
 generation.
 • First step is to select which chromosomes will
  reproduce.

 Roulette-wheel selection involves using the
  fitness ratio to randomly select chromosomes to
  reproduce.


                                                    20
   The range of real numbers from 0 to 100 is
    divided up between the chromosomes
    proportionally to each chromosome’s fitness.
   A random number is now generated between 0
    to 100. This number will fall in the range of one of
    the chromosomes, and this chromosome has
    been selected for reproduction.
   The next random number is used to select the
    chromosome’s mate.
   Hence, fitter chromosomes will tend to produce
    more offspring than less fit chromosomes.

                                                           21
 Itis important that this method does not
  stop less fit chromosomes from
  reproducing at all.
 We will now need to generate four
  random numbers to find the four parents
  that will produce the next generation.
 We first choose 56.7, which falls in the
  range of c2. So, c2 is parent 1.
 Next, 38.2 is chosen, so its mate is c1
  (parent 2).
                                             22
 We  now combine c1 and c2 to produce
  new offspring.
 Select a random crossover point.
           10 | 01
           00 | 11
 Crossover is applied to produce two
  offspring, c5 and c6:
      c5=1011
      c6=0001
                                         23
 Similarly, we   calculate c7 and c8 from
  parents c1 and c3:
      c7=1000
      c8=1011
 Observe that c4 did not get a chance to
  reproduce. So its genes will be lost.
 c1 was the fittest of all chromosomes. So,
  it could reproduce twice, thus passing on
  its highly fit genes to all members of the
  next generation.
                                               24
Chromosome   Genes   Integer   F(x)   Fitness   Fitness
                     value            F’(x)     ratio
C5           1011    11        -1     0         0%
C6           0001    1         0.84   92.07     48.1%
C7           1000    8         0.99   99.47     51.9%
C8           1011    11        -1     0         0%




                                                          25
 It is possible to explain genetic
  algorithms by comparison with natural
  evolution: small changes that occur on a
  selective basis combined with
  reproduction will tend to improve the
  fitness of the population over time.

 John Holland invented schemata to
  provide an explanation for genetic
  algorithms that is more rigorous.
                                             26
        of numbers are used to represent
 Strings
 input patterns in classifier systems. In these
 patterns, * is used to represent “any value”
 or “don’t care”, so that the following string:
     1011*001*0
 matches the following strings:
   1011000100
   1011000110
   1011100100
   1011100110

                                                  27
 A schema is a string of bits that represents a
  possible chromosome, using * to represent “any
  value.”
 A schema is said to match a chromosome if the
  bit string that represents the chromosome
  matches the schema in the way shown above.

        *11*
    This matches the following four chromosomes

       0110       0111       1110       1111


                                                   28
A  schema with n *’s will match a total of
  2^n chromosomes.
 Each chromosome of r bits will match 2^r
  different schemata.

 TheDefining length of a schema is
 defined as the distance between the first
 and last defined bits in the schema.


                                              29
        **10111*
        1*0*1**
        11111
        1***1
        *****10**1*****
The defining length for all the above
schemata is 4.

             dL(S)<=L(S)
                                        30
      of the schema is defined a the
 Order
 number of defined bits in the schema.
           **10*11*
           1*0*1**1
           1111
           1***1***1***1
           1*****10***1*****
  The order of all the above schemata is 4.
 We denote the order of schema as O(S).
 Order of the schema tells us how specific it
  is.
                                                 31
   Consider the following population of 10
    chromosomes, each of length 32.
    C1=01000100101010010001010100101010
    C2=10100010100100001001010111010101
    C3=01010101011110101010100101010101
    C4=11010101010101001101111010100101
    C5=11010010101010010010100100001010
    C6=00101001010100101010010101111010
    C7=00101010100101010010101001010011
    C8=11111010010101010100101001010101
    C9=01010101010111101010001010101011
    C10=11010100100101010011110010100001


                                              32
 Let us consider the following schema:
      s0=11010*********************
 This schema is matched by three
  chromosomes in our population:
  c4,c5,c10.
 We say that schema s0 matches three
  chromosomes in generation ‘i’ and write
  this as follows:
            m(s0,i) = 3
                                            33
   The fitness of a schema, S, in generation ‘i’ is
    written as follows:
              f(S,i)
   The fitness of a schema is defined as the average
    fitness of the chromosomes in the population that
    match the schema.
   Hence if we define the fitness of c4, c5, and c10
    as follows:
              f(c4,i)=10
              f(c5,i)=22
              f(c10,i)=40

                                                        34
 Hence, thefitness of the schema s0 is
 defined as the average of these three
 values:
         f(s0,i)=(10+22+40)/3
                = 24

 We will now consider factors which affect
 the likelihood of a particular schema
 surviving from one generation to the
 next.
                                              35
 Let us assume that there is a chromosome
  that matches a schema, S, in the
  population at time i.
 The number of occurrences of S in the
  population at time i is:
           m(S,i)
 Number of occurrences of S in the
  population in the subsequent generation
  is:
           m(S,i+1)
                                             36
 The fitness of S in generation i is
                     f(S,i)
 We will calculate the probability that a given
  chromosome, c, which matches the schema S at time
  i, will reproduce and thus its genes will be present in
  the population at time i+1.
   The probability that a chromosome will reproduce is
    proportional to its fitness, so the expected number of
    offspring of chromosome c is:
             m(c,i+1)=f(c,i)/a(i)
        Where a(i) is the average fitness of the
    chromosomes in the population at time i.

                                                             37
 Because   chromosome c is an instance of
  schema S, we can thus deduce:
      m(S, i+1)=f(c1,i)+…..f(Cn,i)/a(i)
  where C1 to Cn are the chromosomes in
  the population at time i that match
  schema S.
 Let us compare this with the definition of
  the fitness of schema S, f(S,i), which is
  defined as follows:
           f(S,i)=f(c1,i)+…..f(Cn,i)/m(S,i)
                                               38
   By combining the above stated formulas,
            m(S,i+1)=f(S,i).m(S,i)/a(i)
   The more fit a schema is compared with the
    average fitness of the current population, the
    more likely it is that that schema will appear in a
    subsequent population of chromosomes.
   There will be fewer occurrences of a given
    schema whose fitness is lower than the average
    fitness of the population and more occurrences
    of a given schema whose fitness is higher than
    average.

                                                          39
 Both  mutation and crossover can destroy
  the presence of a schema.
 A given schema can be said to have
  survived crossover, if the crossover
  operation produces a new chromosome
  that matches the schema from a parent
  that also matches the schema.
 For a schema to survive crossover, the
  crossover point must be outside the
  defining length.
                                             40
 Hence, the  probability that a schema S of
  defining length dL(S) and of length L(S)
  will survive crossover is
           Ps(S)=1-[dL(S)]/L(S)-1
 This formula assumes that crossover is
  applied to each pair of parents that
  reproduce.
 Hence, after certain modifications of the
  above formula:
           Ps(S)>=1-(Pc)[dL(S)]/L(S)-1
                                               41
Effect of Mutation:
 Probability that mutation will be applied
  is Pm.
 Hence, a schema will survive mutation if
  mutation is not applied to any of the
  defined bits. The probability of survival
  can be defined as:
           Ps(S)=(1-Pm)^O(s)
 Hence, a schema is more likely to survive
  mutation if it has lower order
                                              42
   We can combine all the equations we have to
    give one equation that defines the likelihood of a
    schema surviving
    reproduction using crossover and mutation.
   That equation represents the schema theorem,
    developed by Holland, which can be stated as:
    “Short, low order schemata which are fitter than
    the average fitness of the population will appear
    with exponentially increasing regularity in
    subsequent generations.”


                                                         43
   The short, low order, high-fitness schemata are
    known as building blocks.
   Genetic algorithms work well when a small group of
    genes that are close together represent a feature that
    contributes to the fitness of a chromosome.
   Randomly selecting bit to represent particular
    features of a solution is not good enough.
   Bits should be selected in such a way that they group
    naturally together into building blocks, which
    genetic algorithm are designed to manipulate.


                                                             44
 Genetic  Algorithms can be mislead or
  deceived by some building blocks into
  heading toward sub-optimal solutions.
 One way to avoid effects of deception is
  to use inversion, which is a unary
  operator that reverses the order of a
  subset of the bits within a chromosome.
 Another way to avoid deception is to use
  Messy Genetic Algorithms.
                                             45
 Developed    as an alternative to standard
  genetic algorithms.
 Each bit is labeled with its position.
 A chromosome does not have to contain a
  value for each position, and, a given
  position in a chromosome can have more
  than one value.
 Each bit in a chromosome is represented by
  a pair of numbers: the first number
  represents the position within the
  chromosome, and the second number is the
  bit value.
                                               46
 mGA’s  use the standard mutation
  operation. But, instead of crossover, they
  use splice and cut operations.
 Two chromosomes can be spliced
  together by simply joining one to the end
  of other.
 The cut operator splits one chromosome,
  into two smaller chromosomes.


                                               47
 Theprocess for running this genetic
 algorithm is as follows:
 1.   Produce a random population of chromosomes. We
      will start with 100.
 2.   Determine a score for each chromosome by
      playing its strategy against a number of opponents.
 3.   Select chromosomes for the population to
      reproduce.
 4.   Replace the previous generation with new
      population produced by reproduction.
 5.   Return to step 2.


                                                            48
 Most Combinatorial search problems can
  be successfully solved using genetic
  algorithms.
 Genetic Algorithms can be applied to:
  •   Travelling Salesman Problem
  •   The Knight’s tour.
  •   The CNF- satisfiability problem.
  •   Robot Navigation.
  •   Knapsack Problem
  •   Time Table problem.

                                           49
THANK YOU




            50

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:8
posted:7/28/2012
language:English
pages:50