13 genetic algorithm

49
1 Genetic Algorithms “Genetic Algorithms are good at taking large, potentially huge search spaces and navigating them, looking for optimal combinations of things, solutions you might not otherwise find in a lifetime.” - Salvatore Mangano Computer Design, May 1995 Genetic Algorithms: Genetic Algorithms: Soft Computing Week 13 Soft Computing Week 13

Upload: nekolavigne

Post on 16-Jul-2016

239 views

Category:

Documents


2 download

DESCRIPTION

genetic algorithm, machine learning

TRANSCRIPT

Page 1: 13 Genetic Algorithm

1 Genetic Algorithms

“Genetic Algorithms are good at taking large,

potentially huge search spaces and navigating

them, looking for optimal combinations of things, solutions you might not

otherwise find in a lifetime.”

- Salvatore ManganoComputer Design, May 1995

Genetic Algorithms:Genetic Algorithms:Soft Computing Week Soft Computing Week

1313

Page 2: 13 Genetic Algorithm

2 Genetic Algorithms

The Genetic Algorithm Directed search algorithms based on

the mechanics of biological evolution Developed by John Holland, University

of Michigan (1970’s) To understand the adaptive processes of

natural systems To design artificial systems software that

retains the robustness of natural systems

Page 3: 13 Genetic Algorithm

3 Genetic Algorithms

The Genetic Algorithm (cont.)

Provide efficient, effective techniques for optimization and machine learning applications

Widely-used today in business, scientific and engineering circles

Page 4: 13 Genetic Algorithm

4 Genetic Algorithms

Evolution in the real world

Each cell of a living thing contains chromosomes - strings of DNA

Each chromosome contains a set of genes - blocks of DNA

Each gene determines some aspect of the organism (like eye colour)

A collection of genes is sometimes called a genotype

Page 5: 13 Genetic Algorithm

5 Genetic Algorithms

Evolution in the real world

A collection of aspects (like eye colour) is sometimes called a phenotype

Reproduction involves recombination of genes from parents and then small amounts of mutation (errors) in copying

The fitness of an organism is how much it can reproduce before it dies

Evolution based on “survival of the fittest”

Page 6: 13 Genetic Algorithm

6 Genetic Algorithms

Start with a Dream… Suppose you have a problem You don’t know how to solve it What can you do? Can you use a computer to somehow

find a solution for you? This would be nice! Can it be done?

Page 7: 13 Genetic Algorithm

7 Genetic Algorithms

A dumb solutionA “blind generate and test” algorithm:

RepeatGenerate a random possible solutionTest the solution and see how good it is

Until solution is good enough

Page 8: 13 Genetic Algorithm

8 Genetic Algorithms

Can we use this dumb idea?

Sometimes - yes: if there are only a few possible solutions and you have enough time then such a method could be used

For most problems - no: Too many possible solutions No time to try them all So this method can not be used

Page 9: 13 Genetic Algorithm

9 Genetic Algorithms

A “less-dumb” idea (GA)

Generate a set of random solutionsRepeat

Test each solution in the set (rank them)Remove some bad solutions from setDuplicate some good solutions

make small changes to some of them

Until best solution is good enough

Page 10: 13 Genetic Algorithm

10 Genetic Algorithms

How do you encode a solution?

Obviously this depends on the problem! GA’s often encode solutions as fixed length

“bitstrings” (e.g. 101110, 111111, 000101) Each bit represents some aspect of the

proposed solution to the problem For GA’s to work, we need to be able to

“test” any string and get a “score” indicating how “good” that solution is

Page 11: 13 Genetic Algorithm

11 Genetic Algorithms

Adding Sex - Crossover Although it may work for simple search

spaces our algorithm is still very simple It relies on random mutation to find a good

solution It has been found that by introducing “sex”

into the algorithm better results are obtained This is done by selecting two parents during

reproduction and combining their genes to produce offspring

Page 12: 13 Genetic Algorithm

12 Genetic Algorithms

Adding Sex - Crossover Two high scoring “parent” bit strings

(chromosomes) are selected and with some probability (crossover rate) combined

Producing two new offspring (bit strings) Each offspring may then be changed

randomly (mutation)

Page 13: 13 Genetic Algorithm

13 Genetic Algorithms

Selecting Parents Many schemes are possible so long as better

scoring chromosomes more likely selected Score is often termed the fitness “Roulette Wheel” selection can be used

Page 14: 13 Genetic Algorithm

14 Genetic Algorithms

Example populationNo. Chromosome Fitness1 1010011010 12 1111100001 23 1011001100 34 1010000000 15 0000010000 36 1001011111 57 0101010101 18 1011100111 2

Page 15: 13 Genetic Algorithm

15 Genetic Algorithms

Roulette Wheel Selection

1 2 3 1 3 5 1 2

0 18

21 3 4 5 6 7 8

Rnd[0..18] = 7

