introduction to scientific modelingforrest/classes/cs365/lectures/...references" • j. h....

65
Introduction to Scientific Modeling CS 365, Fall Semester, 2011 Genetic Algorithms Stephanie Forrest http://cs.unm.edu/~forrest/classes/cs365 [email protected] 505-277-7104

Upload: others

Post on 27-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Introduction to Scientific Modeling CS 365, Fall Semester, 2011

Genetic Algorithms

Stephanie Forrest

http://cs.unm.edu/~forrest/classes/cs365 [email protected]

505-277-7104

Page 2: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Genetic Algorithms"

•  Principles of natural selection applied to computation:"–  Variation "–  Selection "–  Inheritance"

•  Evolution in a computer:"–  Individuals (genotypes) stored in computerʼs memory "–  Evaluation of individuals (artificial selection)"–  Differential reproduction through copying and deletion"–  Variation introduced by analogy with mutation and crossover"

•  Simple algorithm captures much of the richness seen in naturally evolving populations."

Page 3: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

A Simple Genetic Algorithm"

00111"

11100 "01010"

..."

11100"

11100 "01010"

..."

01100"

11010"01100"

..."

Population at Tn"

Selection"

Mutation"

Crossover"

F(00111) = 0.1 F(11100) = 0.9 F(01010) = 0.5 "

Population at T n+1"

Page 4: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Example Performance Curve"

0

10

20

30

40

50

60

70

80

90

100

0 20 40 60 80 100120140160180200220240260280300320340360380400420440460480500520535

Generation

Fitness

mean fitness max fitness

Page 5: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Where did these ideas originate?"

•  Genetic algorithms (Holland, 1962)"–  Original idea was to create an algorithm that captured the richness of

natural adaptive systems."–  Emphasized the adaptive properties of entire populations and the

importance of recombination mechanisms such as crossover."–  Application to function optimization introduced by DeJong (1975)."

•  Evolutionstrategie (Rechenberg, 1965)"–  Emphasized the importance of selection and mutation, as"–  Mechanisms for solving difficult real-valued optimization problems."

•  Evolutionary programming (Fogel et al., 1966)"–  Emphasis on evolving finite state machines."

•  Genetic programming (Koza, 1992)

==> “Evolutionary Computation”"

Page 6: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

References"

•  J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second Edition published by MIT Press (1992)."

•  D. E. Goldberg Genetic Algorithms in Search, Optimization, and Machine Learning. Addison-Wesley (1989)."

•  M. Mitchell An Introduction to Genetic Algorithms. MIT Press (1996)."

•  S. Forrest “Genetic Algorithms: Principles of natural selection applied to computation.” Science 261:872-878 (1993)."

•  J. Koza Genetic Programming. MIT Press (1992)."

Page 7: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Multi-parameter Function Optimization"

0 0 1 1 0 1 Base 2

1 5 Base 10

F(x, y) = yx2 - x4

F(001101) = F(1,5) = 5 • 12-14 = 4

Decimal Binary

0 000

1 001

2 010

3 011

4 100

5 101

6 110

7 111

Page 8: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Multi-parameter Function Optimization"

0 0 1 1 1 1 Bit string (Gray coded)

0 0 1 1 0 1 Base 2

1 5 Base 10

F(x, y) = yx2 - x4

Degray

F(001111) = F(1,5) = 5 • 12-14 = 4

Decimal Binary Gray code

0 000 000

1 001 001

2 010 011

3 011 010

4 100 110

5 101 111

6 110 101

7 111 100

Page 9: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Example Applications of Genetic Algorithms

•  Engineering applications:"–  Multi-parameter function optimization (e.g., spectroscopic applications, turbine

engine design)."–  Sequencing problems (e.g., circuit design, factory scheduling, TSP)."–  Machine and robot learning."–  Complex data analysis."–  Automatic programming (e.g., genetic programming)."

•  Modeling:"–  Rule discovery in cognitive systems."–  Learning strategies for games."–  Affinity maturation in immune systems."–  Ecosystem modeling."

Page 10: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Implementation Issues"

•  Implementation issues"•  Genetic programming:"

–  Example: Trigonometric functions "–  Software repair"

•  Permutation problems and special operators:"–  Example: TSP"

