Message Boards Message Boards

0
|
4024 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Increase efficiency of cellular automaton and combine values in datasets

Hi all,

I'm working on a model of self-organised critical systems following [B. Drossel and F. Schwabl, Physical Review Letters 69, 1629 (1992)] forest fire model to create a cellular automaton which counts the total number of fires within the lattice.

Given a matrix (100 x 100) with randomly generated integer values in range [0,2], on each timestep t, the matrix values will be updated according to 3 rules which change the values within the matrix, 0 -> 1 if rule1, 1 -> 2 if rule 2 etc. This would run over t time steps and then I would run the code "sample" number of times to create a pdf of the total count of each site.

I have attached the nb. Advice on increasing efficiency of the calculations is also more than welcome.

What I am trying to do next is create a dataset which notes the time taken for a 2 in the matrix to change back to a 2 after a series of rules has changed it cyclically from 2->0->1->2. Essentially looking at the wait times between the 2's occuring at a specific site.

To do this, I created a dataset:

wait = Dataset[{<|"run,i,j" -> {y, i, j}, "t" -> ii|>}];

Aiming to note which run of the code, where in the matrix the value 2 lies, and at what timestep it appears on. I would like to be able to append only the t values for a given value of {y, i , j} without duplication.

My first attempt to test these changes went like this:

n = 20;
sample = 4;
t = 10;
n = 20;
wait = Dataset[{<|"run,i,j" -> {y, i, j}, "t" -> ii|>}];
Nmat = Table[RandomInteger[{0, 1}], {n}, {n}];

For[y = 1, y < sample + 1, y++,

 For[ii = 1, ii < t + 1, ii++,

  For[i = 1, i < n + 1, i++,
    For[j = 1, j < n + 1, j++,

    If[Nmat[[i, j]] == 1,
     (*Add a value into the dataset noting the run and matrix \
component*)
     If[MemberQ[waittimes[[All, 1]], {y, i, j}],
      ]
     ]
    ]
   ]
  ]
 ]

However I get stuck on changing the values within the specifi row of the dataset. For example if a 2 occurs at "run,i,j" = {1,1,1} for t = 1 and then t = 5, I would like to append only the t column within the dataset where the specific row is {1,1,1}

Any help is more than welcome!

POSTED BY: Jon Rickett
3 Replies

Are you sure your algorithm cannot be implemented via CellularAutomaton function? See Details section (especially "general function to apply to each list of neighbors ") and many examples.

POSTED BY: Sam Carrettie

I'm sure it probably could, however I have been struggling to interpret the implementation of the required rules into the CellularAutomaton function.

I labelled each site as:

0 - black site
1 - green site
2 - red site

The rules required for update at each time step are: i) red site becomes black ii) green site becomes red if one of it's neighbors is red, otherwise it becomes red with probability f iii) a black site becomes green with probability p.

Any assistance with the CellularAutomaton function is welcome too though.

POSTED BY: Jon Rickett

Hi Sam,

I recently found some code which has helped:

evolve[nbhd_List, k_] := 0 /; nbhd[[2, 2]] == 2    (*burning->empty*)
evolve[nbhd_List, k_] := 2 /; nbhd[[2, 2]] == 1 && Max@nbhd == 2     (*near_burning&nonempty->burning*)
evolve[nbhd_List, k_] := RandomChoice[{f, 1 - f} -> {2, nbhd[[2, 2]]}] /; nbhd[[2, 2]] == 1 && Max@nbhd < 2   (*spontaneously combusting tree*)
evolve[nbhd_List, k_] := RandomChoice[{p, 1 - p} -> {1, nbhd[[2, 2]]}] /; nbhd[[2, 2]] == 0  (*random tree growth*)

r = 100; c = 100; p = 10^-2; f = 10^-4;
init = RandomInteger[BernoulliDistribution[0.05], {r, c}];
MatrixPlot[CellularAutomaton[{evolve, {}, {1, 1}}, {init, 0}, {{{300}}}], ColorRules -> {0 -> White, 1 -> Green, 2 -> Red}, Frame -> False]

However, this is for a 9-neighbourhood region. Do you know how I can implement a 5-neighbourhood totalistic region for this?

POSTED BY: Jon Rickett
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract