Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP305. Part II. Genetic Algorithms. Genetic Algorithms.

Similar presentations


Presentation on theme: "COMP305. Part II. Genetic Algorithms. Genetic Algorithms."— Presentation transcript:

1 COMP Part II. Genetic Algorithms. Genetic Algorithms

2 Basic Genetic Algorithm.
Topic 4. Basic Genetic Algorithm. Genetic Algorithms

3 GAs by John Holland. Holland introduced
a “population” of binary strings which he called “chromosomes”. The “population” evolves using kind of “natural selection” together with the genetics-inspired operators of crossover, mutation, and inversion. Bits in a “chromosome” represent genes, and each “gene” is an instance of a particular “allele”, 0 or 1. The selection operator chooses those chromosomes in the population that will be allowed to reproduce, and on average the fitter chromosomes produce more offspring than the less fit ones. Crossover exchange subparts of two chromosomes Mutation randomly changes the allele values of some locations in the chromosome. Inversion reverses the order of a contiguous section of the chromosome rearranging the genes order. Genetic Algorithms

4 Basic Structure of a Genetic Algorithm.
Randomly generate initial population of n bit strings (“chromosomes”) Evaluate the fitness of each string in the population 3. Repeat the following steps until next generation of n individual strings produced a. Select pair of parent chromosomes from current population according to their fitness, i.e. chromosomes with higher fitness are selected more often b. Apply crossover (with probability) c. Apply mutation (with probability of occurrence) 4. Apply generational replacement 5. Go to 2 or terminate if termination condition met Genetic Algorithms

5 Basic Structure of a Genetic Algorithm.
Randomly generate initial population of n bit strings (“chromosomes”) Evaluate the fitness of each string in the population 3. Repeat the following steps until next generation of n individual strings produced a. Select pair of parent chromosomes from current population according to their fitness, i.e. chromosomes with higher fitness are selected more often b. Apply crossover (with probability) c. Apply mutation (with probability of occurrence) 4. Apply generational replacement 5. Go to 2 or terminate if termination condition met Each iteration in the cycle produces a new “generation” of chromosomes. The entire set of generations is called a run. Typical GA run is from 50 to 500 or more generations. At the end of a run often there is at least one highly fit chromosome in the population. Genetic Algorithms

6 Example Implementation of a GA.
Let the length of the string l = 8 , and the number of chromosomes in the population (population size) n = 4. Fitness function f(x) is equal to the number of ones in the bit string x. Selection operator Fitness-proportionate selection, i.e. the number of times an individual is expected to reproduce is equal to its fitness fi divided by the average fitness of the population f Ni = fi / f Crossover probability pc = 0.7 Mutation probability pm = 0.001 Make a run of three generations. Genetic Algorithms

7 Example of a Genetic Algorithm.
The initial randomly generated population might look like this: Chromosome Chromosome index string n = Generation 0 l = 8 Genetic Algorithms

8 Example of a Genetic Algorithm.
2. Evaluate the fitness of each string in the population Chromosome Chromosome Fitness = number of ones index string in the string f1 = 2 f2 = 6 f3 = 1 n = f4 = 3 Generation 0 Genetic Algorithms

9 Example of a Genetic Algorithm.
3a. Select pair of parent chromosomes from current population according to their fitness Chromosome Chromosome Fitness times to be selected index string for reproduction f1 = N1 = f1 / f = 2/ f2 = N2 = f2 / f = 2 f3 = N3 = f3 / f = 1/ n = f4 = N4 = f4 / f = 1 Average fitness f = ( )/4 = 3 Generation 0 Genetic Algorithms

10 Example of a Genetic Algorithm.
3a. Select pair of parent chromosomes from current population according to their fitness Chromosome Chromosome Fitness times to be selected index string for reproduction f1 = N f2 = N2 = 2 f3 = N n = f4 = N4 = 1 Thus, chromosome number 1 shall be selected one time, chromosome number 2 shall be selected two times, chromosome number 3 shall not be selected at all, chromosome number 4 shall be selected one time. Generation 0 Genetic Algorithms

