126
Genetic Algorithms Chapter 9, Complexity: A Guided Tour

Genetic Algorithms

  • Upload
    xannon

  • View
    32

  • Download
    1

Embed Size (px)

DESCRIPTION

Genetic Algorithms. Chapter 9, Complexity: A Guided Tour. Evolution by Natural Selection. Charles Darwin. Evolution by Natural Selection. Organisms inherit traits from parents. Charles Darwin. Evolution by Natural Selection. Organisms inherit traits from parents - PowerPoint PPT Presentation

Citation preview

Page 1: Genetic Algorithms

Genetic Algorithms

Chapter 9, Complexity: A Guided Tour

Page 2: Genetic Algorithms

Evolution by Natural Selection

Charles Darwin

Page 3: Genetic Algorithms

Evolution by Natural Selection

Charles Darwin

• Organisms inherit traits from parents

Page 4: Genetic Algorithms

Evolution by Natural Selection

Charles Darwin

• Organisms inherit traits from parents

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

Page 5: Genetic Algorithms

Evolution by Natural Selection

Charles Darwin

• Organisms inherit traits from parents

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

• Due to competition for limited resources, the organisms best adapted to the environment tend to produce the most offspring.

Page 6: Genetic Algorithms

Evolution by Natural Selection

Charles Darwin

• Organisms inherit traits from parents

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

• Due to competition for limited resources, the organisms best adapted to the environment tend to produce the most offspring.

• This way traits producing adapted individuals spread in the population

Page 7: Genetic Algorithms

Evolution by Natural Selection

• Organisms inherit traits from parents

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

• Due to competition for limited resources, the organisms best adapted to the environment tend to produce the most offspring.

• This way traits producing adapted individuals spread in the population

in computers

Computer (e.g., programs)

Charles Darwin

Page 8: Genetic Algorithms

Evolution by Natural Selection

• Organisms inherit traits from parents

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

• Due to competition for limited resources, the organisms best adapted to the environment tend to produce the most offspring.

• This way traits producing adapted individuals spread in the population

in computers

Computer (e.g., programs)

Charles Darwin

John Holland

Page 9: Genetic Algorithms

Evolution by Natural Selection

• Organisms inherit traits from parents

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

• Due to competition for limited resources, the organisms best adapted to the environment tend to produce the most offspring.

• This way traits producing adapted individuals spread in the population

in computers

Computer (e.g., programs)

Charles Darwin

John Holland

Genetic Algorithms (GAs)

Page 10: Genetic Algorithms

Some real-world uses of genetic algorithms

Page 11: Genetic Algorithms

Some real-world uses of genetic algorithms

• Used by GE to automate parts of aircraft design

Page 12: Genetic Algorithms

Some real-world uses of genetic algorithms

• Used by GE to automate parts of aircraft design

• Used by pharmaceutical companies to discover new drugs

Page 13: Genetic Algorithms

Some real-world uses of genetic algorithms

• Used by GE to automate parts of aircraft design

• Used by pharmaceutical companies to discover new drugs

• Used by the London Stock Exchange to automatically detect fraudulent trades

Page 14: Genetic Algorithms

Some real-world uses of genetic algorithms

• Used by GE to automate parts of aircraft design

• Used by pharmaceutical companies to discover new drugs

• Used by the London Stock Exchange to automatically detect fraudulent trades

• Used to generate realistic computer animation in the movies Lord of the Rings: The Return of the King and Troy

Page 15: Genetic Algorithms

Some real-world uses of genetic algorithms

• Used by GE to automate parts of aircraft design

• Used by pharmaceutical companies to discover new drugs

• Used by the London Stock Exchange to automatically detect fraudulent trades

• Used to generate realistic computer animation in the movies Lord of the Rings: The Return of the King and Troy

• Used to model and understand evolution in nature!

Page 16: Genetic Algorithms

Example: Evolving Strategies for Robby the

Robot

Page 17: Genetic Algorithms

Example: Evolving Strategies for Robby the

RobotInput: Contents of N, S, E, W,

C(Current)

Page 18: Genetic Algorithms

Example: Evolving Strategies for Robby the

RobotInput: Contents of N, S, E, W,

C(Current)

Possible actions:

Move N

Move S

Move E

Move W

Move random

Stay put

Try to pick up can

Page 19: Genetic Algorithms

Example: Evolving Strategies for Robby the

RobotInput: Contents of N, S, E, W,

C(Current)

Possible actions:

Move N

Move S

Move E

Move W

Move random

Stay put

Try 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 20: Genetic Algorithms

Example Strategy

Page 21: Genetic Algorithms

Encoding a Strategy

Code: MoveNorth = 0MoveSouth = 1MoveEast = 2MoveWest = 3StayPut = 4PickUpCan = 5MoveRandom = 6

Page 22: Genetic Algorithms

Encoding a Strategy

Code: MoveNorth = 0MoveSouth = 1MoveEast = 2MoveWest = 3StayPut = 4PickUpCan = 5MoveRandom = 6

Page 23: Genetic Algorithms

Encoding a Strategy

0

Code: MoveNorth = 0MoveSouth = 1MoveEast = 2MoveWest = 3StayPut = 4PickUpCan = 5MoveRandom = 6

Page 24: Genetic Algorithms

