SlideShare a Scribd company logo
1 of 26
Genetic Algorithms
CS121 Spring 2009
Richard Frankel
Stanford University
1
Outline
• Motivations/applicable situations
• What are genetic algorithms?
• Pros and cons
• Examples
2
Motivation
• Searching some search spaces with traditional
search methods would be intractable. This is
often true when states/candidate solutions
have a large number of successors.
– Example: Designing the surface of an aircraft.
Image source: http://www.centaursoft.com/cms/index.php?section=25 3
Applicable situations
• Often used for optimization (scheduling,
design, etc.) problems, though can be used for
many other things as well, as we’ll see a bit
later.
– Good problem for GA: Scheduling air traffic
– Bad problems for GA: Finding large primes
(why?), 2D pathfinding (why?)
4
Applicable situations
• Genetic algorithms work best when the
“fitness landscape” is continuous (in some
dimensions). This is also true of standard
search, e.g. A*.
– Intuitively, this just means that we can find a
heuristic that gives a rough idea of how close a
candidate is to being a solution.
Image source: scholarpedia.org 5
So what is a genetic algorithm?
• Genetic algorithms are a randomized heuristic
search strategy.
• Basic idea: Simulate natural selection, where
the population is composed of candidate
solutions.
• Focus is on evolving a population from which
strong and diverse candidates can emerge via
mutation and crossover (mating).
6
Basic algorithm
• Create an initial population, either random or
“blank”.
• While the best candidate so far is not a
solution:
– Create new population using successor functions.
– Evaluate the fitness of each candidate in the
population.
• Return the best candidate found.
7
Simple example – alternating string
• Let’s try to evolve a length 4 alternating string
• Initial population: C1=1000, C2=0011
• We roll the dice and end up creating C1’ =
cross (C1, C2) = 1011 and C2’ = cross (C1, C1) =
1000.
• We mutate C1’ and the fourth bit flips, giving
1010. We mutate C2’ and get 1000.
• We run our solution test on each. C1’ is a
solution, so we return it and are done.
8
Basic components
• Candidate representation
– Important to choose this well. More work here means
less work on the successor functions.
• Successor function(s)
– Mutation, crossover
• Fitness function
• Solution test
• Some parameters
– Population size
– Generation limit
9
Candidate representation
• We want to encode candidates in a way that
makes mutation and crossover easy.
• The typical candidate representation is a
binary string. This string can be thought of as
the genetic code of a candidate – thus the
term “genetic algorithm”!
– Other representations are possible, but they make
crossover and mutation harder.
10
Candidate representation example
• Let’s say we want to represent a rule for classifying
bikes as mountain bikes or hybrid, based on these
attributes*:
– Make (Bridgestone, Cannondale, Nishiki, or Gary Fisher)
– Tire type (knobby, treads)
– Handlebar type (straight, curved)
– Water bottle holder (Boolean)
• We can encode a rule as a binary string, where each bit
represents whether a value is accepted.
*Bikes scheme used with permission from Mark Maloof.
Make Tires Handlebars Water bottle
B C N G K T S C Y N
11
Candidate representation example
• The candidate will be a bit string of length 10,
because we have 10 possible attribute values.
• Let’s say we want a rule that will match any
bike that is made by Bridgestone or
Cannondale, has treaded tires, and has
straight handlebars. This rule could be
represented as 1100011011:
Make Tires Handlebars Water bottle
1 1 0 0 0 1 1 0 1 1
B C N G K T S C Y N
12
Successor functions
• Mutation – Given a candidate, return a slightly
different candidate.
• Crossover – Given two candidates, produce
one that has elements of each.
• We don’t always generate a successor for each
candidate. Rather, we generate a successor
population based on the candidates in the
current population, weighted by fitness.
13
Successor functions
• If your candidate representation is just a
binary string, then these are easy:
– Mutate(c): Copy c as c’. For each bit b in c’, flip b
with probability p. Return c’.
– Cross (c1, c2): Create a candidate c such that c[i] =
c1[i] if i % 2 = 0, c[i] = c2[i] otherwise. Return c.
• Alternatively, any other scheme such that c gets roughly
equal information from c1 and c2.
14
Fitness function
• The fitness function is analogous to a heuristic
that estimates how close a candidate is to being a
solution.
• In general, the fitness function should be
consistent for better performance. However,
even if it is, there are no guarantees. This is a
probabilistic algorithm!
• In our classification rule example, one possible
fitness function would be information gain over
training data.
15
Solution test
• Given a candidate, return whether the
candidate is a solution.
• Often just answers the question “does the
candidate satisfy some set of constraints?”
• Optional! Sometimes you just want to do the
best you can in a given number of
generations, e.g. the classification rule
example.
16
New population generation
• How do we come up with a new population?
– Given a population P, generate P’ by performing
crossover |P| times, each time selecting
candidates with probability proportional to their
fitness.
– Get P’’ by mutating each candidate in P’.
– Return P’’.
17
New population generation
• That was just one approach – be creative!
– That approach doesn’t explicitly allow candidates
to survive more than one generation – this might
not be optimal.
– Crossover is not necessary, though it can be
helpful in escaping local maxima. Mutation is
necessary (why?).
18
Basic algorithm (recap)
• Create an initial population, either random or
“blank”.
• While the best candidate so far is not a
solution:
– Create new population using successor functions.
– Evaluate the fitness of each candidate in the
population.
• Return the best candidate found.
19
Pros and Cons
• Pros
– Faster (and lower memory requirements) than searching a
very large search space.
– Easy, in that if your candidate representation and fitness
function are correct, a solution can be found without any
explicit analytical work.
• Cons
– Randomized – not optimal or even complete.
– Can get stuck on local maxima, though crossover can help
mitigate this.
– It can be hard to work out how best to represent a
candidate as a bit string (or otherwise).
20
Examples - GA in the wild
• Rule set classifier generation
• I tried this as an undergrad, and it worked pretty well.
Rather than classifying bikes, I was classifying Congressional
representatives by party, based on their voting records.
• General approach:
– Use GA to generate a rule for training data, with information
gain for the fitness function and no solution test (just a
generation limit).
– Remove positive examples covered by the rule.
– Repeat the above two steps until all positive training examples
are covered.
– To classify an example: iff the example is matched by any of the
rules generated, consider it a positive example.
21
Examples - GA in the wild
• ST5 Antenna – NASA Evolvable Systems Group
http://ti.arc.nasa.gov/projects/esg/research/antenna.htm
22
ST5 Antenna
• Needs less power than standard antennae.
• Doesn’t require a matching network nor a
phasing circuit – two less steps in design and
fabrication.
• More uniform coverage than standard
antennae, yielding more reliable performance.
• Short design cycle – 3 person-months to
prototype fabrication, vs. 5-person months on
average for conventionally designed antennae.
23
Examples - GA in the wild
• Image compression – evolving the Mona Lisa
http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/
Generation 904314
Generation 2716
Generation 301
Generation 1
24
Evolving the Mona Lisa
• Uses only 50 polygons of 6 vertices each.
• Population size of 1, no crossover – parent
compared with child, and superior image kept.
• Assuming each polygon has 4 bytes for color
(RGBA) and 2 bytes for each of 6 vertices, this
image only requires 800 bytes.
• However, compression time is prohibitive and
storage is cheaper than processing time. 
25
More evolved images
http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/ 26