•  Modeling applications:"–  Example: Prisonerʼs Dilemma"–  Example: Classifier Systems "–  Example: Echo"

Page 11: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Implementation Issues"

•  Data structures:"–  Packed arrays of bits"–  Byte arrays"–  Vectors of real numbers"–  Lists and trees"

•  Representation:"–  Feature lists"–  Binary encodings, gray codes"–  Real numbers"–  Permutations"–  Trees …"

•  Selection"–  On next slide"

•  Scaling"–  On next slide"

•  Crossover:"–  1-point, 2-point, n-point"–  Uniform"–  Special operators"

•  Mutation:"–  Bit flips"–  Creep (Gaussian noise)"

•  Elitism"•  Parameters (rough guidelines):"

–  Bitstring length (32 - 10,000)"–  Population size (100 - 1000)"–  Length of run (50 - 10,000)"–  Crossover rate (0.6 per pair)"–  Mutation rate (0.005 per bit)"

Page 12: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Selection Methods"

•  Fitness-proportionate (used in theoretical studies):

–  Expected value of individuali:"–  Implement as roulette wheel:

•  Rank-based: (SKIP)"–  Intended to prevent premature convergence (slow down evolution)."–  Each individual ranked according to fitness."–  Expected value depends on rank."–  Min, Max are constants."

