Docsity

Using Genetic Algorithms to Evolve Cellular Automata Rules - Assignment 2 | CS 591, Assignments of Programming Languages

Toggle sidebar
bg1
Using&Genetic&Algorithms&to&Evolve&Cellular&Automata&Rules&
Complex&Adaptive&Systems,&CS&591&
Assignment&2&
Due&March&31,&2008&
!
Introduction&&&Setup&
In!this!assignment!you!will!use!a!genetic!algorithm!(GA)!to!evolve!rules!for!a!SIR!CA!
that!maximizes!the!fitness!of!a!virus.!You!may!work!in!pairs.!
!
The!CA!
The!CA!has!4!states:!(0=!EMPTY,!1=!SUSCEPTIBLE,!2=INFECTED,!3=RECOVERED).!
One!rule!set!for!such!a!CA!is!described!in!Assignment!1,!part!2.2.!There!are!
constraints!on!the!transition!rules!such!that!the!cells!have!a!predetermined!cycle!of!
states;!they!can!go!from!0!‐>1!‐>!2!‐>!3!‐>0,!so!that!cells!can!potentially!cycle!
indefinitely.!Assignment!1!Rule!Set!2!gives!one!set!of!transition!rules:!
1.!A!cell!transitions!from!state!0!to!1!if!2&or&more!neighbors!are!in!state!0!(birth)!
2.!A!cell!transitions!from!state!1!to!2!if!2&or&more!neighbors!are!in!state!2!(infection)!
3.!A!cell!transitions!from!2!to!3!if!4&or&fewer!neighbors!are!in!state!2!(recovery)!
4.!A!cell!transitions!from!state!3!to!0!if!3&or&more!neighbors!are!in!state!3!(death)!
If!these!conditions!are!not!met,!the!cell!stays!in!its!current!state.!
Your!job!in!this!assignment!is!to!evolve!a!new!set!of!rules,!that!have!the!same!
structure!as!the!4!rules!above,!in!order!to!maximize!the!number!of!infections!that!
the!virus!can!create.!Preserve!the!transition!cycle!(0!‐>1!‐>!2!‐>!3!‐>0),!and!the!
dependencies!of!the!states!(e.g.,!the!transition!from!0!to!1!depends!on!the!number!of!
neighbors!in!state!0,!and!neighbors!in!other!states!are!irrelevant.)!You!should!also!
preserve!the!>=!condition!in!rules!1,2!and!4!and!the!<=!relationship!in!rule!3.!
To!do!this,!you!will!need!to!‘evolve’!4!separate!numbers:!
A=!the!min!number!of!neighbors!in!state!0!that!cause!a!cell!to!transition!from!0!to!1!!
B=!the!min!number!of!neighbors!in!state!2!that!cause!a!cell!to!transition!from!1!to!2!
C=!the!max!number!of!neighbors!in!state!2!that!cause!a!cell!to!transition!from!2!to!3!!
D=!the!min!number!of!neighbors!in!state!3!that!cause!a!cell!to!transition!from!3!to!0!
!
The!CA!should!use!a!Moore!neighborhood,!so!there!are!8!possible!neighbors.!Use!a!3!
bit!string!to!represent!the!number!of!neighbors,!and!use!Gray!codes!to!avoid!the!
Hamming!cliff.!(There!are!actually!9!possible!conditions!to!consider!since!0!to!8!
neighbors!could!be!in!the!relevant!state.!To!make!things!easier,!don’t!allow!your!
rules!to!cause!a!transition!with!0!neighbors.!Then!you!have!8!numbers!to!consider!
and!can!use!a!3!bit!gray!code!for!each!number.)!For!this!simple!case,!you!will!have!a!
very!short!(12!bit)!string!to!evolve.!!
!
pf3
pf4

Partial preview of the text

Download Using Genetic Algorithms to Evolve Cellular Automata Rules - Assignment 2 | CS 591 and more Assignments Programming Languages in PDF only on Docsity!

Using Genetic Algorithms to Evolve Cellular Automata Rules

Complex Adaptive Systems, CS 591

Assignment 2

Due March 31, 2008

Introduction & Setup

