introduction to genetic algorithm - niordckarafarin.niordc.ir/uploads/94_79_ga.pdf§§genetic...

47
Introduction to Introduction to Genetic Algorithm Genetic Algorithm By: J. Ivakpour

Upload: vuongphuc

Post on 23-May-2018

256 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Introduction toIntroduction toGenetic AlgorithmGenetic Algorithm

By: J. Ivakpour

Page 2: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Introduction to GAIntroduction to GA§§ IntroductionIntroduction§§ OverviewOverview§§ TerminologyTerminology§§ Designing of GADesigning of GA§§ GA’s OperatorsGA’s Operators§§ ExampleExample§§ Genetic ProgrammingGenetic Programming§§ ConclusionConclusion§§ ReferencesReferences

Page 3: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

33

locallocal

globalglobal

introduction to GA to GAintroduction to GA to GA: Hill Climbing: Hill Climbing

Page 4: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ MultiMulti--climbersclimbers

introduction to GA to GAintroduction to GA to GA: Hill Climbing: Hill Climbing

Page 5: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ Genetic algorithmGenetic algorithm

I am not at the top.I am not at the top.My high is better!My high is better!

I am at theI am at thetoptop

Height is ...Height is ...

I will continueI will continue

introduction to GA to GAintroduction to GA to GA: GA: GA

Page 6: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ Genetic algorithmGenetic algorithm -- few microseconds afterfew microseconds after

introduction to GAintroduction to GA: GA: GA

Page 7: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ A class of probabilistic optimizationA class of probabilistic optimizationalgorithmsalgorithms§§ Inspired by the biological evolution processInspired by the biological evolution process§§ Uses concepts of “Natural Selection” andUses concepts of “Natural Selection” and

“Genetic Inheritance” (Darwin“Genetic Inheritance” (Darwin 18591859))§§ Originally developed by John Holland (Originally developed by John Holland (19751975))

introduction to GAintroduction to GA: OVERVIEW: OVERVIEW

Page 8: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

v Goal of natural evolution – to generate a population ofindividuals with increasing fitness (increasing ability to survive andreproduce in a specific environment)

v Evolutionary computation simulates the natural evolution on acomputer

v Goal of evolutionary computation - to generate a set ofsolutions (to a problem) of increasing quality

introduction to GAintroduction to GA: Evolutionary Computation: Evolutionary Computation

Page 9: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

v Chromosome – representation of the candidate solution

encoding

v Gene – constituent entity of the chromosome

v Population – set of individuals/chromosomes

v Individual – candidate solution to a problemdecoding

v Fitness function – representation of how good a candidatesolution is

v Genetic operators – operators applied on chromosomes in orderto create genetic variation (other chromosomes)

Terminology

introduction to GAintroduction to GA: GA: GA

Page 10: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

introduction to GAintroduction to GA: GA: GA

Page 11: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

EVOLUTIONEVOLUTION

EnvironmentEnvironment

IndividualIndividual

FitnessFitness

PROBLEM SOLVINGPROBLEM SOLVING

ProblemProblem

Candidate SolutionCandidate Solution

QualityQuality

introduction to GAintroduction to GA: Metaphor: Metaphor

Page 12: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Initialize the populationInitialize the population

Select individuals for the mating poolSelect individuals for the mating pool

Perform crossoverPerform crossover

Insert offspring into the populationInsert offspring into the population

The EndThe End

Perform mutationPerform mutation

yesyes

nonoStop?Stop?

introduction to GAintroduction to GA: Flowchart: Flowchart

Page 13: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

ll HowHow toto representrepresent genomes?genomes?ll How to define the crossover operator?How to define the crossover operator?ll How to define the mutation operator?How to define the mutation operator?ll How to define fitness function?How to define fitness function?ll How to generate next generation?How to generate next generation?ll How to define stopping criteria?How to define stopping criteria?

introduction to GAintroduction to GA: Designing GA: Designing GA

Page 14: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

RepresentationRepresentation ExampleExample

stringstring 1 0 1 1 1 0 0 11 0 1 1 1 0 0 1

array of stringsarray of strings http avala yubc net ~apopovichttp avala yubc net ~apopovic

treetree -- genetic programminggenetic programming>>

bbxorxor

oror

cc

bbaa

introduction to GAintroduction to GA: Representing Genomes: Representing Genomes

Page 15: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ Crossover is concept from genetics.Crossover is concept from genetics.§§ Crossover combines genetic material from twoCrossover combines genetic material from two

parents,parents,in order to produce superior offspring.in order to produce superior offspring.

§§ Few types of crossover:Few types of crossover:§§ OneOne--pointpoint§§ Multiple point.Multiple point.

introduction to GAintroduction to GA: Crossover: Crossover

Page 16: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Parent #Parent #11 Parent #Parent #22

00

11

55

33

55

44

77

66

77

66

22

44

22

33

00

11

introduction to GAintroduction to GA: One: One--point Crossoverpoint Crossover

Page 17: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Offspring #Offspring #11 Offspring #Offspring #22

00

11

55

33

55

44

77

66

77

66

22

44

22

33

00

11

introduction to GAintroduction to GA: One: One--point Crossoverpoint Crossover

Page 18: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ Mutation introduces randomness into theMutation introduces randomness into thepopulation.population.§§ The idea of mutationThe idea of mutation

is to reintroduce divergenceis to reintroduce divergenceinto a converging population.into a converging population.§§ Mutation is performedMutation is performed

on small part of population,on small part of population,in order to avoid entering unstable state.in order to avoid entering unstable state.

introduction to GAintroduction to GA: Mutation: Mutation

Page 19: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

11 11 00 11 00 1100 00

00 11 00 11 00 1100 11

11 00

00 11

ParentParent

ChildChild

introduction to GAintroduction to GA: Mutation: Mutation

Page 20: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Phenotype

D

Phenotype

D

Phenotype

D

SelectionSelection MutationMutation

Solution distributionSolution distribution

introduction to GAintroduction to GA: Mutation and Selection: Mutation and Selection

Page 21: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ Average probability for individual to crossoverAverage probability for individual to crossoveris, in most cases, aboutis, in most cases, about 8080%.%.

§§ Average probability for individual to mutateAverage probability for individual to mutateis aboutis about 11--22%.%.

§§ Probability of genetic operatorsProbability of genetic operatorsfollow the probability in natural systems.follow the probability in natural systems.

§§ The better solutions reproduce more often.The better solutions reproduce more often.

introduction to GAintroduction to GA: About Probabilities: About Probabilities

Page 22: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

introduction to GAintroduction to GA: Typical Run: Typical Run

Page 23: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ Fitness function is evaluation function,Fitness function is evaluation function,that determines what solutions are better thanthat determines what solutions are better thanothers.others.§§ Fitness is computed for each individual.Fitness is computed for each individual.§§ Fitness function is application depended.Fitness function is application depended.

introduction to GAintroduction to GA: Fitness Function: Fitness Function

Page 24: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ The selection operation copies a single individual,The selection operation copies a single individual,probabilistically selected based on fitness,probabilistically selected based on fitness,into the next generation of the population.into the next generation of the population.

§§ There are few possible ways to implement selection:There are few possible ways to implement selection:§§ “Only the strongest survive”“Only the strongest survive”§§ Choose the individuals with the highest fitnessChoose the individuals with the highest fitness

for next generationfor next generation§§ “Some weak solutions survive”“Some weak solutions survive”§§ Assign a probability that a particular individualAssign a probability that a particular individual

will be selected for the next generationwill be selected for the next generation§§More diversityMore diversity§§ Some bad solutions might have good parts!Some bad solutions might have good parts!

introduction to GAintroduction to GA:: SelectionSelection

Page 25: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

00..9393 00..5151 00..7272 00..3131 00..1212 00..6464

Previous generationPrevious generation

Next generationNext generation

00..9393 00..7272 00..6464