11)(

exp)()( −

−−+= NirankMinMaxMinif

fff i

i =)exp(

Page 13: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Selection Methods cont."

•  Tournament:"–  Computationally efficient."–  Choose T = size of tournament (2 is a common value)."–  Pick subsets of size T from the population randomly (with replacement)."–  Compare fitnesses within the subset and choose the winner (either

deterministically or stochastically)."–  Iterate."

•  Steady state."•  Implicit (e.g., Echo, immune models, etc.)"

–  Reproduction rate proportional to resources obtained."

Page 14: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

How do Genetic Algorithms Work? The Central Dogma of Genetic Algorithms

(Holland, 1975)"

•  Schema processing"•  Schema Theorem"•  Implicit parallelism"•  Building block hypothesis "•  K-armed bandit analogy"

Page 15: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Genetic Algorithms and Search"

•  High-dimensional search spaces:"–  All binary strings of length l. !–  All possible strategies for playing the game of chess."–  All possible tours in the Travelling Salesman Problem."

•  Genetic algorithms use biased sampling to search high-dimensional spaces:"

–  Independent sampling."–  Selection biases search towards high-fitness regions."–  Crossover combines partial solutions from different strings."

•  Partial solution formalized as “schema.”"

1***"

0***"*0**"*1**"

Page 16: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Schemas"

•  Schemas capture important regularities in the search space:

•  Implicit Parallelism: 1 individual samples many schemas simultaneously.

•  Schema Theorem: Reproduction and crossover guarantee exponentially increasing samples of the observed best schemas.

•  Order of a schema O(s) = number of defined bits. Defining length of a schema D(s) = distance between outermost bits.

1 0 0 1 1 10 1 0 0 1 1* * * * 1 1* * 0 * * ** * 0 * * 1* * 0 * 1 1

Page 17: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Schema Theorem (Holland, 1975)"

Let: s be a schema in population at time t," N(s,t) be the number of instances of s at time t."Question: What is the expected N(s,t+1) ?"Assume: Fitness-proportionate selection." Expected number of offspring(x) ="Ignoring crossover and mutation,"

Note: If , then"

Crossover and mutation handled as loss terms:"

),()(),(ˆ)1,( tsNtFtstsN ×=+

µ

)()(tFxF

ctFts=

)(),(µ̂ )0,(),( sNctsN t=

N(s,t +1) ≥ˆ µ (s,t)F(t)

× N(s,t)(1− pcD(s)l −1

)[(1− pm )O(s)]

Page 18: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Royal Road Schemas"

0

10

20

30

40

50

60

70

80

90

100

0 20 40 60 80 100 120 140 160 180 200 220 240 260 280 300Generation

Fitness

schema 1 schema 2 schema 3

Page 19: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Study Question"

•  Given a population, consisting of"–  N individuals,"–  Each individual is L bits long,"

•  How many schemas are sampled by the population (in one generation)?"

•  Hint: "–  Minimum value is: 2L"–  Maximum value is Nx2L"

Page 20: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Questions"

•  When will genetic algorithms work well and when they will not?"–  Not appropriate for problems where it is important to find the exact global

optimum."–  GA domains are typically those about which we have little analytical

knowledge (complex, noisy, dynamic, poorly specified, etc.)."–  Would like a mathematical characterization that is predictive."

•  What makes a problem hard for genetic algorithms?"–  Deception, multi-modality, conflicting schema information, noise, ..."

•  What makes a problem easy for genetic algorithms?"•  What distinguishes genetic algorithms from other optimization

methods, such as hill climbing?"•  What does it mean for a genetic algorithm to perform well?"

Page 21: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Building Blocks Hypothesis (Holland, 1975)"

1. GA initially detects biases in low-order schemas:"GA obtains good estimates of schema average fitness by sampling strings."

2. Over time, information from low-order schemas is combined through crossover, and"

3. GA detects biases in high-order schemas,"4. Eventually converging on the most fit region of the space.

Implies that crossover is central to the success of the GA."

•  Claim: GA allocates samples to schemas in a near optimal way:"–  K-armed bandit argument. "

Page 22: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Genetic Programming"

•  Evolve populations of computer programs:"–  Typically use the language Lisp."–  Select a set of primitive functions for each problem."–  Represent program as a syntax tree."

•  Function approximation vs. function optimization."•  Crossover operator:"

–  Exchange subtrees between individual program trees."–  Schema Theorem?"

•  Many applications:"–  Optimal control (e.g., the pole balancing problem)"–  Circuit design"–  Symbolic regression (data fitting)"

Page 23: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Genetic Programming"

Expression X2 + 3xy + y2

LISP (+ (* x x) (*3 x y) (* y y))

+

x

*

x x

* y 3

* y y

Page 24: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Genetic Programming cont."

•  Consider evolving a program to compute: cos 2x"

•  A human-designed program: 1 - 2sin2x In Lisp: (- 1 (* 2 (* (sin x)(sin x))))"

•  A genetic programming solution: (sin ( - ( - 2 (* x 2)) (sin (sin (sin (sin (sin (sin ( * (sin (sin 1)) (sin (sin 1)))))))))))"

•  Junk DNA?"

Page 25: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Example Genetic Programming Application Automatically Repairing Software Bugs"

•  University of New Mexico –  Stephanie Forrest –  ThanhVu Nguyen –  Eric Schulte –  Neal Holtschulte

•  University of Virginia

–  Westley Weimer –  Claire Le Goue –  Zak Fry

Page 26: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Summary of Approach"•  Assume: "

–  Access to C source code"–  Negative test case (input = 10593 ; output = infinite loop)"–  Positive test cases (encode required program functionality)"

•  Construct Abstract Syntax Tree (AST) using CIL"•  Evolve repair that avoids negative test case and passes positive test

case"•  Minimize repair using program analysis methods (addresses code

bloat)"–  Structural differencing and delta debugging"

Page 27: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second
Page 28: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Mutation operators"

Swap" Delete" Insert"

Page 29: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Example: Microsoft Zune Players"

•  Dec. 31, 2008. Microsoft Zune players mysteriously freeze up."

•  Bug: Infinite loop when input is last day of a leap year."

•  Negative test case: 10593, which corresponds to Dec 31, 2008. "

•  Repair is not trivial. Microsoftʼs recommendation was to let Zune drain its battery and then reset."

Downloaded from http://pastie.org/349916 (Jan. 2009). "

Page 30: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Abstract Syntax Tree Representation"

Page 31: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Weighted path"•  Nodes visited by negative test case have weight 1.0"•  Nodes visited by negative and positive test cases have weight 0.01"•  All other nodes have weight 0.0"

Page 32: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

The final evolved repair"

Page 33: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Evolutionary computation Innovations"

•  Start with a working program"•  Focus on execution path through AST"

–  Restrict mutation and crossover to execution path"

•  Represent AST to level of statements"–  Leaves out expressions, variable declarations"

•  Genetic operators"–  Donʼt invent any new code, crossback, macromutation operators"

•  Minimize repair size using structural differencing"