Encoding a Strategy

0 2

Code: MoveNorth = 0MoveSouth = 1MoveEast = 2MoveWest = 3StayPut = 4PickUpCan = 5MoveRandom = 6

Page 25: Genetic Algorithms

Encoding a Strategy

0 2 6

Code: MoveNorth = 0MoveSouth = 1MoveEast = 2MoveWest = 3StayPut = 4PickUpCan = 5MoveRandom = 6

Page 26: Genetic Algorithms

Encoding a Strategy

0 2 6 5 . . . 3 . . . 4

Code: MoveNorth = 0MoveSouth = 1MoveEast = 2MoveWest = 3StayPut = 4PickUpCan = 5MoveRandom = 6

Page 27: Genetic Algorithms

Encoding a Strategy

0 2 6 5 . . . 3 . . . 4

243 values

Code: MoveNorth = 0MoveSouth = 1MoveEast = 2MoveWest = 3StayPut = 4PickUpCan = 5MoveRandom = 6

Page 28: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

Page 29: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

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

Page 30: Genetic Algorithms

Random Initial Population

Page 31: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

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

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

Page 32: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

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

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

3. The strategies pair up and create offspring via “sexual recombination” with random mutations ― the fitter the parents, the more offspring they create.

Page 33: Genetic Algorithms

Parent 1:

Parent 2:

Page 34: Genetic Algorithms

Parent 1:

Parent 2:

Page 35: Genetic Algorithms

Parent 1:

Parent 2:

Child:

Page 36: Genetic Algorithms

Genetic algorithm for evolving strategies for Robby

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

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

3. The strategies pair up and create offspring via “sexual recombination” with random mutations ― the fitter the parents, the more offspring they create.

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

Page 37: Genetic Algorithms

My hand-designed strategy:

Page 38: Genetic Algorithms

My hand-designed strategy:

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

Page 39: 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.”

Page 40: 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 41: 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 42: 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 43: 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 44: Genetic Algorithms

One Run of the Genetic Algorithm

Bes

t fit

ness

in p

opul

atio

n

Generation number

Page 45: Genetic Algorithms

Generation 1

Best average score = 81

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: 0 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: 1 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: 2 Score: 5

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: 2 Score: 5

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: 3 Score: 10

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: 3 Score: 10

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: 4 Score: 15

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: 4 Score: 15

Page 54: Genetic Algorithms

Generation 10

Best average score = 0

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: 0 Score: 0

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: 1 Score: 0

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: 2 Score: 0

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: 3 Score: 0

Page 59: Genetic Algorithms

Generation 200

Fitness = 240

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: 0 Score: 0

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: 1 Score: 0

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: 2 Score: 0

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: 3 Score: 10

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: 4 Score: 10

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: 5 Score: 20

Page 66: 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 67: 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 68: 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 69: 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 70: 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 71: 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 72: 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 73: 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 74: 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 75: 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 76: 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 77: 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 78: 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 79: 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 80: 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 81: Genetic Algorithms

Generation 1000

Fitness = 492

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: 0 Score: 0

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: 1 Score: 0

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: 2 Score: 10

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: 3 Score: 10

Page 86: 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 87: 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 88: 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 89: 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 90: 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 91: 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 92: 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 93: 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 94: 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 95: 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 96: 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 97: 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 98: 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 99: 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 100: 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 101: Genetic Algorithms

Why Did The GA’s Strategy Outperform Mine?

Page 102: Genetic Algorithms

My Strategy

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

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 106: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 107: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 108: Genetic Algorithms

The GA’s Evolved Strategy

Page 109: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 110: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 111: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 112: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 113: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 114: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 115: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 116: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 117: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 118: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 119: Genetic Algorithms

0

1

2

3

4

5

6

7

8

9

0 1 2 3 4 5 6 7 8 9

Page 120: Genetic Algorithms

Principles of Evolution Seen in Genetic Algorithms

Page 121: Genetic Algorithms

Principles of Evolution Seen in Genetic Algorithms

• Natural selection works!

Page 122: Genetic Algorithms

Principles of Evolution Seen in Genetic Algorithms

• Natural selection works!

• Evolution proceeds via periods of stasis “punctuated” by periods of rapid innovation

Page 123: Genetic Algorithms

Principles of Evolution Seen in Genetic Algorithms

• Natural selection works!

• Evolution proceeds via periods of stasis “punctuated” by periods of rapid innovation

Bes

t fit

ness

in p

opul

atio

n

Generation number

Page 124: Genetic Algorithms

Principles of Evolution Seen in Genetic Algorithms

• Natural selection works!

• Evolution proceeds via periods of stasis “punctuated” by periods of rapid innovation

• Exaptation is common

Page 125: Genetic Algorithms

Principles of Evolution Seen in Genetic Algorithms

• Natural selection works!

• Evolution proceeds via periods of stasis “punctuated” by periods of rapid innovation

• Exaptation is common

• Co-evolution speeds up innovation

Page 126: Genetic Algorithms

Principles of Evolution Seen in Genetic Algorithms

• Natural selection works!

• Evolution proceeds via periods of stasis “punctuated” by periods of rapid innovation

• Exaptation is common

• Co-evolution speeds up innovation

• Dynamics and results of evolution are unpredictable and hard to analyze