105
Genetic Algorithms

Genetic Algorithms

Embed Size (px)

DESCRIPTION

Genetic Algorithms. Some Examples of Biologically Inspired AI. Neural networks Evolutionary computation (e.g., genetic algorithms) Immune-system-inspired computer/network security Insect- colony optimization (ants, bees, etc.) Slime-mould path-finding - PowerPoint PPT Presentation

Citation preview

Page 1: Genetic Algorithms

Genetic Algorithms

Page 2: Genetic Algorithms

Some Examples of Biologically Inspired AI

• Neural networks

• Evolutionary computation (e.g., genetic algorithms)

• Immune-system-inspired computer/network security

• Insect-colony optimization (ants, bees, etc.)

• Slime-mould path-finding

• Swarm intelligence (e.g., decentralized robots)

Page 3: Genetic Algorithms

Evolutionary Computation

• A population of candidate solutions evolves over time, with the fittest at each generation contributing the most offspring to the next generation

• Offspring are produced via crossover between parents, along with random mutations and other “genetic” operations.

A collection of computational methods inspired by

biological evolution:

Page 4: Genetic Algorithms

Evolution made simple

Essentials of Darwinian evolution:– Organisms reproduce in

proportion to their fitness in the environment

– Offspring inherit traits from parents

– Traits are inherited with some variation, via mutation and sexual recombination

Charles Darwin1809–1882

Page 5: Genetic Algorithms

Evolution made simple

Essentials of Darwinian evolution:– Organisms reproduce in

proportion to their fitness in the environment

– Offspring inherit traits from parents

– Traits are inherited with some variation, via mutation and sexual recombination

Essentials of evolutionary algorithms:– Computer “organisms”

(e.g., programs) reproduce in proportion to their fitness in the environment (e.g., how well they perform a desired task)

– Offspring inherit traits from their parents

– Traits are inherited, with some variation, via mutation and “sexual recombination”

Page 6: Genetic Algorithms

Appeal of ideas from evolution:

• Successful method of searching large spaces for good solutions (chromosomes / organisms)

• Massive parallelism

• Adaptation to environments, change

• Emergent complexity from simple rules

Page 7: Genetic Algorithms

Genetic Algorithms

Components of a GA:

• Population of candidate solutions to a given problem (“chromosomes”)

• Fitness function that assigns fitness to each chromosome in the population

• Selection procedure that selects individuals to reproduce

• Genetic operators that take existing chromosomes and produce offspring with variation (e.g., mutation, crossover)

Page 8: Genetic Algorithms

A Simple Genetic Algorithm

1. Start out with a randomly generated population of chromosomes (candidate solutions).

2. Calculate the fitness of each chromosome in the population.

3. Select pairs of parents with probability a function of fitness rank in the population.

4. Create new population: Cross over parents, mutate offspring, place in new population.

5. Go to step 2.

Page 9: Genetic Algorithms

Genetic operators

• Crossover: exchange subparts of two chromosomes:

0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 1 1

0 0 1 1 1 1 1 1 1 0 0 1 0 0 1 0 0 0

• Mutation: randomly change some loci:

0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0

Page 10: Genetic Algorithms

From Hornby et al., 2006

Evolvable hardware work at NASA Ames(Hornby, Lohn, et al.)

Page 11: Genetic Algorithms

From Hornby et al., 2006

Page 12: Genetic Algorithms

Example: Evolving Strategies for Robby the Robot

Sensors: N,S,E,W,C(urrent)

Actions:Move NMove SMove EMove WMove randomStay putTry to pick up can

Rewards/Penalties (points): Picks up can: 10 Tries to pick up can on

empty site: -1 Crashes into wall: -5

Page 13: Genetic Algorithms

Robby’s fitness function

Calculate_Fitness (Robby) { Total_Reward = 0 ; Average_Reward = 0 ‘ For i = 1 to NUM_ENVIRONMENTS {

generate_random_environment( ); /* .5 probability * to place can at * each site */

For j = 1 to NUM_MOVES_PER_ENVIRONMENT {Total_Reward = Total_Reward + perform_action(Robby);

} }

Fitness = Total_Reward / NUM_ENVIRONMENTS; return(Fitness);}

Page 14: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

1. Generate 200 random strategies (i.e., programs for controlling Robby)

Page 15: Genetic Algorithms

Random Initial Population

Page 16: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

1. Generate 200 random strategies (i.e., programs for controlling Robby)

2. For each strategy in the population, calculate fitness (average reward minus penalties earned on random environments)

Page 17: Genetic Algorithms

Fitness = Average final score from N moves on each of M random environments

Page 18: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

1. Generate 200 random strategies (i.e., programs for controlling Robby)

2. For each strategy in the population, calculate fitness (average reward minus penalties earned on random environments)

3. Strategies are selected according to fitness to become parents. (See code for choice of selection methods.)

Page 19: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

1. Generate 200 random strategies (i.e., programs for controlling Robby)

2. For each strategy in the population, calculate fitness (average reward minus penalties earned on random environments)

