Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of...

28
Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search Encodings

Transcript of Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of...

Page 1: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Biologically Inspired Computing:

Introduction to Evolutionary Algorithms

This is lecture four of

`Biologically Inspired Computing’

Contents:

Local Search

Encodings

Page 2: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Typical Landscapes

As we home in on the good areas, we can identify broad types of Landscape feature. Most landscapes of interest are predominantly multimodal.Despite being locally smooth, they are globally rugged

Unimodal Plateau

Multimodal Deceptive

Page 3: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Beyond Hillclimbing

HC clearly has problems with typical landscapes:

There are two broad ways to improve HC, from the algorithm viewpoint:

1. Allow downhill moves – a family of methods called Local Search does this in various ways.

2. Have a population – so that different regions can be explored inherently in parallel – I.e. we keep `poor’ solutions around and give them a chance to `develop’.

Page 4: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Local Search

Initialise: Generate a random solution c; evaluate its fitness, f(s) = b; call c the current solution, and call b the best so far.

Repeat until termination conditon reached:1. Search the neighbourhood of c, and choose one, m Evaluate fitness of m, call that x.2. According to some policy, maybe replace c with x, and update c and b as appropriate.

E.g. Monte Carlo search: 1. same as hillclimbing; 2. If x is better, accept it as new current solution;if x is worse, accept it with someprobabilty (e.g. 0.1).

E.g. tabu search: 1. evaluate all immediate neighbours of c 2. choose the best from (1) to be the next current solution, unless it is`tabu’ (recently visited), in which choose the next best, etc.

Page 5: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Population-Based Search• Local search is fine, but tends to get stuck in local

optima, less so than HC, but it still gets stuck.• In PBS, we no longer have a single `current solution’,

we now have a population of them. This leads directly to the two main algorithmic differences between PBS and LS– Which of the set of current solutions do we mutate? We

need a selection method– With more than one solution available, we needn’t just

mutate, we can [mate, recombine, crossover, etc …] two or more current solutions.

• So this is an alternative route towards motivating our nature-inspired EAs – and also starts to explain why they turn out to be so good.

Page 6: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Basics of Encodings

Page 7: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Encoding / Representation

Maybe the main issue in (applying) ECNote that:• Given an optimisation problem to solve, we need

to find a way of encoding candidate solutions • There can be many very different encodings for

the same problem• Each way affects the shape of the landscape and

the choice of best strategy for climbing that landscape.

Page 8: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

E.g. encoding a timetable I

4, 5, 13, 1, 1, 7, 13, 2

• Generate any string of 8 numbers between 1 and 16, and we have a timetable! • Fitness may be <clashes> + <consecs> + etc …• Figure out an encoding, and a fitness function, and you can try to evolve solutions.

mon tue wed thur

9:00 E4, E5

E2 E3, E7

11:00

E8

2:00 E6

4:00 E1

Exam1 in 4th slotExam2 in 5th slot

Etc …

Page 9: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Mutating a Timetable with Encoding 1

4, 5, 13, 1, 1, 7, 13, 2

mon tue wed thur

9:00 E4, E5

E2 E3, E7

11:00

E8

2:00 E6

4:00 E1

Using straightforward single-gene mutation

Choose a random gene

Page 10: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Mutating a Timetable with Encoding 1

4, 5, 6 , 1, 1, 7, 13, 2

mon tue wed thur

9:00 E4, E5

E2 E7

11:00

E8 E3

2:00 E6

4:00 E1

Using straightforward single-gene mutation

One mutation changes position of one exam

Page 11: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Alternative ways to do it

This is called a `direct’ encoding. Note that:

• A random timetable is likely to have lots of clashes.

• The EA is likely (?) to spend most of its time crawling through clash-ridden areas of the search space.

• Is there a better way?

Page 12: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

E.g. encoding a timetable II

4, 5, 13, 1, 1, 7, 13, 2

mon tue wed thur

9:00 E4, E5

E2 E3, E7

11:00

E8

2:00 E6

4:00 E1

Use the 4th clash-free slot for exam1Use the 5th clash-free slot for exam2

Use the 13th clash-free slot for exam3

Etc …

Page 13: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

E.g. encoding a timetable III

H1, H3, H2, H2, H1, H1 …

mon tue wed thur

9:00 E4, E5

E2 E3, E7

11:00

E8

2:00 E6

4:00 E1

Use heuristic H1 to schedule exam1 (first fit)Use heuristic H3 to schedule exam2 (best fit based on consecs)

Use heuristic H2 to schedule exam3 (reduce future conflicts)

Etc …

Page 14: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

One of the very first applications. Determine the internal shape of a two-phase jet nozzle that can achieve the maximum possible thrust under given starting conditions

Ingo Rechenberg was the very first, with pipe-bend design

This is slightly later work in the same lab, by Schwefel

Starting point

EA (ES) runningResult

A recurring theme: design freedom entirely new and better designsbased on principles we don’t yet understand.

Page 15: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

A Real Encoding (and: How EAs can innovate, rather than just optimize)

D1, D2, D3, D4 D5 D6

D1 >= D2 >= D3, D4 <= D5 <= D6Fixed at six diameters, five sections

Page 16: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

E.g. How EAs can innovate, rather than just optimize

2, 1.8, 1.1, 1.3 1.3 1.5

D1 >= D2 >= D3, D4 <= D5 <= D6Fixed at six diameters, five sections

Page 17: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

E.g. How EAs can innovate, rather than just optimize

Z1, Z2, D1, D2, D3 Dsmall…, Dn, Dn+1, …

Middle section constrained to be smallest,That’s all Mutations can change diameters, add sections,and delete sections

Num sections before smallest

Num sections after smallest

Section diameters

Page 18: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Constructive Methods

Problems like timetabling, scheduling, and other `logistics’ activities are often `solved’ in practice via constructive heuristics, These are also called greedy heuristics. A constructive method is a technique that builds a single solution step by step, trying to be clever (often) about each step.

Page 19: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Examples

Prim’s algorithm for building the minimal spanning tree (see an earlier lecture) is an example.

Djikstra’s shortest path algorithm is also an example.

In both of these cases, the optimal solution is guaranteed to be found, since MST and SP are easy problems.

But usually we see constructive methods used to give very fast `OK’ solutions to hard problems.

Page 20: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

A constructive method for the TSP

Start with a random current city c; mark c as visited:Initialise Tour = {} (empty)Repeat ncities-1 times: choose, BTR, the closest unvisited city to c (call it d) add the edge cd to Tour mark d as visited Let d be the current city

Try it yourself a few times. Can you construct examples

where this will give a very poor result?

Page 21: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

A constructive method for exam timetabling

Repeat nexams times:

choose an exam, e, randomly.

let V be the set of valid timeslots for e – I.e.

slots it can go in without introducing a clash.

If V is empty, mark e as unplaced

Else choose random slot t from V, and assign e to t.

Is this how people do timetabling, or is there an even better way?

Page 22: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

A (usually) better constructive method for exam timetabling

Assign a difficulty score to each exam – e.g. this could be the number of other exams with which it clashes.

Repeat nexams times: choose an unscheduled exam e with highest difficulty,BTR. Find V, the set of slots it can go in without introducing a

clash. If V is empty, mark e as unplaced Else for each slot in V, find its usability score – e.g. the

number of unplaced exams that could go in that slot without introducing a clash

Choose a slot t with minimal usability score. Assign e to t.

Page 23: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Back to encoding …

We can use constructive methods as encodings in the following sort of way; this is sometimes called a `hybrid’ approach.

The EA searches through the space of orderings of items (e.g. exams to schedule, edges to put in a graph, etc…).

When evaluating fitness, a constructive method builds a solution using the ordering provided in the chromosome, and then evaluates fitness in the normal way.

Page 24: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Think about these things

How could you design a `smart’ mutation operator for the direct timetable encoding?

(hint – when you’ve randomly chosen a gene to mutate, can you do better than give it a random new slot?)

How could you design a smart mutation operator for the indirect timetable encoding?

(hint – hard)

Page 25: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Direct vs Indirect EncodingsDirect: • straightforward genotype (encoding) phenotype (individual) mapping• Easy to estimate effects of mutation• Fast interpretation of chromosome (hence speedier fitness evlaluation)

Indirect/Hybrid:• Easier to exploit domain knowledge – (e.g. use this in the constructive

heuristic)• Hence, possible to `encode away’ undesirable features• Hence, can seriously cut down the size of the search space• But, slow interpretation• Neighbourhoods are highly rugged.

Page 26: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

Back to Bin-PackingThe bin-packing encoding that you will use in your

assignment is a direct one.

But there are some well-known constructive heuristics for bin-packing: the following ones are used when the bins have fixed capaities, and the problem is to pack the items into the smallest number of bins:

First-fit-random (FFR):

Repeat nitems times:

Choose an item i randomly and place it in the

first bin in which it will fit.

First-fit-descending (FFD):

Order the items from heaviest to lightest (BTR)

For each item in order: place it into the first

bin in which it will fit.

How might you invent an indirect encoding for bin-packing?

Page 27: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

An important aside about constructive methods

Some Constructive Heuristics are deterministic. I.e. they give the same answer each time.

Some are stochastic – I.e. they may give a different solution in different runs.

Usually, if we have a deterministic constructive method such as FFD, we can engineer a stochastic version of it. E.g. instead of choosing the next-lightest item in each step, we might choose randomly between the lightest three unplaced items.

When applying EAs, it is often found that a stochastic constructive heuristic is very useful for building an initial population. But care has to be taken with such an approach – why?

Page 28: Biologically Inspired Computing: Introduction to Evolutionary Algorithms This is lecture four of `Biologically Inspired Computing’ Contents: Local Search.

This week’s additional material

Further encodings:

Grouping problems, Rules, Trees.