GeneralizedBinaryState#

class graph_tool.dynamics.GeneralizedBinaryState(g, f, r, s=None)[git][source]#

Bases: DiscreteStateBase

Generalized binary dynamics, with transition probabilities that depend on the number of active neighbors.

Parameters:
gGraph

Graph to be used for the dynamics

ftwo-dimensional numpy.ndarray

Activation probabilities, where f[m, k] is the probability that an inactive node with \(k\) (in-)neighbors, of which \(m\) are active, becomes active. Both dimensions must be larger than the largest (in-)degree.

rtwo-dimensional numpy.ndarray

Probabilities of remaining active, where r[m, k] is the probability that an active node with \(k\) (in-)neighbors, of which \(m\) are active, remains active. Both dimensions must be larger than the largest (in-)degree.

sVertexPropertyMap (optional, default: None)

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

Notes

This implements a generalized binary-state dynamics [gleeson-binary-2013], which includes the SIS epidemic, voter and threshold models as special cases.

Each node has a state \(s_i\in\{0,1\}\). If a node \(i\) is updated at time \(t\), the transition to state \(s_i(t+1)\) is given by the probabilities

\[\begin{split}P(s_i(t+1)=1|s_i(t)=0) &= f_{m_i(t),k_i},\\ P(s_i(t+1)=1|s_i(t)=1) &= r_{m_i(t),k_i},\end{split}\]

where \(k_i=\sum_jA_{ij}\) is the (in-)degree of node \(i\), and \(m_i(t)=\sum_jA_{ij}s_j(t)\) is the number of its active (in-)neighbors.

References

[gleeson-binary-2013]

James P. Gleeson, “Binary-state dynamics on complex networks: pair approximation and beyond”, Phys. Rev. X 3, 021004 (2013), DOI: 10.1103/PhysRevX.3.021004 [sci-hub, @tor], arXiv: 1209.2983

Examples

The SIS epidemic model with infection probability \(\beta\) per infected neighbor and recovery probability \(\gamma\) corresponds to \(f_{m,k} = 1-(1-\beta)^m\) and \(r_{m,k} = 1-\gamma\):

>>> g = gt.GraphView(gt.collection.data["polblogs"].copy(), directed=False)
>>> gt.remove_parallel_edges(g)
>>> g = gt.extract_largest_component(g, prune=True)
>>> k_max = g.get_total_degrees(g.get_vertices()).max()
>>> m, k = np.meshgrid(np.arange(k_max + 1), np.arange(k_max + 1),
...                    indexing="ij")
>>> beta, gamma = 0.02, 0.1
>>> f = 1 - (1 - beta) ** m
>>> r = np.full(f.shape, 1 - gamma)
>>> state = gt.GeneralizedBinaryState(g, f, r)
>>> ret = state.iterate_sync(niter=1000)
>>> print(state.s.fa.mean())
0.594108...

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.

set_active(active)

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

copy()[git]#

Return a copy of the state.

get_active()[git]#

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

get_state()[git]#

Returns the internal VertexPropertyMap with the current state.

iterate_async(niter=1)[git]#

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)[git]#

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.

Parallel implementation.

If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.

reset_active()[git]#

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

set_active(active)[git]#

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