Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

35
Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble

Transcript of Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Page 1: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Genetic Algorithms

Lecture 5

Addendum to the slides of Jason Noble

Page 2: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

NN II

NI

N I

NI

N I N I

NN NI NI II

Page 3: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Binary Genetic Algorithms

Variable Encoding and Decoding Generating a Population Generating Offspring:

Crossover Mutation Selection

Real chromosomes diploid GA almost always (haploid) exception will be

explicitly mentioned

Page 4: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Example (Haupt & Haupt, 2004)

Suppose we have a digital map of a mountain range

We want to find the highest peak on the map Automatically! Difficult problem for conventional optimization

techniques

Page 5: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Page 6: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Variable EncodingVariable Value Decimal Binary

Latitude

(min)

40o,15’ 1 0000000

Latitude

(max)

40o,16’ 128 1111111

Longitude

(min)

105036’ 1 0000000

Longitude

(max)

105037’30’’ 128 1111111

Chromosome =[11000110011001]

X y

Page 7: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Generate an Initial Population

00101111000110 12359

11100101100100 11872

00110010001100 13477

00101111001000 12363

11001111111011 11631

01000101111011 12097

11101100000001 12588

01001101110011 11860

Assign each chromosome a fitness (in this case simply the height of the point)

Page 8: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Selection (at 50% selection rate)

00101111000110 12359

00110010001100 13477

00101111001000 12363

11101100000001 12588

Selection:•Choose a selection rate•Choose a threshold (all above survive)

Page 9: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Assume random mating

00101111000110 12359

00110010001100 13477

00101111001000 12363

11101100000001 12588

Selection:•Choose a selection rate•Choose a threshold (all above survive)

Page 10: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Assume random mating

00101111000110 12359

00110010001100 13477

00101111001000 12363

11101100000001 12588

Selection:•Choose a selection rate•Choose a threshold (all above survive)

Page 11: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Crossover

00101111000110

00110010001100

00101111001000

11101100000001

Page 12: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Crossover

00101111000110

00110010001100

00101111001000

11101100000001

Crossover point

Page 13: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Crossover

00101111000110

00110010001100

00101111001000

11101100000001

Crossover point

Page 14: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Crossover

00101111000110

00110010001100

00101111001000

11101100000001

Crossover point

Page 15: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Crossover

00101111000110 00101100000001

00110010001100

00101111001000

11101100000001 11101111000110

Crossover point

Page 16: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Crossover

00101111000110 00101100000001

00110010001100

00101111001000

11101100000001 11101111000110

Crossover point

Page 17: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Crossover

00101111000110 00101100000001

00110010001100 00110111001000

00101111001000 00101010001100

11101100000001 11101111000110

Crossover point

Page 18: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

New generation (almost)

00101111000110 00101100000001

00110010001100 00110111001000

00101111001000 00101010001100

11101100000001 11101111000110

Crossover point

Page 19: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Mutation

00101111000110 00101100000001

00110010101100 00110111001000

00101111001000 00101010101100

11101100000001 11101111000110

Page 20: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Over the generations ….

Page 21: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Summary: Canonical Genetic Algorithm

S1: Set t= 0 S2: Initialize chromosome population P(t)

Usually by random init. S3: Evaluate P(t) by a fitness measure S4: while (termination not satisfied) do:

begin S4.1 Select for recombination chromosomes from P(t). Let P1

be the set of selected chromosomes. Choose individuals from P1 to enter the mating pool (MP)

S4.2 Recombine the chromosomes in MP forming P2. Mutate chromosomes in P2 forming P3

S4.3 Select for replacement from P3 and P(t) forming P(t+1) t = t + 1end

Page 22: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Generating offspring

Weighted random pairing (roulette wheel weighting)

Rank weighting Cost weighting

Equivalently allow a number of copies to mate (weighted)

Page 23: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Generating offspring

Roulette wheel selection How many copies take part in mating?

Rank weighting Cost weighting

http://www.edc.ncl.ac.uk/highlight/rhjanuary2007g02.php/

Page 24: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Roulette wheel weighting (1)

00110010001100 13477

11101100000001 12588

00101111000110 12359

00101111001000 12363

0.4 0.4

0.3 0.7

0.2 0.9

0.1 1.0

Rank weighting: assign distributions by rank, make sure that total probability is 1.0

pnΣpn

Page 25: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Roulette wheel weighting (2)

00110010001100 13477

11101100000001 12588

00101111001000 12363

00101111000110 12359

0.265 0.265

0.248 0.513

0.243 0.756

0.243 1.0

Fitness based weighting: assign distributions by fitness, make sure that total probability is 1.0

pnΣpn

Page 26: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Roulette wheel weighting (3)

00110010001100 13477-12097

= 1380

11101100000001 12588-12097 = 491

00101111001000 12363-12097

= 266

00101111000110 12359-12097 = 262

0.575 0.575

0.205 0.780

0.111 0.891

0.109 1.0

Cost based weighting: assign distributions by cost, make sure that total probability is 1.0

pnΣpn

Page 27: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Pairing offspring

Randomly Rank based (1-2) (3-4)

Prevents overly quick convergence Tournament:

Pick two chromosomes Set parameter k Generate random nr r If (r < k) pick fitter (eg. k = 0.75)

Elitism: always pick (a couple of) the best

Page 28: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Real valued chromosomes

In case of example: (x, y), where x and y are the spatial

coordinates Crossover

Discrete recombination Intermediate recombination Line recombination

Page 29: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Real valued chromosomesCrossover

Line recombination (122, 45, 77) and (3,4,3) Generate random positions:

(1,2,2) and (1,1,2) Results in:

(122, 4, 3) and (122, 45, 3)

Page 30: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Real valued chromosomes

Intermediate recombination Offspring = parent 1 + α(parent 2 – parent 1) Allow area to be slightly larger than hypercube

defined by parents Generate α for each position

Line recombination Use a single value for α

Page 31: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Genetic Programming(Koza, 1992,1994,…)

Example (Mitchell, 1998): Kepler’s law P2 = cA3, P orbital Period, A average distance

from sun

Programme for Mars:

Program Orb

// Mars

A = 1.52;

P = SQRT(A*A*A);

PRINT P

END

Page 32: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Genetic Programming

Lisp version(defun orbital_period ()

; Mars;

(setf A 1.52)

(sqrt (A A (* A A))))

Page 33: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Parse tree for LISP expression

SQRT

*

A *

A A

Page 34: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Koza’s algorithm

Trees consist of functions and terminals Choose a set of functions and terminals, e.g

{ +, -, *, /, √}; {A} Generate random programmes (trees) which

are syntactically correct Evaluate fitness Apply crossover (mutation)

Page 35: Genetic Algorithms Lecture 5 Addendum to the slides of Jason Noble.

Evolutionary Algorithms

Crossover

/

A /

/ /

A A A A

*

A -

* √

A A A

/

A /

/ /

√ A A A

*

A -

* A

A A

X

A