TransWikia.com

How to simulate a cellular automaton on a network?

Mathematica Asked by lesobrod on December 3, 2020

Unfortunately, I have not yet understood the Neural Network well.
Suppose there is simple network (like Kauffman automata):
several nodes that can only be in states 1-0, connections between them, and the simplest function for determining a new state of node by inputs (e.g. XOR)

enter image description here

How can I create it using Wolfram Language
and watch it’s evolution?

One Answer

I hadn't heard of the Kauffman automata before, but if it's an XOR cellular automata on a graph, then this shouldn't be too hard to construct. All updates are simultaneous and there is no propagation delay. If that is desired instead then you'd could randomly pick an order to update the cells.

SeedRandom[1];
g = RandomGraph[{30, 55}, DirectedEdges -> True];
(*don't care about disconnected components,choose the largest graph*)
g = First[MaximalBy[ConnectedGraphComponents[g], VertexCount]];

nodes = VertexList[g];
state = AssociationThread[nodes, RandomInteger[1, Length[nodes]]];
newstate = state;
colour[s_] := If[s == 1, Green, Red]
inputs[node_] := 
 Cases[IncidenceList[g, node], DirectedEdge[x_, node]][[All, 1]]
xor[node_] := BitXor @@ (state[#] & /@ inputs[node])

iterations = 50;
results = Reap[Do[Scan[Set[newstate[#], xor[#]] &, nodes];
     state = newstate;
     Sow[Graph[EdgeList[g], 
       VertexStyle -> KeyValueMap[#1 -> colour[#2] &, state]]];, 
     iterations]][[2, 1]];
ListAnimate[results]

kauffman xor

We can find the period of the above network by recording the states and using FindRepeat. Clear your kernel with Remove["Global`*"] to reset the state and execute the first two paragraphs of the code. Instead of that last paragraph of the code execute the following:

iterations = 2000;
statelist = Reap[Do[Scan[Set[newstate[#], xor[#]] &, nodes];
     state = newstate;
     Sow[state];
     , iterations]][[2, 1]];
FindRepeat[statelist] // Length
(* result: 254 *)

Here's a different network with a $tanh(sum{x_i})$ update function instead of XOR:

SeedRandom[123456];
g = RandomGraph[{115, 250}, DirectedEdges -> True];
(* don't care about disconnected components, choose the largest graph *)
g = First[MaximalBy[ConnectedGraphComponents[g], VertexCount]];

nodes = VertexList[g];
state = AssociationThread[nodes, RandomReal[{-1, 1}, Length[nodes]]];
newstate = state;
colour[s_] := Rescale[s, {-1, 1}] // Hue
inputs[node_] := 
 Cases[IncidenceList[g, node], DirectedEdge[x_, node]][[All, 1]]
tanhupdate[node_] :=
 Tanh[Total[(state[#] & /@ inputs[node])]]

iterations = 25;
results = Reap[Do[
     Scan[Set[newstate[#], tanhupdate[#]] &, nodes];
     state = newstate;
     Sow[Graph[EdgeList[g], 
       VertexStyle -> KeyValueMap[#1 -> colour[#2] &, state], 
       VertexSize -> 1]];
     , iterations]][[2, 1]];
ListAnimate[results]

kauffman tanh

Correct answer by flinty on December 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP