34
Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Embed Size (px)

Citation preview

Page 1: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Algorithms and their Applications

CS2004 (2012-2013)

13.1 Further Evolutionary Computation

Page 2: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 2

Recap – Genetic AlgorithmsGenetic Algorithms Genetic Algorithms (GA) are a powerful toolBased on the biological theory of evolutionThe correct use is down to experienceThe GA involves the iterative application of a number of genetic genetic operatorsoperatorsThere are a number of parameters that need to be carefully selected

Page 3: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 3

Holland’s AlgorithmInput: The GA parameters: NG, PS, CP, MP and n

The Fitness Function

1) Generate PS random Chromosomes of length n

2) For i = 1 to NG

3) Crossover Population, with chance CP per Chromosome

4) Mutate all the Population, with chance MP per gene

5) Kill off all Invalid Chromosomes

6) Survival of Fittest, e.g. Roulette Wheel

7) End For

Output: The best solution to the problem is the Chromosome in the last generation (the NGth population) which has the best fitness value

Page 4: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 4

The Parts of Holland’s AlgorithmInitial population

Create an initial population of random solutions to the problem

CrossoverPair up those allowed to breed and recombine genes from the parents to produce new children

MutationMutate some of the genes of some of the chromosomes

Kill off invalid chromosomesSurvival of the fittest

Select the fittest to survive to the next generation

Page 5: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 5

In This Lecture

We are going to look at:An application of Genetic AlgorithmsEvolutionary ProgrammingGenetic ProgrammingRelated Areas

Page 6: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 6

The Eight Queens (EQ) – Part 1

The problem is to place the eight Queens on a chess

board such that none of the Queens are attacking each

other

Page 7: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 7

The Eight Queens (EQ) – Part 2

Queens can attack in straight lines and diagonal lines

In the example below the Queens are attacking each

other

Page 8: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 8

The Eight Queens (EQ) – Part 3

In order to solve this problem using a Genetic Algorithm we need the following:

A representationA fitness functionParameter values

Page 9: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 9

EQ Representation – Part 1Only one queen on each row8 sets of 3 bits

0-7 for the column number the Queen occupies

Total of 24 bits Each set of 3 represents the row and then the position on that rowThere are no invalid chromosomes

Page 10: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 10

EQ Representation – Part 2

Representation Example

011000100110000111000101

Row 0 = 011 = 3Row 1 = 000 = 0Row 2 = 100 = 4Row 3 = 110 = 6Row 4 = 000 = 0Row 5 = 111 = 7Row 6 = 000 = 0Row 7 = 101 = 5

10 3 5 72 4 6

10

3

5

7

2

4

6

Page 11: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 11

EQ Fitness Function

The number of clashesThis is the total number of attacksMaximum number of attacks is 56

8×7Therefore the fitness function becomes 56 minus the number of attacks

For a maximisation problem

Page 12: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 12

EQ ParametersNG Number of Generations 100PS Population Size 100CP Crossover Probability 75%MP Mutation Probability 4%5 Chromosome Elitism

Page 13: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 13

EQ Implementation

C++Not Java – I did this a while ago!

STLGenetic algorithm templateRun on a above average specification desktop PC

Very slow by today's standardTakes a few seconds to run

Page 14: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 14

EQ Results – Part 1

37

42

47

52

57

0 10 20 30 40 50 60 70 80 90 100

Generations

Fitness

Average Fitness

Best Fitness

Page 15: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 15

EQ Results – Part 2

Page 16: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 16

EQ ConclusionNot the best method but it works!Other methods such as using a permutation based representation would be better

We will cover this laterHowever, the analysis of the intermediate results shows that “Knight Like”“Knight Like” moves are the key

Page 17: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 17

EC – IntroductionWe have looked at the Genetic Algorithms (GA)GAs belong to family of techniques that are inspired from evolution theoryThese methods come under the field of Evolutionary Computation

Evolutionary Programming (covered) Genetic Programming (covered) Evolutionary Strategies (not covered) Classifier Systems (not covered)

Page 18: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 18

Evolutionary Programming – Part 1

Evolutionary Programming (EP) is a similar approach to that of Genetic AlgorithmsThe emphasis is on mutationmutation and there is no crossovercrossoverEvery individual mutates, doubling the populationThe selection/survival operator tends to be Tournament SelectionTournament SelectionThe mutation operators tend to be complex and/or adaptive

Page 19: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 19

Evolutionary Programming – Part 2

The EP algorithm is as follows:

Input: Population size, number of generations

and Fitness Function

