torsdag 29. mai 2014

So, what are Cellular Automata anyway?

Cellular Automata are simply a set of "cells" that change their state depending on their neighbours state. If a set of neighbours had a certain state in one generation, then their state in the next generation is defined by their state in the previous generation.

As an example, say you have five cells with this state in generation n:

0,0,0,1,0

And that we only worry about the immediate neighbours of each cell, what is their state in generation n +1?

To figure out what each cell's state is supposed to be in the next generation, we're going to have to define a set of "rules". That is, a table of neighbour-configurations and the corresponding next state, an example of this would be:

000 -> 1 (Read: Left neighbour is 0, Cell itself is 0, and Right neighbour is 0, then next state for this cell is 1)

For a full example of our selected set of cells we'll follow Rule 30 (named so according to the Wolfram classification scheme), which we can get from http://en.wikipedia.org/wiki/Rule_30#Rule_set.

The rules say that any cell that has a neighbour-configuration of 100,011,010 or 001, should be 1 in the next generation, and otherwise it should be 0. The middle digit in these configurations represent the cell itself, from this we can read that any cell that is 1 will become 0 unless either none of it's neighbours, or only it's right hand neighbour are 1. (Correspondingly, any 0-cell will become 1 if exactly one of it's neighbours are 1)

One question that is still not covered though: What are the neighbours of the edge-cells? Here we have a few options:
  1. We could say that they only have one neighbour (but then our rules wouldn't be generic) 
  2. We could let them "wrap", i.e. the leftmost node has the rightmost node as it's left neighbour, and vice verca
  3. We could make their neighbours a constant value (i.e. always 1 or always 0).
For this demonstration, we'll pick option 3, and let the edge cells have a constant 0-neighbour.

So, let's step through our five cells from right to left (numbering them from the left, to follow a convention that i'll come back to later):

Generation n + 1:
Cell 5: 0, neighbour-configuration: 000, next state: 0
Cell 4: 0, neighbour-configuration: 000, next state: 0
Cell 3: 0, neighbour-configuration: 001, next state: 1
Cell 2: 0, neighbour-configuration: 010, next state: 1
Cell 1: 0, neighbour-configuration: 100, next state: 1

This yields:
0,0,1,1,1

Now, following the same rules a few generations:
Gen n + 2: 0,1,1,0,0
Gen n + 3: 1,1,0,1,0
Gen n + 4: 1,0,0,1,1
Gen n + 5: 1,1,1,1,0
Gen n + 6: 1,0,0,1,1
...

Now, it's important to note one detail here, the neighbour-states that go into defining the state in generation (n+1) MUST be the states from generation n, thus we must take care when working with CA's, so that we don't use the state from generation (n+1) untill we're starting work on creating generation (n+2).

Ingen kommentarer:

Legg inn en kommentar