3. Strategies are selected according to fitness to become parents. (See code for choice of selection methods.)

4. The parents pair up and create offspring via crossover with random mutations.

Page 20: Genetic Algorithms

Parent 1:

Parent 2:

Page 21: Genetic Algorithms

Parent 1:

Parent 2:

Page 22: Genetic Algorithms

Parent 1:

Parent 2:

Child:

Page 23: Genetic Algorithms

Parent 1:

Parent 2:

Child:Mutate to “0”

Mutate to “4”

Page 24: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

1. Generate 200 random strategies (i.e., programs for controlling Robby)

2. For each strategy in the population, calculate fitness (average reward minus penalties earned on random environments)

3. Strategies are selected according to fitness to become parents. (See code for choice of selection methods.)

4. The parents pair up and create offspring via crossover with random mutations.

5. The offspring are placed in the new population and the old population dies.

Page 25: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

1. Generate 200 random strategies (i.e., programs for controlling Robby)

2. For each strategy in the population, calculate fitness (average reward minus penalties earned on random environments)

3. Strategies are selected according to fitness to become parents. (See code for choice of selection methods.)

4. The parents pair up and create offspring via crossover with random mutations.

5. The offspring are placed in the new population and the old population dies.

6. Keep going back to step 2 until a good-enough strategy is found!

Page 26: Genetic Algorithms

My hand-designed strategy:

“If there is a can in the current site, pick it up.”

“Otherwise, if there is a can in one of the adjacent sites,

move to that site.”

“Otherwise, choose a random direction to move in.”

Page 27: Genetic Algorithms

My hand-designed strategy:

“If there is a can in the current site, pick it up.”

“Otherwise, if there is a can in one of the adjacent sites,

move to that site.”

“Otherwise, choose a random direction to move in.”

Average fitness of this strategy: 346

(out of max possible 500)

Page 28: Genetic Algorithms

My hand-designed strategy:

“If there is a can in the current site, pick it up.”

“Otherwise, if there is a can in one of the adjacent sites,

move to that site.”

“Otherwise, choose a random direction to move in.”

Average fitness of this strategy: 346

(out of max possible 500)

Average fitness of GA evolved strategy: 486

(out of max possible 500)

Page 29: Genetic Algorithms

One Run of the Genetic AlgorithmB

est

fitne

ss in

pop

ulat

ion

Generation number

Page 30: Genetic Algorithms

Generation 1

Best fitness = 81

Page 31: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 0 Score: 0

Page 32: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 1 Score: 0

Page 33: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 2 Score: 5

Page 34: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 2 Score: 5

Page 35: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 3 Score: 10

Page 36: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 3 Score: 10

Page 37: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 4 Score: 15

Page 38: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 4 Score: 15

Page 39: Genetic Algorithms

Generation 14

Best fitness = 1

Page 40: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 0 Score: 0

Page 41: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 1 Score: 0

Page 42: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 2 Score: 0

Page 43: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 3 Score: 0

Page 44: Genetic Algorithms

Generation 200

Fitness = 240

Page 45: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 0 Score: 0

Page 46: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 1 Score: 0

Page 47: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 2 Score: 0

Page 48: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 3 Score: 10

Page 49: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 4 Score: 10

Page 50: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 5 Score: 20

Page 51: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 6 Score: 20

Page 52: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 7 Score: 20

Page 53: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 8 Score: 20

Page 54: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 9 Score: 20

Page 55: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 10 Score: 20

Page 56: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 11 Score: 20

Page 57: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 12 Score: 20

Page 58: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 13 Score: 20

Page 59: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 14 Score: 30

Page 60: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 15 Score: 30

Page 61: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 16 Score: 40

Page 62: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 17 Score: 40

Page 63: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 18 Score: 50

Page 64: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 19 Score: 50

Page 65: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 20 Score: 60

Page 66: Genetic Algorithms

Generation 1000

Fitness = 492

Page 67: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 0 Score: 0

Page 68: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 1 Score: 0

Page 69: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 2 Score: 10

Page 70: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 3 Score: 10

Page 71: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 4 Score: 20

Page 72: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 5 Score: 20

Page 73: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 6 Score: 20

Page 74: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 7 Score: 20

Page 75: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 8 Score: 20

Page 76: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 9 Score: 30

Page 77: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 10 Score: 30

Page 78: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 11 Score: 40

Page 79: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 12 Score: 40

Page 80: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 13 Score: 50

Page 81: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 14 Score: 50

Page 82: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 15 Score: 60

Page 83: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 16 Score: 60

Page 84: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 17 Score: 70

Page 85: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Time: 18 Score: 70

Page 86: Genetic Algorithms

Why Did The GA’s Strategy Outperform Mine?

Page 87: Genetic Algorithms

My Strategy

Page 88: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 89: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 90: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 91: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 92: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 93: Genetic Algorithms

The GA’s Evolved Strategy

Page 94: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 95: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 96: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 97: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 98: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 99: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 100: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 101: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 102: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 103: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 104: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 105: Genetic Algorithms

Robby Demo and Code