4
$\begingroup$

How can I use the CellularAutomaton function to create a 2D automaton using a custom function and k colors?

I understood from this post how to use custom rules for 1D automata.

I'm trying now to do that for 2D automata but I don't quite understand how CellularAutomaton is reacting to this.

I tried this to see what the general function gets:

CellularAutomaton[{Print[#] &, {}, {1, 1}}, {{{1}}, 0}, 1]

And I see that I get a matrix representing, I assume, the possible cases for rules

enter image description here

Compare this to the 1D case

enter image description here

But I still don't completely understand how to interpret this matrix and how to use more colors.

My final goal is to create this kind of cyclic automata using the CellularAutomaton function

Any kind of help would be useful. Thanks

$\endgroup$
4
  • $\begingroup$ Can you put more information? I mean what is the input of your function and how you plotted it? $\endgroup$ Commented May 27, 2020 at 7:07
  • $\begingroup$ @wandermonde I solved it. The approved answer is the one I did. About the input, it's just an implementation of this paper (math.ucdavis.edu/~gravner/papers/cca.pdf). To plot it it's just an ArrayPlot $\endgroup$
    – xtian777x
    Commented May 28, 2020 at 13:33
  • $\begingroup$ @wandermondeI'm actually working on a computational essay about this. It's not ready yet (and will probably be posted in the Wolfram Community). Once it's done I can let you know here. If you have other questions please let me know. $\endgroup$
    – xtian777x
    Commented May 28, 2020 at 13:37
  • $\begingroup$ @wandermonde You can see other preliminary CCA work I did here: wolfr.am/MSTvSyVA $\endgroup$
    – xtian777x
    Commented May 28, 2020 at 13:56

2 Answers 2

4
$\begingroup$

I did it. It's probably not the best implementation but works. Any feedback about how to optimize the code would be highly appreciated.

CyclicFunction[N_,matrix_,preylist_]:=Module[{cell=matrix[[2,2]],prey},prey=preylist[cell];If[MemberQ[Flatten[matrix],prey],prey,cell]]

CyclicCellularAutomaton[k_,size_,steps_]:=With[{preylist=Association@@Function[u,u-> RotateLeft[Range[0,k-1],u][[2]]]/@Range[0,k-1]},CellularAutomaton[{CyclicFunction[k,#,preylist]&,{},{1,1}},RandomInteger[{0,k-1},size],{{{steps}}}]]

BTW, I exported the evolution of the automaton as a gif but doesn't loop infinitely...why is that?

enter image description here

$\endgroup$
2
$\begingroup$

Every possible 2D function is enumerated in CellularAutomaton, so you need merely pick the function number. To get your desired colors, use ColorFunction, e.g.,

ArrayPlot[
 CellularAutomaton[{746, 
     {2, {{2, 2, 2}, {2, 1, 2}, {2, 2, 2}}}, 
     {1, 1}}, 
     {{Table[1, {7}]}, 0}, {{{150}}}],
 ColorFunction -> "Rainbow"]

or

ColorRules -> {0 -> Red, 1 -> Green, _ -> Black}

If you want to write your own function, look at the documentation for CellularAutomaton to see examples, such as:

CellularAutomaton[{Total[#] &, {}, 1/2}, {{1}, 0}, 5] // Grid
$\endgroup$
2
  • 1
    $\begingroup$ How do you go from an arbitrary function to a function number? I want to write my own function, i.e. using the rule form {fun,{},rspec} $\endgroup$
    – xtian777x
    Commented Mar 16, 2017 at 20:44
  • 1
    $\begingroup$ As I mentioned in my post, I already know how to write my own function for 1D. What I'm asking is how to do that for 2D automata. Examples in the ref pages are for 1D $\endgroup$
    – xtian777x
    Commented Mar 16, 2017 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.