15.053 tuesday, may 14

43
1 15.053 Tuesday, May 14 Genetic Algorithms Handouts: Lecture Notes Question: when should there be an additional review session?

Upload: milek

Post on 15-Jan-2016

41 views

Category:

Documents


0 download

DESCRIPTION

15.053 Tuesday, May 14. Genetic Algorithms. Handouts: Lecture Notes Question: when should there be an additional review session?. The basic genetic algorithm. Developed by John Holland in 1975 Simulates the process of evolution - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 15.053                 Tuesday, May 14

1

15.053 Tuesday, May 14

• Genetic Algorithms

Handouts: Lecture Notes

Question: when should there be an additional review session?

Page 2: 15.053                 Tuesday, May 14

2

The basic genetic algorithm

• Developed by John Holland in 1975

• Simulates the process of evolution

• Basic Principle: Evolution can be viewed as an optimizing process

Page 3: 15.053                 Tuesday, May 14

3

More on physical analogies

• Physical Analogies as a guiding principle for optimization problems – Genetic Algorithms • John Holland 1975 – Simulated Annealing • Kirkpatrick – Ant Colony Systems

Page 4: 15.053                 Tuesday, May 14

4

The basic genetic algorithm

• Loosely modeled on natural selection with a touch of molecular biology thrown in.

• Fitter individuals mate [selection operator].

• The chromosomes of each child are formed as a mixture of the chromosomes of the parents [crossover operator].

• Mutation adds diversity within the species and a greater scope for improvement [mutation operator].

• Chromosomes encode the relevant information.

Page 5: 15.053                 Tuesday, May 14

5

GA terms

chromosome(solution)

gene

(variable)

alleles

(values)

selection

crossover

mutation

population Objective: maximize fitness function

(objective function)

Page 6: 15.053                 Tuesday, May 14

6

Selection Operator:

Selects two parents from the population for mating.The selection is biased towards fitter individuals.

Crossover Operator:

Each child is obtained as a random mixture of itsparents using a crossover operation.

Mutation Operator:

At times an individual in the population undergoes a random mutation.

Page 7: 15.053                 Tuesday, May 14

7

A Simple Example: Maximize the number of 1’s

• Initial Population Fitness

• 1 1 1 0 1 4• 0 1 1 0 1 3• 0 0 1 1 0 2• 1 0 0 1 1 3

• Average fitness 3 Usually populations are much bigger, say around 50 to 100, or more.

Page 8: 15.053                 Tuesday, May 14

8

Crossover Operation: takes two solutions andcreates a child (or more) whose genes are amixture of the genes of the parents.

parent 1 parent 2

0 1 1 0 1 1 0 0 1 1

Select two parentsfrom thepopulation.

This is theselection step.There will bemore on this later.

Page 9: 15.053                 Tuesday, May 14

9

Crossover Operation: takes two solutions andcreates a child (or more) whose genes are amixture of the genes of the parents.

parent 1 parent 2

0 1 1 0 1 1 0 0 1 1

1 point crossover: Divide each parent into twoparts at the same location k (chosen randomly.)

Child 1 consists of genes 1 to k-1 from parent 1and genes k to n from parent 2. Child 2 is the“reverse”.

child 1 child 2 0 1 1 1 1 1 0 0 0 1

Page 10: 15.053                 Tuesday, May 14

10

Selection Operator

• Think of crossover as mating• Selection biases mating so that fitter parents are more likely to mate.

For example, let the probability of selectingmember j be fitness(j)/total fitness

Example:

1. 1 1 1 0 1 4

2. 0 1 1 0 1 3

3. 0 0 1 1 0 2

4. 1 0 0 1 1 3

Total fitness 12

Prob(1) = 4/12 = 1/3

Prob(3) = 2/12 = 1/6

Page 11: 15.053                 Tuesday, May 14

11

Example with Selection and Crossover Only

original after 5 after 10 generations generations

1 0 0 1 1 1 1 0 1 1 1 1 0 1 10 1 0 0 0 1 0 1 1 1 1 0 0 1 10 0 0 0 1 1 1 0 1 1 1 1 0 1 11 1 1 1 1 1 1 0 1 1 1 1 0 1 1. . .0 0 1 0 0 1 1 0 1 1 1 1 0 1 11 1 0 1 1 1 1 0 1 1 1 1 0 1 1

2.8000 3.7000 3.9000

Page 12: 15.053                 Tuesday, May 14

12

Mutation

• Previous difficulty: important genetic variability was lost from the population

• Idea: introduce genetic variability into the population through mutation

• simple mutation operation: randomly flip q% of the alleles (bits) in the population.

Page 13: 15.053                 Tuesday, May 14

13

Previous Example with a 1% mutation rate

original after 5 after 10 generations generations

1 0 0 1 1 1 1 0 1 1 1 1 1 1 10 1 0 0 0 1 1 1 1 1 1 1 1 1 10 0 0 0 1 1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1. . .1 0 0 0 1 0 1 1 1 1 1 1 1 1 10 0 1 0 0 1 1 1 1 1 1 1 1 1 11 1 0 1 1 1 1 1 1 1 1 1 1 1 1

2.8000 4.8000 4.9000

Page 14: 15.053                 Tuesday, May 14

14

Representations of Operators

illustrated on a bit-based representation

Selection Crossover Mutation

Page 15: 15.053                 Tuesday, May 14