Chromosome4

Parent1

Rnd[0..18] = 12

Chromosome6

Parent2

Page 16: 13 Genetic Algorithm

16 Genetic Algorithms

Crossover - Recombination

1010000000

1001011111

Crossover single point -

random

1011011111

1010000000

Parent1

Parent2

Offspring1

Offspring2

With some high probability (crossover rate) apply crossover to the parents.

Page 17: 13 Genetic Algorithm

17 Genetic Algorithms

Mutation

1011011111

1010000000

Offspring1

Offspring2

1011001111

1000000000

Offspring1

Offspring2

With some small probability (the mutation rate) flip each bit in the offspring (typical values between 0.1

and 0.001)

mutate

Original offspring Mutated offspring

Page 18: 13 Genetic Algorithm

18 Genetic Algorithms

Back to the (GA) Algorithm

Generate a population of random chromosomes

Repeat (each generation) Calculate fitness of each chromosome Repeat

» Use roulette selection to select pairs of parents» Generate offspring with crossover and mutation

Until a new population has been produced Until best solution is good enough

Page 19: 13 Genetic Algorithm

19 Genetic Algorithms

Many Variants of GA Different kinds of selection (not roulette)

Tournament Elitism, etc.

Different recombination Multi-point crossover 3 way crossover etc.

Different kinds of encoding other than bitstring Integer values Ordered set of symbols

Different kinds of mutation

Page 20: 13 Genetic Algorithm

20 Genetic Algorithms

Many parameters to set Any GA implementation needs to decide on a

number of parameters: Population size (N), mutation rate (m), crossover rate (c)

Often these have to be “tuned” based on results obtained - no general theory to deduce good values

Typical values might be: N = 50, m = 0.05, c = 0.9

Page 21: 13 Genetic Algorithm

21 Genetic Algorithms

Why does crossover work?

A lot of theory about this and some controversy

Holland introduced “Schema” theory The idea is that crossover preserves “good

bits” from different parents, combining them to produce better solutions

A good encoding scheme would therefore try to preserve “good bits” during crossover and mutation

Page 22: 13 Genetic Algorithm

22 Genetic Algorithms

Classes of Search Techniques

F in on acci N ew ton

D irect m eth ods Indirec t m ethods

C alcu lu s-based tech n iques

Evolu tion ary s trategies

C entra l ized D istribute d

Pa ra l le l

S tea dy-s ta te G enera tiona l

Seque ntia l

G e ne tic a lgori thm s

Evolutiona ry a lgori thm s Sim u lated ann ealin g

G uide d random se arc h te chnique s

D yn am ic program m in g

Enu m erative tech n iqu es

Se arch te chniques

Page 23: 13 Genetic Algorithm

23 Genetic Algorithms

Components of a GAA problem to solve, and ... Encoding technique (gene, chromosome) Initialization procedure (creation) Evaluation function (environment) Selection of parents (reproduction) Genetic operators (mutation, recombination) Parameter settings (practice and art)

Page 24: 13 Genetic Algorithm

24 Genetic Algorithms

Simple Genetic Algorithm

{

initialize population;evaluate population;while TerminationCriteriaNotSatisfied{

select parents for reproduction;perform recombination and mutation;evaluate population;

}}

Page 25: 13 Genetic Algorithm

25 Genetic Algorithms

The GA Cycle of Reproduction

reproduction

population evaluation

modification

discard

deleted members

parents

children

modifiedchildren

evaluated children

Page 26: 13 Genetic Algorithm

26 Genetic Algorithms

Population

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 ...

population

Page 27: 13 Genetic Algorithm

27 Genetic Algorithms

Reproductionreproduction

population

parents

children

Parents are selected at random with selection chances biased in relation to chromosome evaluations.

Page 28: 13 Genetic Algorithm

28 Genetic Algorithms

Chromosome Modification

modificationchildren

Modifications are stochastically triggered Operator types are:

Mutation Crossover (recombination)

modified children

Page 29: 13 Genetic Algorithm

29 Genetic Algorithms

Evaluation

The evaluator decodes a chromosome and assigns it a fitness measure

The evaluator is the only link between a classical GA and the problem it is solving

evaluation

evaluatedchildren

modifiedchildren

Page 30: 13 Genetic Algorithm

30 Genetic Algorithms

Deletion

Generational GA:entire populations replaced with each iteration

Steady-state GA:a few members replaced each generation

population

discard

discarded members

Page 31: 13 Genetic Algorithm

31 Genetic Algorithms

An Abstract Example

Distribution of Individuals in Generation 0

Distribution of Individuals in Generation N

Page 32: 13 Genetic Algorithm

32 Genetic Algorithms

A Simple Example

“The Gene is by far the most sophisticated program around.”

- Bill Gates, Business Week, June 27, 1994

Page 33: 13 Genetic Algorithm

33 Genetic Algorithms

A Simple Example