11 Example of a Genetic Algorithm.
3a. Select pair of parent chromosomes from current population according to their fitness Chromosome Chromosome Fitness times to be selected index string for reproduction f1 = N f2 = N2 = 2 f3 = N n = f4 = N4 = 1 Thus, string number 1 shall be selected one time string number 2 shall be selected two times string number 3 shall not be selected at all string number 4 shall be selected one time Generation 0 Forming pairs of “parents” for crossover: 1st pair: strings 2 and 1, 2nd pair: strings 2 and 4 Genetic Algorithms

12 Example of a Genetic Algorithm.
3b. Apply crossover (with probability) pc = 0.7 Chromosome Chromosome Fitness times to be selected index string for reproduction f1 = N f2 = N2 = 2 f3 = N n = f4 = N4 = 1 Pairs of “parents” for crossover: 1st pair: strings 2 and nd pair: strings 2 and 4 index chromosome index chromosome Generation 0 Genetic Algorithms

13 Example of a Genetic Algorithm.
3b. Apply crossover (with probability) pc = 0.7 Use a generator producing random numbers in the range between 0 and 1 to get a random number r for each pair of parental chromosomes. If the random number r produced by the generator for the pair of “parents” is less or equal to the crossover probability pc, then apply crossover to the “parents” at randomly chosen locus, otherwise the parents do not crossover. If a pair of parents do not undergo crossover, their offspring are their identical copies. Pairs of “parents” for crossover: r = 0.4 < pc => Apply crossover r = 0.8 > pc => No crossover 1st pair: strings 2 and nd pair: strings 2 and 4 index chromosome index chromosome Genetic Algorithms

14 Example of a Genetic Algorithm.
3b. Apply crossover (with probability) pc = 0.7 Pairs of “parents” for crossover: r = 0.4 < pc => Apply crossover r = 0.8 > pc => No crossover 1st pair: strings 2 and nd pair: strings 2 and 4 index chromosome index chromosome old new Genetic Algorithms

15 Example of a Genetic Algorithm.
3c. Apply mutation (with probability of occurrence) pm = 0.001 Use a generator producing random numbers in the range between 0 and 1 to get a random number r for each new chromosome. If the random number r is less or equal to the mutation probability pm, apply mutation to the chromosome, i.e. flip a bit at randomly chosen locus. Mutation: 1st pair: nd pair: index chromosome index chromosome r = 0.4 > pm => No mutation r = 0.8 > pm => No mutation r = 0.1 > pm => No mutation r = < pm => Mutation old new Genetic Algorithms

16 Example of a Genetic Algorithm.
3c. Apply mutation (with probability of occurrence) pm = 0.001 Mutation: 1st pair: nd pair: index chromosome index chromosome old new Genetic Algorithms

17 Example of a Genetic Algorithm.
4. Apply generational replacement Replacement 1st pair: nd pair: index chromosome index chromosome Parents Offspring Genetic Algorithms

18 Example of a Genetic Algorithm.
4. Apply generational Replacement Chromosome Chromosome Fitness times to be selected index string for reproduction f1 = N f2 = N2 = 2 f3 = N n = f4 = N4 = 1 Generation 0 Generation 1 Genetic Algorithms

19 Example of a Genetic Algorithm.
4. Apply generational Replacement Chromosome Chromosome Fitness times to be selected index string for reproduction f1 = N f2 = N2 = 2 f3 = N n = f4 = N4 = 1 Run for the second generation Generation 0 Generation 1 Genetic Algorithms

20 Example of a Genetic Algorithm.
2. Evaluate the fitness of each string in the population Chromosome Chromosome Fitness = number of ones index string in the string f1 = 6 f5 = 4 f6 = 4 f7 = 4 Generation 1 Genetic Algorithms

21 Example of a Genetic Algorithm.
3a. Select pair of parent chromosomes from current population according to their fitness Chromosome Chromosome Fitness times to be selected index string for reproduction f2 = N2 = f2 / f = 6/ f5 = N5 = f5 / f = 4/ f6 = N6 = f6 / f = 4/ f7 = N7 = f7 / f = 4/ Average fitness f = ( )/4 = 4.5 Generation 1 Genetic Algorithms

22 Example of a Genetic Algorithm.
3a. Select pair of parent chromosomes from current population according to their fitness Chromosome Chromosome Fitness times to be selected index string for reproduction f2 = N f5 = N f6 = N f7 = N Thus, chromosome number 2 shall be selected one time, chromosome number 5 shall be selected one time, chromosome number 6 shall be selected one time, and chromosome number 7 shall be selected one time. Generation 1 Genetic Algorithms

