TP n°2 R
Elementary cellular automata
This practical exercise is taken and translated from a practical exercise given by Vincent Runge in 2022 for bionformatics students.
Part 1. The rule 90
Our goal is to study the simulation of elementary cellular automata on R.
An elementary cellular automaton is a 1 dimension cellular automaton defined by a single number, from which we derive the rule that defined the transition from one generation to the next one.
Elementary cellular automata can have various output.
Some similar patterns can be found in nature, for instance on Conus textile shell:
- Build a matrix filled with 0 of size \(n \times m\) with \(n = 100\) and \(m = 50\).
- Fill the first line with a random sampling of 1 and 0.
We will fill the next lines from 2 to \(n\) using the following rule:
current pattern 111 110 101 100 011 010 001 000 new state for center cell 0 1 0 1 1 0 1 0 That is to say, under a 111 we will write a 0 in the matrix; under 110 we will write 1 in the matrix and so on.
Write a lop to fill all lines. Display the result with the
imagefunction.- Do you understand why this rule is called the rule 90?
Part 2. Any rule
- Write a function that returns the following line, given the current line for any rule. The rule should be given as a parameter to your function.
- Check whether you find the dynamics of the rules proposed on the Wikipedia page https://en.wikipedia.org/wiki/Elementary_cellular_automaton.
- Write a function to run the overall simulation.
Part 3. Study dataframe
We want to study the proportion of 1 at the end of the simulation in function of the rule. We will create a dataframe with the column 1 the experiment identifier, column 2 the rule number and column 3 the proportion of 1 in the last generation.
Choose a set of rule numbers. Make a series of simulations of elementary cellular automaton with these rule numbers and store the results in the dataframe.
- Are there rules that are more likely to return more 0 at the end of the simulation ?
- Could you predict the results? How? What hypothesis can you make regarding the link between the rule number and the final proportion of 1? How could you test this hypothesis?
Part 4. Mix the rules
We will now mix 2 rules on the same simulation. For instance, we will apply the rule 18 to obtain the second line, then the rule 22, then we start again with the rule 18. Try to find some interesting results.