More Related Content

Similar to Genetic Algorithms-1.ppt

Fast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA HardwareFast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA HardwareTigerGraph
 
SKIM at Sawtooth Software Conference 2013: ACBC Revisited
SKIM at Sawtooth Software Conference 2013: ACBC RevisitedSKIM at Sawtooth Software Conference 2013: ACBC Revisited
SKIM at Sawtooth Software Conference 2013: ACBC RevisitedSKIM
 
Introduction to Genetic Algorithms 2014
Introduction to Genetic Algorithms 2014Introduction to Genetic Algorithms 2014
Introduction to Genetic Algorithms 2014Aleksander Stensby
 
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...gdgsurrey
 
DIY Driver Analysis Webinar slides
DIY Driver Analysis Webinar slidesDIY Driver Analysis Webinar slides
DIY Driver Analysis Webinar slidesDisplayr
 
IBANK - Big data www.ibank.uk.com 07474222079
IBANK - Big data www.ibank.uk.com 07474222079IBANK - Big data www.ibank.uk.com 07474222079
IBANK - Big data www.ibank.uk.com 07474222079ibankuk
 
Customer choice probabilities
Customer choice probabilitiesCustomer choice probabilities
Customer choice probabilitiesAllan D. Butler
 
Tips and tricks to win kaggle data science competitions
Tips and tricks to win kaggle data science competitionsTips and tricks to win kaggle data science competitions
Tips and tricks to win kaggle data science competitionsDarius Barušauskas
 
Fdp session rtu session 1
Fdp session rtu session 1Fdp session rtu session 1
Fdp session rtu session 1sprsingh1
 
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program RepairIt Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program RepairClaire Le Goues
 
Improving How We Deliver Machine Learning Models (XCONF 2019)
Improving How We Deliver Machine Learning Models (XCONF 2019)Improving How We Deliver Machine Learning Models (XCONF 2019)
Improving How We Deliver Machine Learning Models (XCONF 2019)David Tan
 
Revolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn PipelinesRevolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn PipelinesPhilip Goddard
 
Scalable Software Testing and Verification of Non-Functional Properties throu...
Scalable Software Testing and Verification of Non-Functional Properties throu...Scalable Software Testing and Verification of Non-Functional Properties throu...
Scalable Software Testing and Verification of Non-Functional Properties throu...Lionel Briand
 
Using Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsUsing Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsScott Clark
 
Using Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsUsing Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsSigOpt
 
李俊良/Feature Engineering in Machine Learning
李俊良/Feature Engineering in Machine Learning李俊良/Feature Engineering in Machine Learning
李俊良/Feature Engineering in Machine Learning台灣資料科學年會
 
Use of Definitive Screening Designs to Optimize an Analytical Method
Use of Definitive Screening Designs to Optimize an Analytical MethodUse of Definitive Screening Designs to Optimize an Analytical Method
Use of Definitive Screening Designs to Optimize an Analytical MethodPhilip Ramsey
 
Automated Hyperparameter Tuning, Scaling and Tracking
Automated Hyperparameter Tuning, Scaling and TrackingAutomated Hyperparameter Tuning, Scaling and Tracking
Automated Hyperparameter Tuning, Scaling and TrackingDatabricks
 

Similar to Genetic Algorithms-1.ppt (20)

Fast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA HardwareFast Parallel Similarity Calculations with FPGA Hardware
Fast Parallel Similarity Calculations with FPGA Hardware
 
SKIM at Sawtooth Software Conference 2013: ACBC Revisited
SKIM at Sawtooth Software Conference 2013: ACBC RevisitedSKIM at Sawtooth Software Conference 2013: ACBC Revisited
SKIM at Sawtooth Software Conference 2013: ACBC Revisited
 
Big data
Big dataBig data
Big data
 
Introduction to Genetic Algorithms 2014
Introduction to Genetic Algorithms 2014Introduction to Genetic Algorithms 2014
Introduction to Genetic Algorithms 2014
 
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
 
DIY Driver Analysis Webinar slides
DIY Driver Analysis Webinar slidesDIY Driver Analysis Webinar slides
DIY Driver Analysis Webinar slides
 
IBANK - Big data www.ibank.uk.com 07474222079
IBANK - Big data www.ibank.uk.com 07474222079IBANK - Big data www.ibank.uk.com 07474222079
IBANK - Big data www.ibank.uk.com 07474222079
 
Customer choice probabilities
Customer choice probabilitiesCustomer choice probabilities
Customer choice probabilities
 
Tips and tricks to win kaggle data science competitions
Tips and tricks to win kaggle data science competitionsTips and tricks to win kaggle data science competitions
Tips and tricks to win kaggle data science competitions
 
Fdp session rtu session 1
Fdp session rtu session 1Fdp session rtu session 1
Fdp session rtu session 1
 
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program RepairIt Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
 
Improving How We Deliver Machine Learning Models (XCONF 2019)
Improving How We Deliver Machine Learning Models (XCONF 2019)Improving How We Deliver Machine Learning Models (XCONF 2019)
Improving How We Deliver Machine Learning Models (XCONF 2019)
 
Revolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn PipelinesRevolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
 
Scalable Software Testing and Verification of Non-Functional Properties throu...
Scalable Software Testing and Verification of Non-Functional Properties throu...Scalable Software Testing and Verification of Non-Functional Properties throu...
Scalable Software Testing and Verification of Non-Functional Properties throu...
 
Using Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsUsing Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning Models
 
Using Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsUsing Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning Models
 
李俊良/Feature Engineering in Machine Learning
李俊良/Feature Engineering in Machine Learning李俊良/Feature Engineering in Machine Learning
李俊良/Feature Engineering in Machine Learning
 
Use of Definitive Screening Designs to Optimize an Analytical Method
Use of Definitive Screening Designs to Optimize an Analytical MethodUse of Definitive Screening Designs to Optimize an Analytical Method
Use of Definitive Screening Designs to Optimize an Analytical Method
 
Automated Hyperparameter Tuning, Scaling and Tracking
Automated Hyperparameter Tuning, Scaling and TrackingAutomated Hyperparameter Tuning, Scaling and Tracking
Automated Hyperparameter Tuning, Scaling and Tracking
 
BOM DMAIC TEMPLATE
BOM DMAIC TEMPLATEBOM DMAIC TEMPLATE
BOM DMAIC TEMPLATE
 

Recently uploaded

Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 

Recently uploaded (20)

Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 