23 Example of a Genetic Algorithm.
3a. Select pair of parent chromosomes from current population according to their fitness Chromosome Chromosome Fitness times to be selected index string for reproduction f2 = N f5 = N f6 = N f7 = N Thus, string number 2 shall be selected one time, string number 5 shall be selected one time, string number 6 shall be selected one time, string number 7 shall be selected one time. Generation 1 Forming pairs of “parents” for crossover: 1st pair: strings 2 and 5, 2nd pair: strings 6 and 7 Genetic Algorithms

24 Example of a Genetic Algorithm.
3b. Apply crossover (with probability) pc = 0.7 Chromosome Chromosome Fitness times to be selected index string for reproduction f2 = N f5 = N f6 = N f7 = N Pairs of “parents” for crossover: 1st pair: strings 2 and nd pair: strings 6 and 7 index chromosome index chromosome Generation 1 Genetic Algorithms

25 Example of a Genetic Algorithm.
3b. Apply crossover (with probability) pc = 0.7 Use a generator producing random numbers in the range between 0 and 1 to get a random number r for each pair of parental chromosomes. If the random number r produced by the generator for the pair is less or equal to the crossover probability pc, apply crossover to the “parents” at randomly chosen locus. If a pair of parents do not undergo crossover, their offspring are their identical copies. Pairs of “parents” for crossover: r = 0.6 < pc => Apply crossover r = 0.1 < pc => Apply crossover 1st pair: strings 2 and nd pair: strings 6 and 7 index chromosome index chromosome Genetic Algorithms

26 Example of a Genetic Algorithm.
3b. Apply crossover (with probability) pc = 0.7 Pairs of “parents” for crossover: r = 0.6 < pc => Apply crossover r = 0.1 < pc => Apply crossover 1st pair: strings 2 and nd pair: strings 6 and 7 index chromosome index chromosome old new Genetic Algorithms

27 Example of a Genetic Algorithm.
3c. Apply mutation (with probability of occurrence) pm = 0.001 Use a generator producing random numbers in the range between 0 and 1 to get a random number r for each new chromosome. If the random number r is less or equal to the mutation probability pm, apply mutation to the chromosome, i.e. flip a bit at randomly chosen locus. Mutation: 1st pair: nd pair: index chromosome index chromosome r = 0.35 > pm => No mutation r = 0.1 > pm => No mutation r = 0.47 > pm => No mutation r = 0.53 > pm => No mutation Genetic Algorithms

28 Example of a Genetic Algorithm.
3c. Apply mutation (with probability of occurrence) pm = 0.001 Mutation: 1st pair: nd pair: index chromosome index chromosome old new Genetic Algorithms

29 Example of a Genetic Algorithm.
4. Apply generational replacement Replacement 1st pair: nd pair: index chromosome index chromosome Parents Offspring Genetic Algorithms

30 Example of a Genetic Algorithm.
4. Apply generational Replacement Chromosome Chromosome Fitness times to be selected index string for reproduction f2 = N f5 = N f6 = N f7 = N Generation 1 Generation 2 Genetic Algorithms

31 Example of a Genetic Algorithm.
4. Apply generational Replacement Chromosome Chromosome Fitness times to be selected index string for reproduction f2 = N f5 = N f6 = N f7 = N Run for the third generation Generation 1 Generation 2 Genetic Algorithms

32 Example of a Genetic Algorithm.
2. Evaluate the fitness of each string in the population Chromosome Chromosome Fitness = number of ones index string in the string f8 = 5 f9 = 5 f10 = 3 f11 = 5 Generation 2 Genetic Algorithms

33 Example of a Genetic Algorithm.
3a. Select pair of parent chromosomes from current population according to their fitness Chromosome Chromosome Fitness times to be selected index string for reproduction f8 = N8 = f8 / f = 5/ f9 = N9 = f9 / f = 5/ f10 = N10 = f10 / f = 3/ f11 = N11 = f11 / f = 5/ Average fitness f = ( )/4 = 4.5 Generation 2 Genetic Algorithms