1) Create the initial population

2) For i = 1 to number of generations

3) Mutate the population

4) Apply Tournament Selection

5) End For

Output: Return the best individual

Page 20: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 20

Evolutionary Programming – Part 3

With Tournament selectionTournament selection, each member of the population is compared with a fixed number of other individualsFor each comparison, the individual is awarded a point if it’s fitness is better than the opponentThe population is reduced back to its original size by retaining those with the highest score

Page 21: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 21

Evolutionary Programming – Part 4

)2

1,0(~)

2

1,0(~

),0(

nN

nN

eNxx

i

iiiiii

Self-adapting parameters are a type of mutation

Each individual consists of a number of real genes, x1,…,xn

Each gene has an associated mutation parameter, σi

Note: e = 2.718 and that N(0,…) is the normal distribution

Page 22: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 22

Genetic Programming – Part 1Genetic ProgramsGenetic Programs are used to solve a problem that can be modelled as a grammar

For example: BNFIn this lecture, the technique that is of interest is Symbolic Symbolic RegressionRegression, which is a type of Genetic Programming Genetic Programming With symbolic regression, a mathematical expression is represented as a tree structure

Page 23: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 23

Genetic Programming – Part 2Terminal nodes within this tree are usually variablesNon terminals are operators (for example +,-,/,×) or functions (for example: logarithm)The fitness of such a tree is a function of the observed data versus the calculated data resulting from evaluating the expression the tree representsCrossover and mutation are redesigned to handle tree structuresThe genetic programming algorithm is virtually the same as the genetic algorithm

Page 24: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 24

Genetic Programming – Part 3

Consider the expression: x2+ln(10) -7.3x, then the tree representing this is:

+

-

ln

10

7.3 x

xx

Page 25: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 25

Genetic Programming – Part 4

GP Operator Description Sub-tree Exchange Crossover Two sub-trees are swapped between parents

Self Crossover Sub-trees are exchanged within an individual parent Point Mutation A node in the tree is changed to a different symbol

Permutation Mutation Two terminal symbols from the same sub-tree are swapped

Hoist Mutation A sub-tree creates a new individual Expansion Mutation A sub-tree is added to the base of a tree

Prune Mutation A sub-tree is removed Sub-tree Mutation A sub-tree is replaced for a random sub-tree

Some Genetic Programming Operators

Page 26: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 26

Related TechniquesParticle Swarm and Ant Colony Optimisation

This will be covered in a later lectureNatural ComputationArtificial LifeChaos TheoryComplexity Theory

Page 27: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 27

Particle Swarm and Ant Colony Optimisation

Particle Swarm OptimisationMultiple particles (solutions) form a swarm in the solution space (usually a Euclidean space)The particles cooperate by sharing information regarding good previous positions

Ant Colony OptimisationThis is where artificial ants are used to explore graph problems where they leave a pheromone trial along good paths for other ants to follow

Page 28: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 28

Natural ComputationNatural Computing Natural Computing refers to computation occurring in nature and computational techniques that are inspired by natureThis can aid in the understanding of natural processesBy studying computation in nature, these techniques can be applied to every day computational problems

Page 29: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 29

Artificial Life- Part 1Artificial Life is the simulation of life on a computerThe “Creatures” “Creatures” are often referred to as AgentsAgentsThese agents typically behave like biological creaturesEvolutionary computation can be used Examples are Cellular Automata Cellular Automata (game of life) and BoidsBoids

Page 30: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 30

Artificial Life- Part 2Let’s look at a Game of Life Game of Life demo.Which probably won’t work…

Page 31: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 31

Chaos Theory – Part 1A chaotic system is a system whose long term behaviour is unpredictable

Weather forecastingTiny changes in the starting state values rapidly lead to anywhere in the possible state space There can however be a finite number of available statesOften associated with non-linear equations such as the Mandlebrot Mandlebrot SetSet

Page 32: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 32

Chaos Theory – Part 2

Page 33: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Further Evolutionary Computation Slide 33

ComplexityThe interaction of many simple parts creating complex behaviourThe net effect is greater than the sum of the individuals, e.g. ant coloniesEmergent behaviour as a side effect of the systemOften incorporates elements of Chaos Theory, Artificial Life and Artificial Intelligence

Page 34: Algorithms and their Applications CS2004 (2012-2013) 13.1 Further Evolutionary Computation

Next LectureWe will be talking about:

Ant Colony OptimisationParticle Swarm Optimisation

The laboratory will involve applying a GA to another problem...

Slide 34Further Evolutionary Computation