: 1 Outline: 2 Outline 110 Cellular Automata and Percolation Klaus Sutner 1 Cellular Automata 2 Percolation Carnegie Mellon University Spring 2011 Cellular Automata: 3 Recall: CA Cellular Automata: 4 Rules and Lookup Last time we saw how to implement (elementary) cellular automata: an ECA consists of a local rule that explains how a local configuration (the bit values of a cell plus its two neighbors) turns into a new bit at the next step. To get from an integer to the actual loookup table we have to convert to binary and pad out to 8 bits. rule = [] for i in range(8): rule.append( r % 2 ) r /= 2 Since there are 8 = 23 local configurations and we can choose one bit for each there are 256 = 28 local rules. They can be conveniently represented by an integer r in the range 0 ≤ r < 256. For example, r = 30 corresponds to the rule 000 001 010 011 →0 →1 →1 →1 100 101 110 111 Given a configuration A we can then determine the next bit at position i by calculating an index for the table rule: →1 →0 →0 →0 Cellular Automata: Cyclic and Fixed Boundary Conditions There are two standard methods to deal with missing neighbors at either end of the grid. Cyclic boundary conditions Pretend that the linear sequence of cells is circular so that A[0] and A[n-1] are adjacent. This comes down to looking at positions A[i % n]. Fixed boundary conditions Pretend that there are cells in positions −1 and n that are always in state 0. This requires extra conditionals. 4*A[i-1] + 2*A[i] + A[i+1] But note that one has to be careful with boundary conditions i = 0 and i = n − 1. 5 Cellular Automata: The Main Loop The main function computing the evolution of an ECA then looks like so: def evolution_ca( ca, seed=’onePoint’, width = 81, time = 40 , boundary = ’cyclic’, prob = 0.5 ): rule = convert_to_rule( ca ) A = construct_seed( width, seed, prob ) orbit = [A] for i in range(time): B = next_configuration( A, rule, boundary ) orbit.append( B ) A = B return orbit 6 Cellular Automata: 7 The Parameters Cellular Automata: 8 Pretty-Printing The parameters in evolution ca have the following meaning | | | | | | | | | | | | | | | | | | | | | ca an integer in 0 to 255, denotes the ECA seed determines the initial configuration width the number of cells in the grid time the number of steps to perform boundary the type of boundary condition to be used prob for random initial configurations: the probability to be used (this is a hack). 9 ECA 28 Cellular Automata: ECA 45 | | | | | | | | | | | | | | | | | | | | | Using only ASCII symbols we can get reasonably nice pictures, though graphics really makes a difference here, see below. This is rule 90 on a one-point seed. Of course, there is more one could add. For example, one might want to return only the last t steps in the evolution, or just some part of the grid, or one might want to grow the grid when the typical triangles hit the boundary, or or or . . . Cellular Automata: o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o Cellular Automata: 10 ECA 28 11 Cellular Automata: ECA 54 12 Cellular Automata: 13 ECA 73 Cellular Automata: Randomness and Universality The patterns generated by ECA 30 seem quite chaotic and very hard to predict. S. Wolfram managed to turn this adversity into an advantage: he proposed to use ECA 30 as a (pseudo-) random number generator (Connection Machine, Mathematica). It is quite surprising and really counterintuitive that something as simple as an ECA could produce “randomness.” Here is an even more astonishing ECA: rule 110 (see the following pictures). It produces very complicated, long-lived structures. With a huge amount of effort one can show that it is possible to implement a computer using rule 110: one has to construct very complicated and large initial configurations. Running rule 110 on these configurations one can perform arbitrary computations, albeit very slowly and inefficiently. 14 ECA 90 15 ECA 30 Cellular Automata: Cellular Automata: Cellular Automata: 16 ECA 30 17 Cellular Automata: ECA 110 18 Cellular Automata: 19 ECA 110 Percolation: Cellular Automata: 20 ECA 110 21 Percolation: 22 Percolation 2 Everyone knows from daily experience that fluids can move through porous materials: just brew a cup of coffee. Alas, the theory of percolation is quite difficult and there are lots of open problems. Simulations can help greatly to understand how percolation works. Cellular Automata We can get a cheap two-dimensional model of percolation by using two-dimensional grid of “cells” as before for cellular automata. We initialize a grid by random 0’s and 1’s where 0 indicates a free cell whereas 1 indicates a blocked cell. The liquid can flow from a free cell to its 4 edge-adjacent neighbors (north, south, east, west) in the grid provided they are free. Percolation There is an inexhaustible source of liquid at the center of the grid (which we may safely assume to be free). Percolation: Two Examples 23 Percolation: Explanation In the pictures, dark blue indicates a blocked cell, light blue a free one. The purple square marks the center cell. Yellow indicates the presence of liquid. In the grid on the left only a few cells are flooded, but on the right we have reached the edges of the grid. The right grid is said to percolate. Think of yellow as toxic sludge and the edge as the area where drinking water is drawn from. 24 Percolation: 25 Implementation Percolation: 26 Bookkeeping Initially only the center cell is flooded. Clearly we need to explore the neighbors of a wet cell to see who is free and thus gets flooded, too. And then repeat. This can be done by basic bookkeeping: initialize task list T We need to be careful about two things: while( T not empty ) pick t from T, remove it act on t, possibly adding new tasks to T only add tasks that are new All flooded cells must be reached at some point in the search. Every flooded cell should be touched only once. T can be a list. Note that there are choices: which task to pick, where to put the new tasks. Two standard data structures are stacks and queues, more on this later. The first condition is just correctness. The second relates to efficiency, but also to correctness: if we get caught in an infinite loop the algorithm fails. Percolation: 27 Random Grids Percolation: Blocking Probability Obviously, if all cells are free the grid percolates. If all cells are blocked it does not. Of interest are grids where each cell has some probability p of being blocked. Given a probability p, 0 ≤ p ≤ 1, we place a 1 into position (i, j) with probability p, independently for each cell (note that this is not quite realistic, near a rock it is more likely to have more rock, but let’s not quibble). In code this looks something like Intuitively, the higher the blocking probability the lower the probability that the grid percolates. So if we generate many random grids for each blocking probability and determine the frequency of percolation, one should see an increasing curve going from 0 to 1 as the blocking probability decreases from 1 to 0. rr = random.random() if rr < p: row.append(1) else: row.append(0) The surprising observation is that there is a phase transition: there is a threshold value pc for the blocking probability so that for p < pc a grid almost always percolates, but for p > pc it almost never does. Percolation: 29 A Trial Run 1.0 0.8 0.6 0.4 0.2 20 40 60 80 100 A simple experiment showing percolation probability on grids of size 50 × 50. Blocking probability decreases from left to right. 28
© Copyright 2026 Paperzz