Docsity

Genetic Algorithm Example By Hand-Computational Physics-Lecture Slides, Slides of Computational Physics

Partial preview of the text

Download Genetic Algorithm Example By Hand-Computational Physics-Lecture Slides and more Slides Computational Physics in PDF only on Docsity!

Genetic Algorithm: Example by Hand

  • Now that we have an understanding of the various parts of a GA

let’s evolve a simple GA (SGA) by hand.

  • A SGA is :
    • binary-coded,
    • Uses proportionate selection
    • uses single-point crossover (with a crossover usage rate between 0.6- 1.0),
    • uses a small mutation rate, and
    • is generational.

Genetic Algorithms: Example

• The SGA for our example will use:

  • A population size of 6,
  • A crossover usage rate of 1.0, and
  • A mutation rate of 1/7.

• Let’s try to solve the following problem

  • f(x) = x^2 , where -2.0  x  2.0,
  • Let l = 7, therefore our mapping function will be
    • _d(2,-2,7,c) = 4decode(c)/127 - 2_*

An Example (by hand):

An Example (by hand):

  • Select Six Parents Using the Roulette Wheel

Genotype Phenotype Fitness

Person 6: 0001101 - 1.591 Fit: 2.

Person 3: 1101010 1.339 Fit: 1.

Person 5: 1001111 0.488 Fit: 0.

Person 6: 0001101 - 1.591 Fit: 2.

Person 2: 0100101 - 0.835 Fit: 0.

Person 1: 1001010 0.331 Fit: 0.

An Example (by hand):

  • Create Offspring 3 & 4

Genotype Phenotype Fitness

Person 5: 1011|111 0.488 Fit: 0.

Person 6: 0001|101 - 1.591 Fit: 2.

Child 3 : 1011|101 0.898 Fit:?

Child 4 : 0001|111 - 1.654 Fit:?

An Example (by hand):

  • Create Offspring 5 & 6

Genotype Phenotype Fitness

Person 2: 010|0101 - 0.835 Fit: 0.

Person 1: 100|1010 0.331 Fit: 0.

Child 5 : 010|1010 1.339 Fit:?

Child 6 : 100|0101 0.677 Fit:?

An Example (by hand):

Is Replaced by:

  • • Evaluate Population at t=
    • Person 1: 1001010 0.331 Fit: 0. Genotype Phenotype Fitness
    • Person 2: 0100101 - 0.835 Fit: 0.
    • Person 3: 1101010 1.339 Fit: 1.
    • Person 4: 0110110 - 0.300 Fit: 0.
    • Person 5: 1001111 0.488 Fit: 0.
    • Person 6: 0001101 - 1.591 Fit: 2.
  • Population at t=
    • Person 1: 1001010 0.331 Fit: 0. Genotype Phenotype Fitness
    • Person 2: 0100101 - 0.835 Fit: 0.
    • Person 3: 1101010 1.339 Fit: 1.
    • Person 4: 0110110 - 0.300 Fit: 0.
    • Person 5: 1001111 0.488 Fit: 0.
    • Person 6: 0001101 - 1.591 Fit: 2.
    • Child 1 : 0001010 - 1.685 Fit: 2. Genotype Phenotype Fitness
    • Child 2 : 1101101 1.433 Fit: 2.
    • Child 3 : 1011100 0.898 Fit: 0.
    • Child 4 : 0001011 - 1.654 Fit: 2.
    • Child 5 : 1101010 1.339 Fit: 1.
    • Child 6 : 1010101 0.677 Fit: 0.
  • • Population at t= An Example (by hand):
    • Person 1: 0001010 - 1.685 Fit: 2. Genotype Phenotype Fitness
    • Person 2: 1101101 1.433 Fit: 2.
    • Person 3: 1011100 0.898 Fit: 0.
    • Person 4: 0001011 - 1.654 Fit: 2.
    • Person 5: 1101010 1.339 Fit: 1.
    • Person 6: 1010101 0.677 Fit: 0.

Genetic Algorithms:

An Example Run (Steady-State GA)

  • Randomly Generate an Initial Population

Genotype Phenotype Fitness Person 1: 1001010 0.331 Fit:? Person 2: 0100101 - 0.835 Fit:? Person 3: 1101010 1.339 Fit:? Person 4: 0110110 - 0.300 Fit:? Person 5: 1001111 0.488 Fit:? Person 6: 0001101 - 1.591 Fit:?

Genetic Algorithms:

An Example Run (Steady-State GA)

  • Evaluate Population at t=

Genotype Phenotype Fitness Person 1: 1001010 0.331 Fit: 0. Person 2: 0100101 - 0.835 Fit: 0. Person 3: 1101010 1.339 Fit: 1. Person 4: 0110110 - 0.300 Fit: 0. Person 5: 1001111 0.488 Fit: 0. Person 6: 0001101 - 1.591 Fit: 2.

Genetic Algorithms:

An Example Run (Steady-State GA)

  • Evaluate the Offspring

Genotype Phenotype Fitness Child 1 : 0001010 - 1.685 Fit: 2. Child 2 : 1101101 1.433 Fit: 2.

Genetic Algorithms:

An Example Run (Steady-State GA)

  • Find the two worst individuals to be replaced

Genotype Phenotype Fitness Person 1: 1001010 0.331 Fit: 0. Person 2: 0100101 - 0.835 Fit: 0. Person 3: 1101010 1.339 Fit: 1. Person 4: 0110110 - 0.300 Fit: 0. Person 5: 1001111 0.488 Fit: 0. Person 6: 0001101 - 1.591 Fit: 2.

Genetic Algorithms:

An Example Run (Steady-State GA)

  • This process of:
    • Selecting two parents,
    • Allowing them to create two offspring, and
    • Immediately replacing the two worst individuals in the population with the offspring
  • Is repeated until a stopping criterion is reached
  • Notice that on each cycle the steady-state GA will make two function evaluations while a generational GA will make P (where P is the population size) function evaluations.
  • Therefore, you must be careful to count only function evaluations when comparing generational GAs with steady-state GAs.

Genetic Algorithms: Additional Properties

  • Generation Gap: The fraction of the population that is replaced each cycle. A generation gap of 1.0 means that the whole population is replaced by the offspring. A generation gap of 0.01 (given a population size of 100) means ______________.
  • Elitism: The fraction of the population that is guaranteed to survive to the next cycle. An elitism rate of 0.99 (given a population size of 100) means ________99 will survive_in next cycle__ and an elitism rate of 0. means ___________only one will survive in next cycle____.