introduction to GAintroduction to GA: Selection: Selection -- Survival of The StrongestSurvival of The Strongest

Page 26: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

00..9393 00..5151 00..7272 00..3131 00..1212 00..6464

Previous generationPrevious generation

Next generationNext generation

00..9393 00..7272 0.640.64 00..1212

00..1212

introduction to GAintroduction to GA: Selection: Selection -- Some Weak Solutions SurviveSome Weak Solutions Survive

Page 27: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

©http://www.softchitech.com/ec_intro_html

introduction to GAintroduction to GA:: Roulette Wheel Selection

Page 28: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ Final problem is to decideFinal problem is to decidewhen to stop execution of algorithm.when to stop execution of algorithm.

§§ There are two possible solutionsThere are two possible solutionsto this problem:to this problem:§§ First approach:First approach:§§ Stop after productionStop after production

of definite number of generationsof definite number of generations§§ Second approach:Second approach:§§ Stop when the improvement in averageStop when the improvement in average

fitnessfitnessover two generations is below a thresholdover two generations is below a threshold

introduction to GAintroduction to GA: Stopping Criteria: Stopping Criteria

Page 29: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

v Problem definitionv Encoding of the

candidate solutionv Fitness definitionv Runv Decoding the best fitted

chromosome = solution

introduction to GAintroduction to GA: Genetic Algorithm: Genetic Algorithm

Page 30: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Phases in optimizing on aPhases in optimizing on a 11--dimensional fitnessdimensional fitnesslandscapelandscape

Early phase:quasi-random population distribution

Mid-phase:population arranged around/on hills

Late phase:population concentrated on high hills

introduction to GAintroduction to GA: Working of GA: phases: Working of GA: phases

Page 31: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Typical run of an EA shows so-called “anytime behavior”

Bes

t fitn

ess

in p

opul

atio

n

Time (number of generations)

introduction to GAintroduction to GA: Working of GA: typical run: Working of GA: typical run

Page 32: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Bes

t fitn

ess

in p

opul

atio

n

Time (number of generations)

Progress in 1st half

Progress in 2nd half

introduction to GAintroduction to GA: Working of GA: long runs might not pay off: Working of GA: long runs might not pay off

Page 33: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Time (number of generations)

Bes

t fitn

ess

in p

opul

atio

n

T: time needed to reach level F after randominitialization

T

F: fitness after smart initializationF

introduction to GAintroduction to GA: Working of GA: smart initialization: Working of GA: smart initialization

Page 34: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Scale of “all” problems

Per

form

ance

of m

etho

ds o

n pr

oble

ms

Random search

Special, problem tailored method

Evolutionary algorithm

introduction to GAintroduction to GA: Performance of EAs: Performance of EAs

Page 35: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Per

form

ance

of m

etho

ds o

n pr

oble

ms

EA 1

EA 4

EA 3EA 2

Scale of “all” problems

P

introduction to GAintroduction to GA: Performance of EAs: Performance of EAs

Page 36: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

§§ Simple problem: max xSimple problem: max x22 over {over {00,,11,…,,…,3131}}§§ GA approach:GA approach:§§ Representation: binary code, e.g.Representation: binary code, e.g. 0110101101 «« 1313§§ Population size:Population size: 44§§ 11--point xover, bitwise mutationpoint xover, bitwise mutation§§ Roulette wheel selectionRoulette wheel selection§§ Random initialisationRandom initialisation

§§ We show one generational cycle done by handWe show one generational cycle done by hand

introduction to GAintroduction to GA: An example: An example --Goldberg ‘Goldberg ‘8989

Page 37: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

xx22 example: selectionexample: selection

introduction to GAintroduction to GA: An example: An example --Goldberg ‘89Goldberg ‘89

Page 38: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

XX22 example: crossoverexample: crossover

introduction to GAintroduction to GA: An example: An example --Goldberg ‘Goldberg ‘8989

Page 39: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

XX22 example: mutationexample: mutationintroduction to GAintroduction to GA: An example: An example --Goldberg ‘Goldberg ‘8989

