graph_tool.dynamics.BinaryThresholdState#
- class graph_tool.dynamics.BinaryThresholdState(g, w=1.0, h=0.5, r=0.0, s=None)[source]#
Bases:
DiscreteStateBaseGeneralized binary threshold dynamics.
- Parameters:
- g
Graph Graph to be used for the dynamics
- w
EdgePropertyMaporfloat(optional, default:1.) Edge weights. If a scalar is provided, it’s used for all edges.
- h
float(optional, default:.5) Relative threshold value.
- r
float(optional, default:0.) Input random flip probability.
- s
VertexPropertyMap(optional, default:None) Initial global state. If not provided, a random state will be chosen.
- g
Notes
This implements a Boolean threshold model on a network.
If a node \(i\) is updated at time \(t\), the transition to state \(s_i(t+1)\) is given by
\[\begin{split}s_i(t+1) = \begin{cases} 1, & \text{ if } \sum_jA_{ij}w_{ij}\hat s_j(t) > h k_i,\\ 0, & \text{ otherwise.} \end{cases}\end{split}\]where \(k_i=\sum_jA_{ij}\) 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.GraphView(gt.collection.data["polblogs"].copy(), directed=False) >>> gt.remove_parallel_edges(g) >>> g = gt.extract_largest_component(g, prune=True) >>> state = gt.BinaryThresholdState(g, r=0.25) >>> ret = state.iterate_sync(niter=1000) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=state.s, ... output="binary-threshold.pdf") <...>
State of a binary threshold dynamics on a political blog network.#
Methods
copy()Return a copy of the state.
Returns list of "active" nodes, for states where this concept is used.
Returns the internal
VertexPropertyMapwith 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.
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
VertexPropertyMapwith 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.