59
Genetic Algorithms and Genetic Programming

Genetic Algorithms and Genetic Programming

  • Upload
    marly

  • View
    92

  • Download
    1

Embed Size (px)

DESCRIPTION

Genetic Algorithms and Genetic Programming. Evolutionary Computation. Computational procedures patterned after biological evolution Search procedure that probabilistically applies search operators to a set of points in the search space. Biological Evolution. Lamarck and others - PowerPoint PPT Presentation

Citation preview

Page 1: Genetic Algorithms and Genetic Programming

Genetic Algorithms and Genetic Programming

Page 2: Genetic Algorithms and Genetic Programming

Evolutionary Computation

1. Computational procedures patterned after biological evolution

2. Search procedure that probabilistically applies search operators to a set of points in the search space.

Page 3: Genetic Algorithms and Genetic Programming

Biological Evolution

• Lamarck and others– Species “transmute” over time

• Darwin and Wallace– Consistent heritable variation among individuals in the

population– Natural selection of the fittest

• Mendel and genetics– A mechanism for inheriting traits– genotype -> phenotype mapping

Page 4: Genetic Algorithms and Genetic Programming

Biological Terminology• gene

• functional entity that codes for a specific feature e.g. eye color• set of possible alleles

• allele• value of a gene e.g. blue, green, brown• codes for a specific variation of the gene/feature

• locus• position of a gene on the chromosome

• genome• set of all genes that define a species• the genome of a specific individual is called genotype• the genome of a living organism is composed of several chromosomes

• population• set of competing genomes/individuals

Page 5: Genetic Algorithms and Genetic Programming

Genotype versus Phenotype

• genotype• blue print that contains the information to construct an organism e.g. human DNA• genetic operators such as mutation and recombination modify the genotype during reproduction• genotype of an individual is immutable

(no Lamarckian evolution)• phenotype

