Genetic Algorithms Variations and Implementation Issues CS 431 Advanced Topics in AI Classic Genetic Algorithms GAs as proposed by Holland had the following properties: Randomly generated population Binary encoding of fixed length (k-bits) Constant population size, N Fitness-proportionate selection of parents with replacement Crossover probability or rate, p c (i.e. two selected parents will crossover with probability p c ) One-point crossover at a randomly chosen crossover point/location Per bit Mutation rate, p m (i.e. each bit can mutate with probability p m ) Bit-flip mutation Keep all offspring, discard parents for next generation (population remains equal to N) Fitness function based stopping criterion (i.e. fitness of best individual does not change from one generation to another) CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 2 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 1
Design Decisions for Classic GAs Problem formulation as search for best solution in search/solution space Choice of a fitness function for evaluating goodness of candidate solutions Length (k) of binary string for representing candidate solutions Size of population (N) Crossover rate, p c Mutation rate, p m Convergence criteria Implementing in software CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 3 Design Decisions for GAs The following decisions might have to be made for general and modern GAs Type of crossover operator Type of mutation operator (or even if mutation should be used on not) Whether to use other operators as well (like hill-climbing, operators from other fields) Selection strategies Replacement strategies Convergence criteria Integration with other techniques (e.g. neural networks, fuzzy systems, etc) Parameters for the various operations Efficient implementation in software CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 4 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 2
Operators (1) Crossover operators One-point crossover K-point crossover Uniform crossover Arithmetic crossover Crossover rate: the probability of applying crossover Other operators for nonlinear representations Mutation operators Bit flipping Random bit assignment Multiple mutations Per-chromosome vs. per-gene (bit) mutation rate Other operators for non-binary representations CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 5 Operators (2) Selection Fitness-proportionate selection/roulette wheel algorithm Rank-based selection Tournament selection More complex selection strategies Search bias The various operators bias the search process in different ways. That is, some offspring tend to be more likely to be generated than others. As such, these operators bias the performance of Gas. Depending on the cause, bias can be crossover bias, mutation bias, selection bias, etc. CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 6 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 3
Crossover Operators (1) CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 7 Crossover Operators (2) One-point crossover (SPX) Classic and simplest technique Involves cutting the chromosomes of the parents at a randomly chosen common point and exchanging the righthand sub-chromosomes Limitation: may not produce variant offspring for certain types of parent chromosomes (from the theory of GAs) Positive: simple CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 8 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 4
Crossover Operators (3) Two-point or double-point crossover (DPX) Two common points are located in parents and the sub-chromosomes between these points are exchanged The chromosomes are thought of as rings with the first and last gene connected. The rings are cut at two points and the resulting parts are exchanged In general, k-point crossover CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 9 Crossover Operators (4) Uniform crossover (UPX) Each gene in offspring is randomly selected from corresponding genes of the parents There is a uniform probability of an offspring getting a particular gene from either parent Arithmetic crossover (APX) An arithmetic operator is applied to all the genes of the two parents to compute the genes for the offspring Crossover is applied to parents with probability p c (usually between 0.5-0.8). If parents are not crossovered then they are cloned to maintain the population CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 10 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 5
Mutation Operators Mutation consists of making (usually small) alterations to one or more genes in a chromosome In binary chromosomes it consists of inverting random bits of the genotypes In GAs, mutation is generally considered as a method to avoid fixation of genetic material rather than to obtain better solutions The per-gene mutation rate is very low (usually between 0.001 and 0.01). A rule of thumb is p m = 1/(no. of bits in string) CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 11 Selection Strategies or Operators (1) Selection is the process by which individual (i.e. their chromosomes) are selected for reproduction To emulate natural selection individuals with a higher fitness should be chosen with a higher probability By exploiting higher fitness individuals it is expected that offspring would be of high quality and the population evolves in quality However, a balance must be achieved between exploitation and exploration (through genetic operators) to avoid local searches CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 12 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 6
Fitness-Proportionate Selection (1) This is the most common selection strategy. Introduced by Holland. Let f i = fitness of individual i and f = (1/N) Σ j f j = average fitness of population Then, individual i is selected with a probability p i = f i / Σ j f j = f i / fn Can be implemented by the roulette wheel algorithm. E.g. f 1 = f 2 = 10; f 3 = 15; f 4 = 25 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 13 Fitness-Proportionate Selection (2) Roulette wheel algorithm Generate a random floating point number r in the range [0, Σ j N f j ]. Select individual i such that Σ i i-1 f i r < Σ i N f i Problems with FPS Premature convergence Stagnation Solution: fitness scaling techniques CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 14 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 7
Rank Selection Individuals are sorted (ranked) on the basis of their fitness, so that f i >= f j for i < j Then each individual is assigned a probability p i of being selected taken from a given distribution, with the constraint that Σi p i = 1 Advantages No premature convergence No stagnation Explicit fitness not needed for sorting; only the ability to compare two individuals Disadvantages Sorting overhead No theoretical basis (and not naturally inspired) CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 15 Tournament Selection For tournament selection, a group of N >= 2 individuals is selected randomly from the population The individual with highest fitness in the group is selected, the others are discarded (tournament) Process is repeated until desired number of parents are obtained Advantages No premature convergence No stagnation No sorting required Explicit fitness not needed Is naturally inspired CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 16 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 8
Encoding Schemes (1) Integer parameters If parameter p varies in the range [0, 2 N -1] then we can encode it using binary representation of N bits (b 1 to b N ) such that p = Σi N b i 2 i-1 If p is in the range [M, M + 2 N - 1] (M is not zero), then the above encoding can be used with translation If p is in the range [0, L-1] where there is no N such that L = 2 N then some remapping schemes would have to used CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 17 Encoding Schemes (2) Real-valued parameters Real-valued parameters can be represented as fixed points numbers or integers by scaling and quantization. E.g. if p ranges from p min to p max then it is quantized to the following value when binary representation of length N is used: p(2 N 1) /(p max p min ) Thus, there is a conflict between keeping the chromosome short for good convergence and knowing the solution with good precision Real-valued parameters can also be represented by nonbinary symbols or real numbers CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 18 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 9
Assignment Problem (1) Find the maximum of the following function in the range -8 x, y 7. Consider integer values only. 2 2 2 f ( x, y) = exp[ 0.7( x + 0.2) ]*exp[ 0.9y ] + 2exp[ ( x 5) ]*exp[ ( y 2) What is its fitness function? What representation to use? Length of bit string? Effect of size of initial population? Effect of p m and p c? Effect of crossover, mutation, selection, and replacement? 2 ] CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 19 Assignment Problem (2) CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 20 CS 431 (Wi 2002/2003) - Asim Karim @ LUMS 10