Page 40: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

introduction to GAintroduction to GA: GENETIC PROGRAMMING: GENETIC PROGRAMMING

Page 41: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

Objective:Objective: Find a computer program with oneFind a computer program with oneinput (independent variableinput (independent variable XX) whose) whoseoutput equals the given dataoutput equals the given data

11 Terminal set:Terminal set: T = {X, RandomT = {X, Random--Constants}Constants}

22 FunctionFunction setset:: F = {+,F = {+, --, *, %}, *, %}

33 Fitness:Fitness: TheThe sumsum ofof thethe absoluteabsolute valuevalue ofof thethedifferencesdifferences betweenbetween thethe candidatecandidateprogram’sprogram’s outputoutput andand thethe givengiven datadata(computed(computed overover numerousnumerous valuesvalues ofofthethe independentindependent variablevariable xx fromfrom ––11..00toto ++11..00))

44 Parameters:Parameters: Population sizePopulation size MM = 4= 4

55 Termination:Termination: An individual emerges whose sum ofAn individual emerges whose sum ofabsolute errors is less than 0.1absolute errors is less than 0.1

introduction to GAintroduction to GA: PREPARATORY STEPS: PREPARATORY STEPS

Page 42: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

POPULATION OFPOPULATION OF 44 RANDOMLY CREATEDRANDOMLY CREATEDINDIVIDUALS FOR GENERATIONINDIVIDUALS FOR GENERATION 00

introduction to GAintroduction to GA: SYMBOLIC REGRESSION: SYMBOLIC REGRESSION

Page 43: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

FITNESS OF THEFITNESS OF THE 44 INDIVIDUALS IN GENINDIVIDUALS IN GEN00

x + 1 x2 + 1 2 x

0.67 1.00 1.70 2.67

introduction to GAintroduction to GA: SYMBOLIC REGRESSION: SYMBOLIC REGRESSION xx22 ++ xx ++ 11

Page 44: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

GENERATIONGENERATION 11

Copy of (a)Mutant of(c)

picking “2”as mutationpoint

First offspringof crossover of(a) and (b)picking “+” ofparent (a) andleft-most “x” ofparent (b) ascrossoverpoints

Secondoffspring ofcrossover of (a)and (b)picking “+” ofparent (a) andleft-most “x” ofparent (b) ascrossoverpoints

introduction to GAintroduction to GA:: SYMBOLIC REGRESSIONSYMBOLIC REGRESSION xx22 ++ xx ++ 11

Page 45: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

ØØ AdvantagesAdvantagesoo No presumptions w.r.t. problem spaceNo presumptions w.r.t. problem spaceoo Widely applicableWidely applicableoo Low development & application costsLow development & application costsoo Easy to incorporate other methodsEasy to incorporate other methodsoo Solutions are interpretable (unlike NN)Solutions are interpretable (unlike NN)oo Can be run interactively, accommodate user proposed solutionsCan be run interactively, accommodate user proposed solutionsoo Provides many alternative solutionsProvides many alternative solutionsoo Intrinsic parallelismIntrinsic parallelism

ØØ DisadvantagesDisadvantagesoo No guarantee for optimal solution within finite timeNo guarantee for optimal solution within finite timeoo Weak theoretical basisWeak theoretical basisoo May need parameter tuningMay need parameter tuningoo Often computationally expensive, i.e. slowOften computationally expensive, i.e. slow

introduction to GAintroduction to GA:: Conclusion: advantages and disadvantagesConclusion: advantages and disadvantages

Page 46: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction

introduction to GAintroduction to GA: References: References

www.cs.vu.nl/~jabekker/ec0607/

web.umr.edu/~ercal/387/

www.genetic-programming.com

David E. Goldberg (1989), Genetic Algorithms in Search, Optimization, andMachine Learning.

Page 47: Introduction to Genetic Algorithm - NIORDCkarafarin.niordc.ir/uploads/94_79_ga.pdf§§Genetic algorithmGenetic algorithm -- few microseconds after few microseconds after introduction