graph_tool.dynamics.BooleanState#

class graph_tool.dynamics.BooleanState(g, f=None, p=0.5, r=0, s=None)[source]#

Bases: DiscreteStateBase

Boolean network dynamics.

Parameters:
gGraph

Graph to be used for the dynamics

fVertexPropertyMap (optional, default: None)

Vertex property map of type vector<bool> containing the Boolean functions. If not provided, the functions will be randomly chosen.

pfloat (optional, default: .5)

Output probability of random functions. This only has an effect if f is None.

rfloat (optional, default: 0.)

Input random flip probability.

sVertexPropertyMap (optional, default: None)

Initial global state. If not provided, a random state will be chosen.

Notes

This implements a Boolean network model.

If a node \(i\) is updated at time \(t\), the transition to state \(s_i(t+1)\) is given by

\[s_i(t+1) = f^{(i)}_{\sum_{j\in \partial i}2^{\hat s_j(t)}}\]

where \(\partial i\) are the (in-)neighbors of \(i\), indexed from \(0\) to \(k-1\), and \(\hat s_i(t)\) are the flipped inputs sampled with probability

\[P(\hat s_i(t)|s_i(t)) = r^{1-\delta_{\hat s_i(t),s_i(t)}}(1-r)^{\delta_{\hat s_i(t),s_i(t)}}.\]

Examples

>>> g = gt.random_graph(50, lambda: (2,2))
>>> state = gt.BooleanState(g)
>>> ret = state.iterate_sync(niter=1000)
>>> s0 = state.s.copy()
>>> ret = state.iterate_sync(niter=1)
>>> l = 1
>>> while any(state.s.a != s0.a):
...     ret = state.iterate_sync(niter=1)
...     l += 1
>>> print("Period length:", l)
Period length: 4

Methods

copy()

Return a copy of the state.

get_active()

Returns list of "active" nodes, for states where this concept is used.

get_state()

Returns the internal VertexPropertyMap with the current state.

iterate_async([niter])

Updates nodes asynchronously (i.e. single vertex chosen randomly), niter number of times.

iterate_sync([niter])

Updates nodes synchronously (i.e. a full "sweep" of all nodes in parallel), niter number of times.

reset_active()

Resets list of "active" nodes, for states where this concept is used.

copy()#

Return a copy of the state.

get_active()#

Returns list of “active” nodes, for states where this concept is used.

get_state()#

Returns the internal VertexPropertyMap with the current state.

iterate_async(niter=1)#

Updates nodes asynchronously (i.e. single vertex chosen randomly), niter number of times. This function returns the number of nodes that changed state.

iterate_sync(niter=1)#

Updates nodes synchronously (i.e. a full “sweep” of all nodes in parallel), niter number of times. This function returns the number of nodes that changed state.

If enabled during compilation, this algorithm runs in parallel (i.e. using more than one thread.)

reset_active()#

Resets list of “active” nodes, for states where this concept is used.