Page 34: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Evolutionary computation details"

•  Fitness: Weighted sum of test cases that the program passes:!–  F(Programs that donʼt compile) = 0"–  5 positive test cases (weight = 1), 1 or 2 negative test cases (weight = 10)!

•  Mutation operations: "–  Delete a statement, Insert a statement, Swap a stmt along the weighted path

with a stmt from another part of the program,"•  Crossover: Exchange subtrees"•  Population size is 40. Standard run is 10 gens + 10 gens"

Page 35: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Summary of repairs to date"

•  Twenty distinct programs totaling 186,603 LOC (180kLOC)."

•  Scientific Computing: 1"•  Scripting Languages: 3"•  Games, Graphics, Sound: 4"•  Servers (web, ftp,

authentication): 4"•  Operating system utilities: 8"

•  Buffer overflow attacks: 3"•  Segfaults: 7"•  Infinite loops: 4"•  Incorrect output: 2"•  Integer overflow: 2"•  Nonoverflow DOS: 1"•  Format string vulnerability: 1"

Page 36: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Benchmark programs "GECCO 2009, ICSE 2009, TSE (in press)"

Program Lines of

Code (LOC) Functionality Fault

Time to Repair

zune 28 media player infinite loop 42s

gcd 22 handcrafted example infinite loop 153s

uniq 1146 duplicate text processing segfault 34s

look-u 1169 dictionary lookup segfault 45s

look-s 1363 dictionary lookup infinite loop 55s

units 1504 metric conversion segfault 109s

deroff 2236 document processing segfault 131s

nullhttp 5575 webserver heap overflow 578s

indent 9906 source code processing infinite loop 546s

flex 18775 lexical analyzer generator segfault 230s

atris 21553 graphical tetris game stack overflow 80s

openldap io.c 6519 directory protocol nonoverflow DOS 665s

lighttp fastcgi.c 13984 webserver heap overflow 49s

php string.c 26044 scripting language integer overflow 6s

wu-ftpd 35109 FTP server format string 2256s

Page 37: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Time to discover repair"

•  Average time to repair: approx. 3 minutes "•  Time includes: "

–  GP algorithm (selection, mutation, calculating fitness, etc.)"–  Running test cases"–  Pretty printing and memoizing ASTs"–  gcc (compiling ASTs into executable code)"

Page 38: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Search time scales with weighted path length"

m = 1.26

Page 39: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Why it works"

•  Powerful intermediate representation"•  Weighted path greatly reduces search space"•  Minimization eliminates unnecessary fixes"•  Most bugs can be fixed with a few local modifications"

–  667 average atomic genetic operations to discover a repair; Repair discovered on average in 3.6 generations; 2.9 genetic operations per fitness evaluation"

–  About 1/2 the time, Random Search does as well as GP "•  Will this scale to more complex problems? "

Page 40: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

References"

•  W. Weimer, T. Nguyen, C. Le Goues, and S. Forrest “Automatically finding patches using genetic programming.” 31st International Conference on Software Engineering (ICSE) (2009). "

•  S. Forrest, W. Weimer, T. Nguyen, and C. Le Goes “A Genetic Programming Approach to Automated Software Repair.” Genetic and Evolutionary Computation Conference (in press)."

•  C. Le Goues, T. Nguyen, W. Weimer, and S. Forrest “Closed-Loop Repair of Security Vulnerabilities.” ETAPS(Submitted Oct. 2009). "

Page 41: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Permutation Problems and Special Operators"

•  Problem: Find an optimal ordering for a sequence of N items. "•  Examples:"

–  Traveling Salesman Problem (TSP)"–  Bin packing problems"–  Scheduling"–  DNA fragment assembly"

•  Traveling Salesman Problem:"

4

3

1

2

6

6 2

2 5 3

Page 42: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Using Genetic Algorithms to Find Good Tours for TSP"

•  Natural representation: Permutations in which each city is labeled by a unique integer (bitstring): 3 2 1 4 4 1 2 3"

•  Problem: Mutation and crossover do not produce legal tours: 3 2 2 3"

•  Solutions:"–  Other representations."–  Other operators."–  Penalize illegal solutions through fitness function."

Page 43: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Specialized Operators"