Genetic Algorithms-1.ppt

  • 1. Genetic Algorithms CS121 Spring 2009 Richard Frankel Stanford University 1
  • 2. Outline • Motivations/applicable situations • What are genetic algorithms? • Pros and cons • Examples 2
  • 3. Motivation • Searching some search spaces with traditional search methods would be intractable. This is often true when states/candidate solutions have a large number of successors. – Example: Designing the surface of an aircraft. Image source: http://www.centaursoft.com/cms/index.php?section=25 3
  • 4. Applicable situations • Often used for optimization (scheduling, design, etc.) problems, though can be used for many other things as well, as we’ll see a bit later. – Good problem for GA: Scheduling air traffic – Bad problems for GA: Finding large primes (why?), 2D pathfinding (why?) 4
  • 5. Applicable situations • Genetic algorithms work best when the “fitness landscape” is continuous (in some dimensions). This is also true of standard search, e.g. A*. – Intuitively, this just means that we can find a heuristic that gives a rough idea of how close a candidate is to being a solution. Image source: scholarpedia.org 5
  • 6. So what is a genetic algorithm? • Genetic algorithms are a randomized heuristic search strategy. • Basic idea: Simulate natural selection, where the population is composed of candidate solutions. • Focus is on evolving a population from which strong and diverse candidates can emerge via mutation and crossover (mating). 6
  • 7. Basic algorithm • Create an initial population, either random or “blank”. • While the best candidate so far is not a solution: – Create new population using successor functions. – Evaluate the fitness of each candidate in the population. • Return the best candidate found. 7
  • 8. Simple example – alternating string • Let’s try to evolve a length 4 alternating string • Initial population: C1=1000, C2=0011 • We roll the dice and end up creating C1’ = cross (C1, C2) = 1011 and C2’ = cross (C1, C1) = 1000. • We mutate C1’ and the fourth bit flips, giving 1010. We mutate C2’ and get 1000. • We run our solution test on each. C1’ is a solution, so we return it and are done. 8
  • 9. Basic components • Candidate representation – Important to choose this well. More work here means less work on the successor functions. • Successor function(s) – Mutation, crossover • Fitness function • Solution test • Some parameters – Population size – Generation limit 9
  • 10. Candidate representation • We want to encode candidates in a way that makes mutation and crossover easy. • The typical candidate representation is a binary string. This string can be thought of as the genetic code of a candidate – thus the term “genetic algorithm”! – Other representations are possible, but they make crossover and mutation harder. 10
  • 11. Candidate representation example • Let’s say we want to represent a rule for classifying bikes as mountain bikes or hybrid, based on these attributes*: – Make (Bridgestone, Cannondale, Nishiki, or Gary Fisher) – Tire type (knobby, treads) – Handlebar type (straight, curved) – Water bottle holder (Boolean) • We can encode a rule as a binary string, where each bit represents whether a value is accepted. *Bikes scheme used with permission from Mark Maloof. Make Tires Handlebars Water bottle B C N G K T S C Y N 11
  • 12. Candidate representation example • The candidate will be a bit string of length 10, because we have 10 possible attribute values. • Let’s say we want a rule that will match any bike that is made by Bridgestone or Cannondale, has treaded tires, and has straight handlebars. This rule could be represented as 1100011011: Make Tires Handlebars Water bottle 1 1 0 0 0 1 1 0 1 1 B C N G K T S C Y N 12
  • 13. Successor functions • Mutation – Given a candidate, return a slightly different candidate. • Crossover – Given two candidates, produce one that has elements of each. • We don’t always generate a successor for each candidate. Rather, we generate a successor population based on the candidates in the current population, weighted by fitness. 13
  • 14. Successor functions • If your candidate representation is just a binary string, then these are easy: – Mutate(c): Copy c as c’. For each bit b in c’, flip b with probability p. Return c’. – Cross (c1, c2): Create a candidate c such that c[i] = c1[i] if i % 2 = 0, c[i] = c2[i] otherwise. Return c. • Alternatively, any other scheme such that c gets roughly equal information from c1 and c2. 14
  • 15. Fitness function • The fitness function is analogous to a heuristic that estimates how close a candidate is to being a solution. • In general, the fitness function should be consistent for better performance. However, even if it is, there are no guarantees. This is a probabilistic algorithm! • In our classification rule example, one possible fitness function would be information gain over training data. 15
  • 16. Solution test • Given a candidate, return whether the candidate is a solution. • Often just answers the question “does the candidate satisfy some set of constraints?” • Optional! Sometimes you just want to do the best you can in a given number of generations, e.g. the classification rule example. 16
  • 17. New population generation • How do we come up with a new population? – Given a population P, generate P’ by performing crossover |P| times, each time selecting candidates with probability proportional to their fitness. – Get P’’ by mutating each candidate in P’. – Return P’’. 17
  • 18. New population generation • That was just one approach – be creative! – That approach doesn’t explicitly allow candidates to survive more than one generation – this might not be optimal. – Crossover is not necessary, though it can be helpful in escaping local maxima. Mutation is necessary (why?). 18
  • 19. Basic algorithm (recap) • Create an initial population, either random or “blank”. • While the best candidate so far is not a solution: – Create new population using successor functions. – Evaluate the fitness of each candidate in the population. • Return the best candidate found. 19
  • 20. Pros and Cons • Pros – Faster (and lower memory requirements) than searching a very large search space. – Easy, in that if your candidate representation and fitness function are correct, a solution can be found without any explicit analytical work. • Cons – Randomized – not optimal or even complete. – Can get stuck on local maxima, though crossover can help mitigate this. – It can be hard to work out how best to represent a candidate as a bit string (or otherwise). 20
  • 21. Examples - GA in the wild • Rule set classifier generation • I tried this as an undergrad, and it worked pretty well. Rather than classifying bikes, I was classifying Congressional representatives by party, based on their voting records. • General approach: – Use GA to generate a rule for training data, with information gain for the fitness function and no solution test (just a generation limit). – Remove positive examples covered by the rule. – Repeat the above two steps until all positive training examples are covered. – To classify an example: iff the example is matched by any of the rules generated, consider it a positive example. 21
  • 22. Examples - GA in the wild • ST5 Antenna – NASA Evolvable Systems Group http://ti.arc.nasa.gov/projects/esg/research/antenna.htm 22
  • 23. ST5 Antenna • Needs less power than standard antennae. • Doesn’t require a matching network nor a phasing circuit – two less steps in design and fabrication. • More uniform coverage than standard antennae, yielding more reliable performance. • Short design cycle – 3 person-months to prototype fabrication, vs. 5-person months on average for conventionally designed antennae. 23
  • 24. Examples - GA in the wild • Image compression – evolving the Mona Lisa http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/ Generation 904314 Generation 2716 Generation 301 Generation 1 24
  • 25. Evolving the Mona Lisa • Uses only 50 polygons of 6 vertices each. • Population size of 1, no crossover – parent compared with child, and superior image kept. • Assuming each polygon has 4 bytes for color (RGBA) and 2 bytes for each of 6 vertices, this image only requires 800 bytes. • However, compression time is prohibitive and storage is cheaper than processing time.  25

