15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

212 CHAPTER 12. CELLULAR AUTOMATA II: ANALYSISbetween a configuration <strong>and</strong> its unique ID number (from 0 <strong>to</strong> 2 L − 1; 511 in our example),arranging <strong>the</strong> bits in <strong>the</strong> order <strong>of</strong> <strong>the</strong>ir significance from left <strong>to</strong> right. For example, <strong>the</strong>configuration [0, 1, 0, 1, 1, 0, 1, 0, 1] is mapped <strong>to</strong> 2 7 + 2 5 + 2 4 + 2 2 + 2 0 = 181. Thefunction config receives a non-negative integer x <strong>and</strong> returns a list made <strong>of</strong> 0 <strong>and</strong> 1, i.e.,a configuration <strong>of</strong> <strong>the</strong> CA that corresponds <strong>to</strong> <strong>the</strong> given number. Note that “&” is a logicalAND opera<strong>to</strong>r, which is used <strong>to</strong> check if x’s i-th bit is 1 or not. The function cf_numberreceives a configuration <strong>of</strong> <strong>the</strong> CA, cf, <strong>and</strong> returns its unique ID number (i.e., cf_numberis an inverse function <strong>of</strong> config).Next, we need <strong>to</strong> define an updating function <strong>to</strong> construct a one-step trajec<strong>to</strong>ry <strong>of</strong> <strong>the</strong>CA model. This is similar <strong>to</strong> what we usually do in <strong>the</strong> implementation <strong>of</strong> CA models:Code 12.2:def update(cf):nextcf = [0] * Lfor x in range(L):count = 0for dx in range(-r, r + 1):count += cf[(x + dx) % L]nextcf[x] = 1 if count > (2 * r + 1) * 0.5 else 0return nextcfIn this example, we adopt <strong>the</strong> majority rule as <strong>the</strong> CA’s state-transition function, whichis written in <strong>the</strong> second-<strong>to</strong>-last line. Specifically, each cell turns <strong>to</strong> 1 if more than half <strong>of</strong>its local neighbors (<strong>the</strong>re are 2r + 1 such neighbors including itself) had state 1’s, or i<strong>to</strong><strong>the</strong>rwise turns <strong>to</strong> 0. You can revise that line <strong>to</strong> implement different state-transition rulesas well.Now we have all <strong>the</strong> necessary pieces for phase space visualization. By plugging <strong>the</strong>above codes in<strong>to</strong> Code 5.5 <strong>and</strong> making some edits, we get <strong>the</strong> following:Code 12.3: ca-graph-based-phasespace.pyfrom pylab import *import networkx as nxg = nx.DiGraph()r = 2L = 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!