•  What information (schemas) should be preserved?"–  Absolute position in the sequence"–  Relative ordering in the sequence (precedence)"–  Adjacency relations"

•  How much randomness is introduced?"•  Order crossover (Davis, 1985)"•  Partially-mapped crossover (PMX) (Goldberg, et al. 1985)"•  Cycle crossover (Oliver, et al. 1987)"•  Edge-recombination:"

–  Try to preserve adjacencies in parents"–  Favor adjacencies common to both parents"–  When 1,2 fail, make a random selection."

Page 44: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Edge Recombination Operator"

Algorithm:"

1. Select one parent at random and assign the first element in its permutation to be the first one in the child."

2. Select the second element for the child, as follows:"If there is an adjacency common to both parents, then choose that."If there is an unused adjacency available from one parent, choose it."If (1) and (2) fail, then pick an adjacency randomly."

3. Select the remaining elements in order by repeating step 2."

Page 45: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Edge Recombination Example"

3 6 2 1 4 5

5 2 1 3 6 4 3 6 4 1 2 5

Original Individuals New Individual

Key Adjacent Keys 1 2,2,3,4, 2 1,1,5,6, 3 1,6,6, 4 1,5,6 5 2,4 6 2,3,3,4

Page 46: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Using Genetic Algorithms to Model Natural and Artificial Systems"

•  Modeling social systems"–  Evolution as a model of imitation (Prisonerʼs Dilemma)"–  Economies (stock market)"

•  Cognitive systems"–  Induction and learning (Classifier Systems)"

•  Genetic evolution"–  Natural ecological systems (Echo)"–  Immune systems"

•  Somatic evolution in CancerSim"–  Ecosystem modeling"–  Artificial life models"

•  In each of these systems, adaptation is central"–  What can we learn from modeling with genetic algorithms?"

Page 47: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Using Complex Systems Approaches to Model Social Systems"

•  Societies and political systems"–  Sugarscape models (related to Cellular Automata)"–  George Gummermanʼs agent-based simulation of Anasazi settlements."

•  Economies"–  Stock market models"–  Econophysics approaches to understanding financial markets."

•  Game theory / non-zero sum games "•  Ant colony models (social insects). "

Page 48: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Evolution of Cooperation(Axelrod, 1984)"

•  What is the Prisonerʼs Dilemma?

•  Non-zero sum game:"–  Total number of points is not constant for each configuration."

•  What is the best move for Player 1? "•  Player 2?"

Player B

Cooperate DefectCooperate 3,3 0,5

Player A Defect 5,0 1,1

Page 49: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Prisonerʼs Dilemma cont."

•  Iterated Prisonerʼs Dilemma:"–  Play game for an indeterminate number of steps."–  Raises possibility of strategies based on the behavior of the other player."

•  What are the possible strategies?"

Page 50: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Prisonerʼs Dilemma cont."

•  Iterated Prisonerʼs Dilemma:"–  Play game for an indeterminate number of steps."–  Raises possibility of strategies based on the behavior of the other player."

•  What are the possible strategies?"–  RANDOM"–  Always cooperate, always defect"–  Tit-For-Tat"–  Model other player and try to maximize against that model."–  etc."

Page 51: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Evolution of Cooperation"

•  ~1980 Two tournaments:"–  Each strategy (entry) encoded as a computer program."–  Round robin (everyone plays everyone)."–  Tit-For-Tat (TFT) won both times."

•  1982-85 Learning algorithms:"–  Can TFT evolve in a competitive environment? How could a TFT strategy

evolve in nature?"–  Is there a better strategy?"–  How do strategies develop?"

•  Use genetic algorithm to study these questions,"–  In environment of tournament."–  In a changing environment (co-evolution)."–  In a 3-person game."–  In an n-person game."–  In a “Norms” game."

Page 52: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Prisonerʼs Dilemma Using Genetic Algorithm"

•  Population consists of individual strategies:"–  1 strategy per chromosome."

•  Encoding ?"•  Fitness function?"

Page 53: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Prisonerʼs Dilemma Using Genetic Algorithm"

•  Population consists of individual strategies:"–  1 strategy per chromosome."–  Each chromosome is a 64 (70) bit string."–  Each bit specifies the strategyʼs next move (cooperate or defect) for one