Editor's Notes

  1. Images from http://www.centaursoft.com/cms/index.php?section=25
  2. Finding large primes is a bad problem for GA because the fitness landscape is not continuous – hard to differentiate between something 1 bit away from a prime, and something that is the complement of a prime. 2D pathfinding bad because the search space is small, so better off with A*.
  3. Mutation is necessary because some important gene might be missing from all of the initial population.
  4. Mutation is necessary because some important gene might be missing from all of the initial population.
  5. First, there is the potential of needing less power. Antenna ST5-3-10 achieves high gain (2-4dB) across a wider range of elevation angles. This allows a broader range of angles over which maximum data throughput can be achieved. Also, less power from the solar array and batteries may be required. Second, the evolved antenna does not require a matching network nor a phasing circuit, removing two steps in design and fabrication of the antenna. A trivial transmission line may be used for the match on the flight antenna, but simulation results suggest that one is not required. Third, the evolved antenna has more uniform coverage in that it has a uniform pattern with small ripples in the elevations of greatest interest (between 40 and 80 degrees). This allows for reliable performance as elevation angle relative to the ground changes. Finally, the evolved antenna had a shorter design cycle. It was estimated that antenna ST5-3-10 took 3 person-months to design and fabricate the first prototype as compared to 5 person-months for the conventionally designed antenna.
  6. This weekend I decided to play around a bit with genetic programming and put evolution to the test, the test of fine art :-) I created a small program that keeps a string of DNA for polygon rendering. The procedure of the program is quite simple: 0) Setup a random DNA string (application start) Copy the current DNA sequence and mutate it slightly Use the new DNA to render polygons onto a canvas Compare the canvas to the source image If the new painting looks more like the source image than the previous painting did, then overwrite the current DNA with the new DNA repeat from 1 Now to the interesting part :-) Could you paint a replica of the Mona Lisa using only 50 semi transparent polygons? Took 904314 generations, though began to be recognizable as the Mona Lisa after 10,000 or so. Images above are generation 1, 301, 2716, and 904314.