-1

In the book Modelling Cellular automata Simulations with mathematica , the author is using the following code to simulate cellular automata in a two dimensional lattice,

From the Moore Neighbourhood the update rule is

update[site, N, E, S, W, NE, SE, SW, NW]

where N =North, E= East , S=South, W=West, NE= North East, SE=South East, SW= South East, NW=North West. Those arguments represent the values of the nearest neigbours in the Moor Neighbourhood. To apply those rules it uses the code below,

Moore[func_, lat_]:= MapThread[func,Map[RotateRight[lat,#]&,
{{0,0},{1,0},{0,-1},{-1,0},{0,1},
{1,-1},{-1,-1},{-1,1},{1,1}}],2]

For a table like the following (page 144 from the book)

pasture= Table[Floor[Random[]+(preyDensity+predDensity)]*
Floor[1+Random[]+predDensity/(preyDensity+predDensity)],{n},{n}]/. 
2:>{RND,Random[Integer, {1,3}],Random[Integer,{1,5}]}

RND:= Random[Integer, {1,4}]

he is using the following update rule

update[{_,0,0},_,_,_,_,_,_,_,_]  := {RND, 3,5}

My question is: By using a four dimensional table like the following? Can I also apply the following update rule?

InitialMatrix[x_, y_, age_, disease_] :=
  ReplacePart[
    Table[3, {x}, {y}, {age}, {disease}], {{_, _, 1, _} -> 
  0, {_, _, 2, 1} -> 
  Floor[dogpopulation*0.2/cellsno], {_, _, 2, 3} -> 
  Floor[dogpopulation*0.05/cellsno], {_, _, 3, 1} -> 
  Floor[dogpopulation*0.58/cellsno], {_, _, 3, 3} -> 
  Floor[dogpopulation*0.15/cellsno]}] /. 
  3 :> If[RandomReal[] > 0.2, 0, RandomInteger[{1, 2}]];


update[{{x_,0,0},{y_,z_,w_},{a_,b_,c_}},_,_,_,_,_,_,_,_] :=
                                            {{x-1,0,0},{y+z,0,w},{a,b,c}}

This is an example of how I think I can use my table to work with cellular automata. Can I do something like that? Or I am wrong?

Edit my table

By changing my table into the following code below can I use the update rule above?

MyMatrix[x_, y_, age_, disease_] :=
  Table[0, {x}, {y}] /. 
    0 :> ReplacePart[
      Table[3, {age}, {disease}], {{1, _} -> 0, {2, 1} -> 
    Floor[dogpopulation*0.2/cellsno], {2, 3} -> 
    Floor[dogpopulation*0.05/cellsno], {3, 1} -> 
    Floor[dogpopulation*0.58/cellsno], {3, 3} -> 
    Floor[dogpopulation*0.15/cellsno]}] /. 
   3 :> If[RandomReal[] > 0.2, 0, RandomInteger[{1, 2}]];
rcollyer
  • 10,475
  • 4
  • 48
  • 75
noni
  • 67
  • 1
  • 9
  • I was wondering when you were going to find the connection to CAs. Given the problems you have had so far with the approach you are currently working on, switching midstream might just confuse the issue. In any case, you are applying a rule for a 3*3 matrix to a four-dimensional tensor, so I'm not sure the rule will match. You will need to edit the rule to get it to match. Also, that book is 15 years old and some of the code could be revamped. Remember people's earlier suggestions about BernoulliDistribution and BinomialDistribution. They weren't there 15 years ago. – Verbeia Jul 08 '11 at 04:36
  • "...This book will have a DOS-diskette packaged with it..." it says on Amazon. - Would it? – nilo de roock Jul 08 '11 at 09:37
  • @ndroock1 yes it has but I don't have it because I bought it from second hand. @Verveia I know that the book is very old and it's true that some codes had changed, but is the only book that I found to be so helpfull about cellular automata in mathematica but because my table is four dimensional like you said I am not sure if I can apply this rule. Note: every 3x3 matrix in my table is one cell in cellular automata – noni Jul 08 '11 at 13:43
  • I just notice that I wrote @Verbeia wrong in my previus post. – noni Jul 10 '11 at 00:10

2 Answers2

1

The book Modelling Cellular automata Simulations with mathematica was written more than 15 years ago, so would recommend looking at the CellularAutomaton[] function in Mathematica.

The function CellularAutomaton[] is a little complex, but if you want to do 2D Moore CA this is how you call this function:

CellualrAutomaton[{func[#]&,{},{1,1}},initialMatrixVal, numIterations];

What the above code will do is call function func[], with the Moore neighborhood as fn param for each and every node in initialMatrixVal for "numIterations" times.

The CellularAutomaton[] function assumes Periodic boundary conditions.

Hope that helps!

stats
  • 71
  • 1
  • Yes, func[] is the update rule. So for ex. the function: Moore[func_, lat_] is equivalent to calling CellularAuomaton[] once, CellularAutomaton[{func[#]&,{},{1,1}}, lat, 1]. – stats Jul 11 '11 at 01:36
  • Thank you very much!! Can I check my solutions by doing it with both methods? CellularAutomaton and Moore? – noni Jul 11 '11 at 03:17
  • I mean everything that I have done until now on my project it will stay as it was and I have to change the Moore function to improve my code. Isn't it? – noni Jul 11 '11 at 03:40
  • Yes, you can use this as the new Moore[] function. You can further simplify by eliminating the need for NestList[] and specify the number of steps in CellularAutomaton[] function... – stats Jul 11 '11 at 04:54
  • With the moore code in my question, my model works fine but I tried to change it with the code you gave me and it is giving me errors, is this logical? Do I have to do something else? – noni Jul 14 '11 at 19:15
1

Most of the code for the book "Modelling Cellular automata Simulations with mathematica" can be found in the Wolfram web site (library.wolfram.com ?). If you search for the author's name you will find example code for most of the topics covered in the book.

I probably have the code for most of the examples in the book, if you are interested let me know.

Good luck!

stats
  • 71
  • 1