34 Example of a Genetic Algorithm.
3a. Select pair of parent chromosomes from current population according to their fitness Chromosome Chromosome Fitness times to be selected index string for reproduction f8 = N f9 = N f10 = N f11 = N Thus, chromosome number 8 shall be selected one time, chromosome number 9 shall be selected one time, chromosome number 10 shall not be selected at all, and chromosome number 11 shall be selected two times. Generation 2 Genetic Algorithms

35 Example of a Genetic Algorithm.
3a. Select pair of parent chromosomes from current population according to their fitness Chromosome Chromosome Fitness times to be selected index string for reproduction f8 = N f9 = N f10 = N f11 = N Thus, string number 8 shall be selected one time string number 9 shall be selected one time string number 10 shall not be selected at all string number 11 shall be selected two times Generation 2 Forming pairs of “parents” for crossover: 1st pair: strings 8 and 11, 2nd pair: strings 9 and 11 Genetic Algorithms

36 Example of a Genetic Algorithm.
3b. Apply crossover (with probability) pc = 0.7 Chromosome Chromosome Fitness times to be selected index string for reproduction f8 = N f9 = N f10 = N f11 = N Pairs of “parents” for crossover: 1st pair: strings 8 and nd pair: strings 9 and 11 index chromosome index chromosome Generation 1 Genetic Algorithms

37 Example of a Genetic Algorithm.
3b. Apply crossover (with probability) pc = 0.7 Use a generator producing random numbers in the range between 0 and 1 to get a random number r for each pair of parental chromosomes. If the random number r produced by the generator for the pair is less or equal to the crossover probability pc, apply crossover to the “parents” at randomly chosen locus. If a pair of parents do not undergo crossover, their offspring are their identical copies. Pairs of “parents” for crossover: r = 0.83 > pc => No crossover r = 0.54 < pc => Apply crossover 1st pair: strings 8 and nd pair: strings 9 and 11 index chromosome index chromosome Genetic Algorithms

38 Example of a Genetic Algorithm.
3b. Apply crossover (with probability) pc = 0.7 Pairs of “parents” for crossover: r = 0.83 > pc => No crossover r = 0.54 < pc => Apply crossover 1st pair: strings 8 and nd pair: strings 9 and 11 index chromosome index chromosome old new Genetic Algorithms

39 Example of a Genetic Algorithm.
3c. Apply mutation (with probability of occurrence) pm = 0.001 Use a generator producing random numbers in the range between 0 and 1 to get a random number r for each new chromosome. If the random number r is less or equal to the mutation probability pm, apply mutation to the chromosome, i.e. flip a bit at randomly chosen locus. Mutation: 1st pair: nd pair: index chromosome index chromosome r = 0.5 > pm => No mutation r = 0.61 > pm => No mutation r = < pm => Mutation r = > pm => No mutation old new Genetic Algorithms

40 Example of a Genetic Algorithm.
3c. Apply mutation (with probability of occurrence) pm = 0.001 Mutation: 1st pair: nd pair: index chromosome index chromosome old new Genetic Algorithms

41 Example of a Genetic Algorithm.
4. Apply generational replacement Replacement 1st pair: nd pair: index chromosome index chromosome Parents Offspring Genetic Algorithms

42 Example of a Genetic Algorithm.
4. Apply generational Replacement Chromosome Chromosome Fitness times to be selected index string for reproduction f8 = N f9 = N f10 = N f11 = N The third generation STOP Generation 2 Generation 3 Genetic Algorithms

43 Example of a Genetic Algorithm.
2. Evaluate the fitness of each string in the population Chromosome Chromosome Fitness = number of ones index string in the string f8 = 5 f12 = 6 f13 = 4 f14 = 6 Average fitness f = ( )/4 = 5.25 Generation 3 Genetic Algorithms

44 Example of a Genetic Algorithm.
2. Evaluate the fitness of each string in the population Chromosome Chromosome Fitness = number of ones index string in the string f8 = 5 f12 = 6 f13 = 4 f14 = 6 f Average fitness f = ( )/4 = 5.25 The average fitness in the population of possible solutions increases with every generation. Generation № Generation 3 5.0 3.0 1.0 Genetic Algorithms


Download ppt "COMP305. Part II. Genetic Algorithms. Genetic Algorithms."

Similar presentations


Ads by Google