Demo 2: Constructing Networks

Making graphs from CAs

Note: Double-click the grey brackets on the right hand side to expand or collapse cells!
A filled triangle indicates it is a collapsed cell.

Sometimes, it’s fun to think about the world in terms of states and transitions between those states. From the previous demo, we see that CA are a great analogy for this. Let’s explore these transitions a little bit further...

What if we want to know all the possible transitions between all possible states, we can do that! All we need to do it run a single time step for every possible state, to see where each of them goes. Then we can mush all the results together to get a full picture.

Here are all the possible states for a CA of width = 3:

ics =Tuples[{0,1},3]

Now we want to run all these states in a CA.

result=Table[CellularAutomaton[0,ic,1],{ic,ics}]

So, as you can see for all possible initial states it always goes to all 0’s, since it is Rule 0.

And while we're at it, let’s see these transitions under all possible rules. Let’s do a double-loop! This Table function can have more than one variable to loop over. It will loop over the initial states, and then will loop that over all rules with this format:

results=Table[CellularAutomaton[r,ic,1],{r,0,255},{ic,ics}]

We don’t need to visualize these CAs. Instead, we want to visualize the transitions between states on a graph. Let’s do this for one rule, Rule 0. I draw arrows between what states go to where from our results in the previous Table double-loop:

results[[1]]

Rule@@@results[[1]]

If it is formatted with arrows this way, the Graph function can read this essentially as an edge list. That is basically a list of vertex1 -> (goes to) vertex2. Then it is easy to plot with Graph:

Graph[Rule@@@results[[1]],VertexLabels->"Name" ,PlotLabel->0]

You can do this with all the rules! We calculated the results for all the rules already, so simply select the rule you want and modify the above line. Remember, results[[1]] means Rule 0.

Bonus!

If you want to get really fancy, you can make your own Mathematica functions in addition to Table and Graph and Cellular Automata. Why would we want to do that? Well, what if we’d like to apply the arrows to ALL our CA results and then visualize them ALL on a graph? We would need to make a special function that calls both.

Let’s call this function f, cause we’re boring.
It takes in two variables, x and r. The first one x will be our big results Table. The second variable r will be the rule:

f[x_,r_]:=Graph[Rule@@@x,VertexLabels->"Name",PlotLabel->r,ImageSize->Medium ]

Now let’s apply our function in a loop to our results Table in a new Table loop!

Table[f[results[[r+1]],r],{r,0,255}]

Excellent!