The Traveling Salesman Problem:

Find a tour of a given set of cities so that each city is visited only once the total distance traveled is minimized

Page 34: 13 Genetic Algorithm

34 Genetic Algorithms

RepresentationRepresentation is an ordered list of citynumbers known as an order-based GA.

1) London 3) Dunedin 5) Beijing 7) Tokyo2) Venice 4) Singapore 6) Phoenix 8) Victoria

CityList1 (3 5 7 2 1 6 4 8)

CityList2 (2 5 7 6 8 1 3 4)

Page 35: 13 Genetic Algorithm

35 Genetic Algorithms

CrossoverCrossover combines inversion andrecombination: Parent1 (3 5 7 2 1 6 4 8)Parent2 (2 8 7 6 8 1 3 4)

Children1 (3 5 7 6 8 1 3 4)Children2 (2 8 7 2 1 6 3 4)

Page 36: 13 Genetic Algorithm

36 Genetic Algorithms

Mutation changing the list:

* *Before: (5 8 7 2 1 6 3 4)

After: (5 8 6 2 1 7 3 4)

Mutation

Page 37: 13 Genetic Algorithm

37 Genetic Algorithms

TSP Example: 30 Cities

0

10

20

30

40

50

60

70

80

90

100

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 38: 13 Genetic Algorithm

38 Genetic Algorithms

Solution i (Distance = 941)

TSP30 (Performance = 941)

0

10

20

30

40

50

60

70

80

90

100

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 39: 13 Genetic Algorithm

39 Genetic Algorithms

Solution j(Distance = 800)

TSP30 (Performance = 800)

0

10

20

30

40

50

60

70

80

90

100

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 40: 13 Genetic Algorithm

40 Genetic Algorithms

Solution k(Distance = 652)

TSP30 (Performance = 652)

0

10

20

30

40

50

60

70

80

90

100

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 41: 13 Genetic Algorithm

41 Genetic Algorithms

Best Solution (Distance = 420)

TSP30 Solution (Performance = 420)

0

10

20

30

40

50

60

70

80

90

100

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 42: 13 Genetic Algorithm

42 Genetic Algorithms

Overview of Performance

TSP30 - Overview of Performance

0

200

400

600

800

1000

1200

1400

1600

1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31

Generations (1000)

Dist

ance

Best

Worst

Average

Page 43: 13 Genetic Algorithm

43 Genetic Algorithms

Considering the GA Technology

“Almost eight years ago ... people at Microsoft wrote

a program [that] uses some genetic things for

finding short code sequences. Windows 2.0 and 3.2, NT, and almost

all Microsoft applications products have shipped

with pieces of code created by that system.” - Nathan Myhrvold, Microsoft Advanced

Technology Group, Wired, September 1995

Page 44: 13 Genetic Algorithm

44 Genetic Algorithms

Issues for GA Practitioners

Choosing basic implementation issues: representation population size, mutation rate, ... selection, deletion policies crossover, mutation operators

Termination Criteria Performance, scalability Solution is only as good as the evaluation

function (often hardest part)

Page 45: 13 Genetic Algorithm

45 Genetic Algorithms

Benefits of Genetic Algorithms

Concept is easy to understand Modular, separate from application Supports multi-objective optimization Good for “noisy” environments Always has an answer; answer gets

better with time

Page 46: 13 Genetic Algorithm

46 Genetic Algorithms

Benefits of Genetic Algorithms (cont.)

Many ways to speed up and improve a GA-based application as knowledge about problem domain is gained

Easy to exploit previous or alternate solutions

Flexible building blocks for hybrid applications

Substantial history and range of use

Page 47: 13 Genetic Algorithm

47 Genetic Algorithms

When to Use a GA Alternate solutions are too slow or overly

complicated Need an exploratory tool to examine new

approaches Problem is similar to one that has already been

successfully solved by using a GA Want to hybridize with an existing solution Benefits of the GA technology meet key problem

requirements

Page 48: 13 Genetic Algorithm

48 Genetic Algorithms

Some GA Application Types

Domain Application TypesControl gas pipeline, pole balancing, missile evasion, pursuit

Design semiconductor layout, aircraft design, keyboardconfiguration, communication networks

Scheduling manufacturing, facility scheduling, resource allocation

Robotics trajectory planning

Machine Learning designing neural networks, improving classificationalgorithms, classifier systems

Signal Processing filter design

Game Playing poker, checkers, prisoner’s dilemma

CombinatorialOptimization

set covering, travelling salesman, routing, bin packing,graph colouring and partitioning

Page 49: 13 Genetic Algorithm

49 Genetic Algorithms

Conclusions

Question: ‘If GAs are so smart, why ain’t they rich?’

Answer: ‘Genetic algorithms are rich - rich in application across a large and growing number of disciplines.’- David E. Goldberg, Genetic Algorithms in Search, Optimization and Machine Learning