In this assignment you will use a genetic algorithm (GA) to evolve rules for a SIR CA that maximizes the fitness of a virus. You may work in pairs. The CA The CA has 4 states: (0= EMPTY, 1= SUSCEPTIBLE, 2=INFECTED, 3=RECOVERED). One rule set for such a CA is described in Assignment 1, part 2.2. There are constraints on the transition rules such that the cells have a predetermined cycle of states; they can go from 0 ‐>1 ‐> 2 ‐> 3 ‐>0, so that cells can potentially cycle indefinitely. Assignment 1 Rule Set 2 gives one set of transition rules:

  1. A cell transitions from state 0 to 1 if 2 or more neighbors are in state 0 (birth)
  2. A cell transitions from state 1 to 2 if 2 or more neighbors are in state 2 (infection)
  3. A cell transitions from 2 to 3 if 4 or fewer neighbors are in state 2 (recovery)
  4. A cell transitions from state 3 to 0 if 3 or more neighbors are in state 3 (death) If these conditions are not met, the cell stays in its current state. Your job in this assignment is to evolve a new set of rules, that have the same structure as the 4 rules above, in order to maximize the number of infections that the virus can create. Preserve the transition cycle ( 0 ‐>1 ‐> 2 ‐> 3 ‐>0), and the dependencies of the states (e.g., the transition from 0 to 1 depends on the number of neighbors in state 0, and neighbors in other states are irrelevant.) You should also preserve the >= condition in rules 1,2 and 4 and the <= relationship in rule 3. To do this, you will need to ‘evolve’ 4 separate numbers: A= the min number of neighbors in state 0 that cause a cell to transition from 0 to 1 B= the min number of neighbors in state 2 that cause a cell to transition from 1 to 2 C= the max number of neighbors in state 2 that cause a cell to transition from 2 to 3 D= the min number of neighbors in state 3 that cause a cell to transition from 3 to 0 The CA should use a Moore neighborhood, so there are 8 possible neighbors. Use a 3 bit string to represent the number of neighbors, and use Gray codes to avoid the Hamming cliff. (There are actually 9 possible conditions to consider since 0 to 8 neighbors could be in the relevant state. To make things easier, don’t allow your rules to cause a transition with 0 neighbors. Then you have 8 numbers to consider and can use a 3 bit gray code for each number.) For this simple case, you will have a very short (12 bit) string to evolve.

The GA Sample Matlab code for a GA (created by George Bezerra) is posted online. That code uses tournament selection, mutation and 2 point cross‐over to evolve a string with the maximum number of ones. You may start with this code and modify it, or you may find other code online, or you may write your own. Your GA should evolve a string which forms the rule set of the CA described above. Your fitness function ( f ) is simply f = I , where I is the number of new infections produced over a run of the CA. That is, you should calculate the fitness of the string by passing that string to your CA, running the CA, and measuring the number of infections produced. Be aware that you cannot simply add up the number of infected cells at each time step. If a cell is infected for 10 time steps, it only counts as 1 infection. I is the number of transitions from state 1 to state 2. You can use that raw value as your fitness function, and with tournament selection there is no need to normalize the fitness values (e.g. if 1700 infections occur using the rule set encoded by string1, then f (string 1 ) = 1700.) This approach is valid if you run the CA with a fixed grid size for a fixed number of iterations for each run of your GA. You will want to run your CA as efficiently as possible (with no extraneous functionality like displaying the state of the CA to the screen), since you will have to run the CA many times for each tournament for many generations of the GA. Initial conditions Initialize your CA with a fully susceptible population with no empty spaces, and all cells in state 1, EXCEPT, set 8 cells in a row in the center of your CA to be infected. This represents a new virus infecting a fully susceptible population. (You need 8 initially infected cells in order to allow B to equal any value up to 8.) Set your CA to a 20x20 grid. The number of iterations is up to you, but be sure to run your CA long enough for new births to significantly increase the number of infections (without births, there are only 400 possible infections no matter how long you run the CA.) First initialize your GA by following suggestions made in Dr. Forrest’s lecture for the size of the tournament, the number of generations for the GA, mutation rates and cross over rates (given that you have a small string of only 12 bits).

Report

Your report should be no more than 10 pages of text, excluding code and figures. Figures should be embedded into your report, and you should include a printout of your code as an appendix. The report should include the following:

  1. Introduction: State the problem you are trying to solve in your own words and why your approach is useful.
  2. Methods: Describe a) how you solved the problem, e.g., which genetic algorithm software you used, its basic algorithms (what kind of selection, crossover, mutation, etc.) b) how your bit string encodes rules for the CA and c) the basic parameters for each of your GA runs (population size, generation time, crossover rate, mutation rate, etc) and e) How you calculated your fitness function.
  3. Results: Report a) the best, or best few, strings you evolved for each experiment, the fitness of those strings, and a description of the CA behavior with those strings b) a description of how your population of strings improved over time, with figures showing fitness vs. generation of your GA c) how you changed your GA and CA for the 2nd, 3rd, and 4 th^ experiments, and the results of those changes. d) how well your CA rules work with different initial conditions
  4. Discussion and analysis of your results: Explain
    1. the behavior of the most fit CA’s that you can evolve. What are common features among the best rule sets, and why do they maximize fitness?
    2. Explain why a GA is or is not a good way to find an interesting CA rule set.
    3. Discuss how easy or difficult it is to find a set of rules that maximizes the number of infections that occur. What do your experiments say about how easy it would be for a virus to evolve to maximize the number of infections it can cause?
    4. Summarize the most interesting results of your experiments.
  5. Provide a listing of your code, as an appendix of the report (not counted in the 10 page limit). It should be well‐commented.

Grading

Email your reports to [email protected] on March 31. Your grade will be determined by a) whether you correctly implemented your CAs and GAs and fitness functions (25%) b) the creativity of your solutions in experiments 2, 3 and 4 (25%), the fitness of your evolved CA’s (10%) the clarity and quality of your report (40%).