particular history of 3 moves."•  Encoding:"

–  Need to remember each playerʼs move for 3 time steps==> 6 pieces of information."

–  At each point, either player could cooperate or defect (binary decision)."–  ∴26 = 64 possible histories."–  Value of bit at a given position tells strategy what to do (0 = coop, 1 =

defect) in the context of that history."–  Additional 6 bits encodes assumption about previous interactions before the

start of the game."

Page 54: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Prisonerʼs Dilemma Encoding cont."

•  Let A be the sum formed by,"–  Counting the otherʼs defection as 2"–  Counting my own defection as 1,"

•  And giving weights of,"–  16 to the most recent moves,"–  4 to the move two time steps in the past, and"–  1 to the move three time steps in the past."

•  E.g.,"–  History of mutual cooperation for 3 time steps ==> 0."–  History of mutual defection for 3 times steps ==> 63."

Page 55: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Prisonerʼs Dilemma Encoding cont."

•  Let A be the sum formed by,"–  Counting the otherʼs defection as 2"–  Counting my own defection as 1,"

•  And giving weights of,"–  16 to the most recent moves,"–  4 to the move two time steps in the past, and"–  1 to the move three time steps in the past."

•  E.g.,"–  History of mutual cooperation for 3 time steps ==> 0."–  History of mutual defection for 3 times steps ==> 63."

•  What history should we assume for first 3 moves?"–  Mutual cooperation."–  Genetically determined (need 6 more bits)."

Page 56: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Prisonerʼs Dilemma Using GA Fitness Function"

•  Environment of tournament: "–  Select 8 strategies from ~160 tournament entries that predict performance,

and play each candidate strategy against those 8 representatives."•  Co-evolutionary environment:"

–  Strategies play against other strategies in the population."

Page 57: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Results for Fixed Env."

•  From a random start, the GA evolved populations whose median member was just as successful as TFT."

•  Most of the evolved strategies resemble TFT."•  In some rules, strategies were discovered that did significantly

better than TFT (in tournament env.):"–  Discriminates between different opponents (based only on its behavior)."–  Adjusts its own behavior to exploit an exploitable opponent."–  Does this without getting into (too) much trouble with other opponents."–  Achieved this by defecting on first move, and then apologizing when

necessary."

Page 58: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Results in Evolving Environment(From Axelrod, 1997)"

Page 59: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Social Norms"

•  Powerful mechanism for regulating conflict in groups"–  Even with more than two agents and no central authority"

•  How do norms evolve in the first place?"•  What makes them stable? Why do they change so quickly?"•  Examples:"

–  Dueling: Alexander Hamilton v. Aaron Burr"–  Smoking in public"–  Gender-laden language"–  Prohibition against chemical warfare"–  Democratic movements in the Arab world?"

A norm exists in a given social setting to the extent that individuals usually act in a certain way and are often punished when seen not to be acting in this way"

Page 60: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Norms Game"

Page 61: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Studying the Evolution of Norms with Genetic Algorithms"

•  Each individual represents a strategy for playing the Norms game: <B,V>"

•  3 bits per dimension (6 bits total)"–  8 different values for B; 8 different values for V"

•  Pop size = 20"•  Fitness:"

–  Each individual receives 4 opportunities to defect"–  Chance of being seen drawn from uniform distribution and compared to B"–  If individual observes a defection, it Enforces the norm with probability

determined by V"•  Run experiments for 100 generations"

Page 62: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Norms Game Dynamics"

Page 63: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Comments"

•  Relying on individuals to punish defectors may not be enough to enforce the norm"

•  Possible mechanisms for enforcing norms"–  Metanorms (e.g., honor codes)"–  Dominance of one group over another "

•  e.g., whites lynching blacks in South but not vice versa"•  E.g., Libya trying to extend the international norm of a 12-mile limit of territorial

waters."–  Internalization (psychological pain for violating norm)"–  Deterrence"

Page 64: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Meta Norms"

Page 65: Introduction to Scientific Modelingforrest/classes/cs365/lectures/...References" • J. H. Holland Adaptation in Natural and Artificial Systems. Univ. of Michigan Press (1975). Second

Metanorms Dynamics"