5
$\begingroup$

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?

$\endgroup$
1
  • 1
    $\begingroup$ One question per post please. Try to use a descriptive title. $\endgroup$
    – Szabolcs
    Commented Aug 5, 2020 at 11:09

1 Answer 1

12
$\begingroup$

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

$\endgroup$
5
  • $\begingroup$ Dear @flinty! This one is exactly what I have already done. Of course, your code is much more efficient and smarter, thank you! But I would like to do the same using the new features $\endgroup$
    – lesobrod
    Commented Aug 5, 2020 at 13:21
  • 2
    $\begingroup$ @lesobrod those features are for neural networks. Kauffman networks are not neural networks in the usual sense, so they do not really apply here. There are no inputs for example except the initial state, no weights, and no training process e.g back-propagation. $\endgroup$
    – flinty
    Commented Aug 5, 2020 at 13:31
  • $\begingroup$ Yes, @flinty, I've learned the subject and you are right! So, please check my question about detecting period in this process! $\endgroup$
    – lesobrod
    Commented Aug 5, 2020 at 16:20
  • $\begingroup$ @lesobrod I've added some code to get the period using FindRepeat. $\endgroup$
    – flinty
    Commented Aug 5, 2020 at 16:37
  • 2
    $\begingroup$ Those animations are pretty neat! $\endgroup$ Commented Aug 5, 2020 at 23: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.