• physical make-up of an organism• selection operates on phenotypes (Darwin’s principle : “survival of the fittest”

Page 6: Genetic Algorithms and Genetic Programming

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 7: Genetic Algorithms and Genetic Programming

The Genetic Algorithm (cont.)

• Provide efficient, effective techniques for optimization and machine learning applications

• Widely-used today in business, scientific and engineering circles

Page 8: Genetic Algorithms and Genetic Programming

Components of a GA

A 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 9: Genetic Algorithms and Genetic Programming

Genotype Operators

• recombination (crossover)• combines two parent genotypes into a new offspring• generates new variants by mixing existing genetic material• stochastic selection among parent genes

• mutation• random alteration of genes• maintain genetic diversity

• in genetic algorithms crossover is the major operator whereas mutation only plays a minor role

Page 10: Genetic Algorithms and Genetic Programming

Genotype space = {0,1}L

Phenotype space

Encoding (representation)

Decoding(inverse representation)

011101001

010001001

10010010

10010001

Representation

Page 11: Genetic Algorithms and Genetic Programming

Simple Genetic Algorithm{

initialize population;

evaluate population;

while TerminationCriteriaNotSatisfied{

select parents for reproduction;

perform recombination and mutation;

evaluate population;}

}

Page 12: Genetic Algorithms and Genetic Programming

The GA Cycle of Reproduction

reproduction

population evaluation

modification

discard

deleted members

parents

children

modifiedchildren

evaluated children

Page 13: Genetic Algorithms and Genetic Programming

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 14: Genetic Algorithms and Genetic Programming

Reproduction

reproduction

population

parents

children

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

Page 15: Genetic Algorithms and Genetic Programming

Chromosome Modification

modificationchildren

• Modifications are stochastically triggered• Operator types are:

– Mutation– Crossover (recombination)

modified children

Page 16: Genetic Algorithms and Genetic Programming

The simple GA

• Has been subject of many (early) studies– still often used as benchmark for novel GAs

• Shows many shortcomings, e.g.– Representation is too restrictive– Mutation & crossovers only applicable for bit-string &

integer representations– Selection mechanism sensitive for converging

populations with close fitness values– Generational population model (step 5 in SGA repr.

cycle) can be improved with explicit survivor selection

Page 17: Genetic Algorithms and Genetic Programming

Representing Hypotheses

Represent:(Outlook = Overcast v Rain) ^ (Wind = Strong)by

Outlook Wind011 10

Represent:IF Wind = Strong THEN PlayTennis = yesby

Outlook Wind PlayTennis011 10 10

Page 18: Genetic Algorithms and Genetic Programming

SGA operators: 1-point crossover

• Choose a random point on the two parents• Split parents at this crossover point• Create children by exchanging tails

• Pc typically in range (0.6, 0.9)

Page 19: Genetic Algorithms and Genetic Programming

SGA operators: mutation

• Alter each gene independently with a probability pm

• pm is called the mutation rate– Typically between 1/pop_size and 1/ chromosome_length

Page 20: Genetic Algorithms and Genetic Programming

Alternative Crossover Operators

• Performance with 1 Point Crossover depends on the order that variables occur in the representation

– more likely to keep together genes that are near each other

– Can never keep together genes from opposite ends of string

– This is known as Positional Bias

– Can be exploited if we know about the structure of our problem, but this is not usually the case

Page 21: Genetic Algorithms and Genetic Programming

n-point crossover

• Choose n random crossover points• Split along those points• Glue parts, alternating between parents• Generalisation of 1 point (still some positional bias)

Page 22: Genetic Algorithms and Genetic Programming

Uniform crossover

• Assign 'heads' to one parent, 'tails' to the other• Flip a coin for each gene of the first child• Make an inverse copy of the gene for the second child• Inheritance is independent of position

Page 23: Genetic Algorithms and Genetic Programming

Order 1 crossover

• Idea is to preserve relative order that elements occur• Informal procedure:

1. Choose an arbitrary part from the first parent

2. Copy this part to the first child

3. Copy the numbers that are not in the first part, to the first child:

• starting right from cut point of the copied part, • using the order of the second parent • and wrapping around at the end

4. Analogous for the second child, with parent roles reversed

Page 24: Genetic Algorithms and Genetic Programming

Order 1 crossover example• Copy randomly selected set from first parent

• Copy rest from second parent in order 1,9,3,8,2

Page 25: Genetic Algorithms and Genetic Programming

Crossover OR mutation?

• Decade long debate: which one is better / necessary / main-background

• Answer (at least, rather wide agreement):– it depends on the problem, but– in general, it is good to have both– both have another role– mutation-only-EA is possible, xover-only-EA would not work

Page 26: Genetic Algorithms and Genetic Programming

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 27: Genetic Algorithms and Genetic Programming

Selection Schemes• stochastic sampling

• roulette wheel selection• spin wheel N times

• stochastic universal sampling• roulette wheel selection• single spin, wheel has N equally spaced markers

• tournament selection• choose k candidates at random with uniform probability• pick best one for reproduction• expected number of offspring best : k , average k ½ k-1 , worst k 1/N k-1

Page 28: Genetic Algorithms and Genetic Programming

Replacement Schemes• generational replacement

• entire population is replaced each generation• non-overlapping population

100100100111001

SelectionCrossoverMutation

101110100001011

• steady state replacement• a single individual (worst, random) is replaced by one offspring• overlapping population

100100100111001

SelectionCrossoverMutation

10010010011100101110

Page 29: Genetic Algorithms and Genetic Programming

Deletion

• Generational GA:entire populations replaced with each iteration

• Steady-state GA:a few members replaced each generation

population

discard

discarded members

Page 30: Genetic Algorithms and Genetic Programming

An Abstract Example

Distribution of Individuals in Generation 0

Distribution of Individuals in Generation N

Page 31: Genetic Algorithms and Genetic Programming

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 32: Genetic Algorithms and Genetic Programming

Representation

Representation is an ordered list of city

numbers known as an order-based GA.

1) London 3) Dunedin 5) Beijing 7) Tokyo

2) 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 33: Genetic Algorithms and Genetic Programming

Crossover combines inversion and

recombination:

* *

Parent1 (3 5 7 2 1 6 4 8)

Parent2 (2 5 7 6 8 1 3 4)

Child (5 8 7 2 1 6 3 4)

This operator is called the Order1 crossover.

Crossover

Page 34: Genetic Algorithms and Genetic Programming

Mutation involves reordering of the list:

* *

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

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

Mutation

Page 35: Genetic Algorithms and Genetic Programming

TSP Example: 30 Cities

0

20

40

60

80

100

120

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 36: Genetic Algorithms and Genetic Programming

Solution i (Distance = 941)

TSP30 (Performance = 941)

0

20

40

60

80

100

120

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 37: Genetic Algorithms and Genetic Programming

Solution j(Distance = 800)44626967786462544250404038213567606040425099

TSP30 (Performance = 800)

0

20

40

60

80

100

120

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 38: Genetic Algorithms and Genetic Programming

Solution k(Distance = 652)

TSP30 (Performance = 652)

0

20

40

60

80

100

120

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 39: Genetic Algorithms and Genetic Programming

Best Solution (Distance = 420)42383526213532

73846445860697678716967628494

TSP30 Solution (Performance = 420)

0

20

40

60

80

100

120

0 10 20 30 40 50 60 70 80 90 100

x

y

Page 40: Genetic Algorithms and Genetic Programming

Overview of Performance

TSP30 - Overview of Performance

0

200

400

600

800

1000

1200

1400

1600

1800

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

Generations (1000)

Distance

BestWorstAverage

Page 41: Genetic Algorithms and Genetic Programming

Population Models

• SGA uses a Generational model:– each individual survives for exactly one generation– the entire set of parents is replaced by the offspring

• At the other end of the scale are Steady-State models:– one offspring is generated per generation,– one member of population replaced,

• Generation Gap – the proportion of the population replaced– 1.0 for GGA, 1/pop_size for SSGA

Page 42: Genetic Algorithms and Genetic Programming

GABIL [de Jong et al, 1993]

Learn disjunctive set of propositional rules; competitive with C4.5Fitness

Fitness(h) = (correct(h))2

Representation

IF a1=T ^ a2=F THEN c=T; IF a2=T THEN c=Frepresented by:

a1 a2 c a1 a2 c10 01 1 11 10 0

Genetic operators???– want variable length rule sets– want only well-formed bit-string hypotheses

Page 43: Genetic Algorithms and Genetic Programming

Crossover with variable-length bit-stringsStart with:

a1 a2 c a1 a2 c

h1 10 01 1 11 10 0

h1 01 11 0 10 01 0

• choose crossover points for h1, e.g. after bits 1, 8• now restrict points in h2 to those that produce bitstrings with well-

defined semantics, e.g. 〈 1,3 〉 , 〈 1,8 〉 , 〈 6,8 〉 .if we choose 〈 1,3 〉 , the results is:

a1 a2 c

h3: 11 10 0

a1 a2 c a1 a2 c a1 a2 c

h4: 00 01 1 11 11 0 10 01 0

Page 44: Genetic Algorithms and Genetic Programming

GABIL extensions

Add new genetic operators, also applied probabilistically:

1. AddAlternative: generalise constraint on a1 by changing a 0 to 1

2. DropCondition: generalise constraint on ai by changing every 0 to 1.

And, add new field to bitstring to determine whether to allow these:

a1 a2 c a1 a2 c AA DC 01 11 0 10 01 0 1 0

so now the learning strategy also evolves.

Page 45: Genetic Algorithms and Genetic Programming

GABIL Results

• Performance of GABIL comparable to symbolic rule/tree learning methods C4.5, ID5R, AQ14.

• Average performance on a set of 12 synthetic problems:– GABIL without AA and DC operators: 92.1%

accuracy– GABIL with AA and DC operators 95.2% accuracy– symbolic learning methods ranged from 91.2% to

96.6%

Page 46: Genetic Algorithms and Genetic Programming

Extensions to the Simple GA

Encoding schemes• gray encoding• messy genetic algorithms

Replacement schemes• generational replacement• steady state replacement

Fitness scaling• linear scaling• - truncation• ranking

Selection schemes• stochastic sampling• tournament selection

Page 47: Genetic Algorithms and Genetic Programming

• automatic generation of computer programs by means of natural evolution see Koza 1999• programs are represented by a parse tree (LISP expression)• tree nodes correspond to functions : - arithmetic functions {+,-,*,/} - logarithmic functions {sin,exp}• leaf nodes correspond to terminals : - input variables {X1, X2, X3} - constants {0.1, 0.2, 0.5 }

Genetic Programming

+

*

X3X2

X1

tree is parsed from left to right: (+ X1 (* X2 X3)) X1+(X2*X3)

Page 48: Genetic Algorithms and Genetic Programming

Genetic Programming : Crossover

+

*

X3X2

X1

-

/

X1-

X2

X3X2

parent A parent B

+ *

X3X2X1

-

/

X1-X2

X3X2

offspring A offspring B

Page 49: Genetic Algorithms and Genetic Programming

Block-Stacking ProblemNUAL S I R V E

RSAL

NIVE

U

• objective: place the blocks in the correct order such that the stack forms the word universal• functions: set of actions, logical operators, do-until loop• terminals: set of sensors that indicate top block on stack, next suitable block on table etc.• each program tree is tested on 166 different initial configurations• fitness: #configurations for which the stack was correct after program execution

stacktable

Page 50: Genetic Algorithms and Genetic Programming

Block-Stacking Problem

NUAL S I R V E

CSNN

Sensors:• CS: current stack, name of the top block of the stack• TB: top correct block, name of the topmost block on the stack such that it and all blocks underneath are in correct order• NN: next block needed, name of the block needed above TB

TB

Page 51: Genetic Algorithms and Genetic Programming

Block-Stacking Problem

NUAL I R V ES

MS NN

Functions:• MS(X): move block X to the top of the stack, return value X• MT(X): moves the block on top of the stack to the table if X is anywhere in the stack returns X• DU(exp1, exp2): execute exp1 until the predicate exp2 becomes true• NOT(exp1) : negation of expression exp1• EQ(exp1, exp2) : returns true if exp1 and exp2 are equal

SMS TB

N

Page 52: Genetic Algorithms and Genetic Programming

Block-Stacking Problem

N

UAL I R V ES

NNCSTB

• (EQ (MS NN) (EQ (MS NN) (MS NN))) move next needed block to the stack three times in a row (succeeds with a stack VERSAL and U N I on the table• (DU (MS NN) (NOT NN)) move next needed block to the stack until no more blocks are needed• (EQ (DU (MT CS) (NOT CS)) (DU (MS NN) (NOT NN))) empty the stack on the table and then build the stack in the correct order• (EQ (DU (MT CS) (EQ (CS TB))) (DU (MS NN) (NOT NN)))

Page 53: Genetic Algorithms and Genetic Programming

Learned Program

• Trained to fit 166 test problems

• Using population of 300 programs, found this after 10 generations:

(EQ (DU (MT CS)(NOT CS))(DU (MS NN)(NOT NN)))

Page 54: Genetic Algorithms and Genetic Programming

Genetic Programming

• More interesting example: design electronic filter circuits– individual are programs that transform beginning cct to final

cct, by adding/subtracting components and connections.– Use population of 640,000 run on 64 node parallel processor– Discover circuits competitive with best human desgn

Page 55: Genetic Algorithms and Genetic Programming

GP for classifying images

• Teller & Veloso, 1997• Fitness: based on coverage & accuracy• Representation:

– Primitives include Add, Sub, Mult, Div, Not, Max, Min, Read, Write, If-Then-Else, Either, Pixel, Least, Most, Ave, Variance, Difference, Mini, Library

– Mini refers to a local subroutine that is separately co-evolved– Library refers to a global library subroutine (evolved by

selecting the most useful minis)• Genetic operators:

– Crossover mutation– Create “mating pools” and use rank proportionate

reproduction.

Page 56: Genetic Algorithms and Genetic Programming

Biological Evolution

• Lamarck (19th century)– believed individual genetic makeup was

altered by lifetime experience– but current evidence contradicts this view

• What is the impact of individual learning on population evolution?

Page 57: Genetic Algorithms and Genetic Programming

Baldwin Effect

• Assume– individual learning has no direct influence on individual DNA– But ability to learn reduces need to “hard wire” traitsin DNA

• Then– Ability of individuals to learn will support more diverse gene

pool• because learning allow individuals with various “hard

wired” traits to be successful– More diverse gene pool will support faster evolution of gene

pool.– > individual learning (indirectly) increases rate of evolution.

Page 58: Genetic Algorithms and Genetic Programming

Baldwin Effect

Plausible example:1. New predator appears in the environment2. Individual who can learn (to avoid it) will

be selected3. Increase in learning individuals will

support more diverse gene pool4. resulting in faster evolution5. possibly resulting in new non-learned

traits such as instinctive fear of predator

Page 59: Genetic Algorithms and Genetic Programming

Computer experiements on Baldwin Effect• Evolve simple neural nets

– [Hinton & Nowlan, 1987]– some network weights fixed during lifetime, others trainable– genetic makeup determines which are fixed and their weight

values

• Results:– With no individual learning, population failed to improve over

time– when individual learning allowed

• early generations: population contained many individuals with many trainable weights

• later generations: higher fitness, while number of trainable weights decreased.