24
Genetic Algorithm

Genetic Algorithm. Introduction Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics Represent an intelligent

Embed Size (px)

Citation preview

Page 1: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Genetic Algorithm

Page 2: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Introduction

Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics

Represent an intelligent exploitation of random search within a desired search space to solve a problem

Page 3: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

What are evolutionary algorithms and Genetic Algorithm?

Page 4: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Steps of Genetic Algorithm Randomly generate an initial population Compute and save the fitness for each individual in the

current population Define selection probabilities for each individual Generate probabilistically selecting individuals from

population to produce offspring via genetic operators Repeat step 2 until satisfying solution is obtained.

Page 5: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Outline of Basic Genetic Algorithm [Start] Generate random population of n chromosomes

(suitable solutions for the problem) [Fitness] Evaluate the fitness f(x) of each

chromosome x in the population [New population] Create a new population by repeating

following steps until the new population is complete [Selection] Select two parent chromosomes from a population

according to their fitness (the better fitness, the bigger chance to be selected)

[Crossover] With a crossover probability cross over the parents to form a new offspring (children). If no crossover was performed, offspring is an exact copy of parents.

Page 6: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Outline of Basic Genetic Algorithm [Mutation] With a mutation probability mutate new offspring

at each locus (position in chromosome). [Accepting] Place new offspring in a new population

[Replace] Use new generated population for a further run of algorithm

[Test] If the end condition is satisfied, stop, and return the best solution in current population

[Loop] Go to step 2

Page 7: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Flowchart of Genetic Algorithm

Page 8: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

The Initial Population Represent solutions to problems

As a bit string of length L Choose an initial population size

Generate length L strings of 1s & 0s randomly Sometimes (rarely) done more intelligently

Strings are sometimes called chromosomes Letters in the string are called “genes” Call the bit-string “individuals”

Page 9: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

GA Requirements A standard representation of the solution is as an array of

bits. Arrays of other types and structures can be used in essentially the same way.

The main property that makes these genetic representations convenient is that their parts are easily aligned due to their fixed size, that facilitates simple crossover operation.

Variable length representations may also be used, but crossover implementation is more complex in this case.

Page 10: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Representation

Chromosomes could be: Bit strings (0101 ... 1100) Real numbers (43.2 -33.1 ... 0.0 89.2) Permutations of element (E11 E3 E7 ... E1 E15) Lists of rules (R1 R2 R3 ... R22 R23) Program elements (genetic programming) ... any data structure ...

Page 11: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Fitness Fitness is an important concept in genetic algorithms. The fitness of a chromosome determines how likely it is

that it will reproduce. Fitness is usually measured in terms of how well the

chromosome solves some goal problem. E.g., if the genetic algorithm is to be used to sort numbers, then

the fitness of a chromosome will be determined by how close to a correct sorting it produces.

Page 12: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Calculating Fitness

Use a fitness function To assign a probability of each individual being used in the

mating process for the next generation

Usually use fitness(c) = g(c)/A Where A = average of g(c) over the entire population

Other constructions are possible

Page 13: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

The Selection Process

We are going to combine pairs of members of the current population to produce offspring So, we need to choose which pairs to combine

How many strings in schema S will be present in the next generation?

Selecting the individuals according to their fitness and applying genetic operators (recombination and point mutations) to selected chromosomes, generate the offspring population

Page 14: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Selection Methods In Tournament Selection, q individuals are randomly

selected from the population and the best of the q individuals is returned as a parent.

In roulette wheel selection, individuals are given a probability of being selected that is directly proportionate to their fitness. Individuals are then chosen randomly based on these probabilities and produce offspring.

Page 15: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Selection Methods In truncation selection individuals are sorted according to

their fitness. Only the best individuals are selected as parents to produce uniform at random offspring. The parameter for truncation selection is the truncation threshold Trunc. Trunc indicates the proportion of the population to be selected as parents and takes values ranging from 50%-10%. Individuals below the truncation threshold do not produce offspring. The term selection intensity is often used in truncation selection.

Page 16: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

The Recombination Process The population will only evolve to be better

If best parts of the best individuals are combined

Crossover techniques are used Which take material from each individual And adds it to “offspring” individuals

Mutation techniques are used Which randomly alter the offspring

Page 17: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Single-Point Crossover Crossover is applied 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.

Page 18: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Other types of Crossover Usually, crossover is applied with one crossover point, but

can be applied with more, such as in the following case which has two crossover points:

Uniform crossover involves using a probability to select which genes to use from chromosome 1, and which from chromosome 2, randomly copied from first or second parent

Page 19: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Inversion Another possible operator to mix things up

Takes the material from only on parent Randomly chooses two points

Takes the segment in-between the points Reverses it in the offspring

Example:

Page 20: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

The Mutation Process A unary operator – applies to one chromosome. Random mutation

Each bit in every offspring produced Is “flipped” from 0 to 1 or vice versa With a given probability (usually pretty small < 1%)

Could use probability distribution To protect the best individuals in population

Page 21: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Replacement Incorporates the new candidate solution into the original

population Replacement Approaches

Replace All Replace the entire original population with the offspring

Replace Worst Elitism is the name of the method that first copies the best

chromosome (or few best chromosomes) to the new population. The rest of the population is constructed in ways described above. Elitism can rapidly increase the performance of GA, because it prevents a loss of the best found solution.

Page 22: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

22

Termination Criteria A genetic algorithm is run over a number of generations

until the termination criteria are reached. Typical termination criteria are:

Stop after a fixed number of generations. Stop after a fixed amount of time Stop when a chromosome reaches a specified fitness level. Stop when a chromosome succeeds in solving the problem,

within a specified tolerance. Human judgment can also be used in some more

subjective cases.

Page 23: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Schematic Overview for Producing the Next Generation

Page 24: Genetic Algorithm. Introduction  Adaptive heuristic search algorithm based on evolutionary ideas of natural selection and genetics  Represent an intelligent

Slides Taken from Different Websites