15

The basic genetic algorithm

• define the representation – how the solution is represented

• define “fitness” function – objective function

• define the operators – initialization, crossover, mutation

initialize population

select two parents

create 1 or 2children

mutate population

modify population

should we stop orgo on?

finish

Page 16: 15.053                 Tuesday, May 14

16

Generation based GAs

In generation basedGA’s we createchildren onegeneration at a time.

Take the entirepopulation of n andcreate n/2 sets ofparents usingselection.

Page 17: 15.053                 Tuesday, May 14

17

Generation based GAs

Then create twochildren from eachparent.

Page 18: 15.053                 Tuesday, May 14

18

Generation based GAs

Thenreplace theoriginalpopulationby thechildren

Page 19: 15.053                 Tuesday, May 14

19

Generation based GAs

This creates the nextgeneration. Theniterate

Page 20: 15.053                 Tuesday, May 14

20

Steady-State based GAs

In steady state GA’swe create one child atat time, and thenreplace one memberof the population withthe new child.

Page 21: 15.053                 Tuesday, May 14

21

Steady-State based GAs

Select twoparents. Thencreate a child.

Page 22: 15.053                 Tuesday, May 14

22

Steady-State based GAs

Then replace amember of thepopulation withthe new child.

Page 23: 15.053                 Tuesday, May 14

23

Steady-State based GAs

Repeat thisprocess, andoccasionallyform amutation.

Page 24: 15.053                 Tuesday, May 14

24

Steady-State Genetic Algorithm

begin obtain initial population repeat select two individuals I1 and I2; apply the crossover operator on I1 and I2

to produce a child I3; replace a member of the population with I3 or discard I3; (often a parent is replaced) occasionally perform a mutation or an immigration; until the population converges;end;

Page 25: 15.053                 Tuesday, May 14

25

Encoding Schemes (These can be tricky forcombinatorial problems)

• How does one encode a tour on n cities?

• Representation 1: the cities in order

• Representation 2: the list of “next cities”

Page 26: 15.053                 Tuesday, May 14

26

How does one do a crossover?

• It’s very difficult in this case. It’s not clear how to mix two tours.

• People in the GA community have often relied on ad hoc methods, and have not been so successful.

You can’t take half of one tour and half of another

Page 27: 15.053                 Tuesday, May 14

27

How does one do a crossover?

• Standard rule: find something that works. – Example: visit the first k cities in the order that they appear on the first tour, and then visit the remaining cities in the order that they appear on the second tour.

Page 28: 15.053                 Tuesday, May 14

28

Random Keys Representation• A chromosome consists of n integers from 0 to K – in our example, K = 100• By sorting the n integers, one can obtain an order

Here are the “random keys” for cities 1 to 9

This is the order obtained by taking cities inorder of their random keys.

Page 29: 15.053                 Tuesday, May 14

29

A crossover using random keys

parent 1

parent 2

Select a key from one of the two parent (randomly)

Page 30: 15.053                 Tuesday, May 14

30

parent 1

parent 2

child

Page 31: 15.053                 Tuesday, May 14

31

An alternative crossover that relies ona randomized algorithm

• The random insertion algorithm Choose three cities randomly and obtain a tour T on the cities For k = 4 to n, choose a city that is not on T and insert it optimally into T.

• Representation: use random keys. In other words select cities to insert in the order that they appear in random keys

Page 32: 15.053                 Tuesday, May 14

32

Choose the 3 cities with smallest keys,and create a tour on these cities.

Page 33: 15.053                 Tuesday, May 14

33

Find the city with next smallestkey, and insert it.

Page 34: 15.053                 Tuesday, May 14

34

Find the city with next smallest key,and insert it.

Page 35: 15.053                 Tuesday, May 14

35

Find the city with next smallest key,and insert it.

Page 36: 15.053                 Tuesday, May 14

36

Find the city with next smallest key,and insert it.

Page 37: 15.053                 Tuesday, May 14

37

Find the city with next smallest key,and insert it.

Page 38: 15.053                 Tuesday, May 14

38

Insert the 8th city

Page 39: 15.053                 Tuesday, May 14

39

Insert the last city

Page 40: 15.053                 Tuesday, May 14

40

The tour associated with the randomkeys using insertion.

Page 41: 15.053                 Tuesday, May 14

41

GAs Nbhd Search• Population• Fitness function• Mutation Operator (operates on single solutions)• Crossover Operator (creates random child from two parents)• Selection operator (bias towards fitter individuals)• Important use of randomization

• One solution at a time• Objective function

• Neighborhood operator

• Local search: always look for an improvement.

• Usually does not rely on randomization

Page 42: 15.053                 Tuesday, May 14

42

GAs since 1975

• GAs started with 1-point crossover, bit flipping for mutation, and a generational scheme.

• GAs have evolved a lot since then – Lots of approaches for representations, for mutations, for crossover, for combining multiple heuristics, … – It’s no longer obvious what is or is not a genetic algorithm.

Page 43: 15.053                 Tuesday, May 14

43

Features of Genetic Algorithms

• GAs seem to work best in problems in which the function is very complex, and feasibility is easy to achieve.

• GA implementation is still an art. They often require a lot of tweaking, then again sometimes you can tweak all you want and they will still find the same result.

• Easy to make parallel

• Easy to get started and get an approach that is working

• Often requires lots of effort to make it work well.