SIState#

class graph_tool.dynamics.SIState(g, beta=1.0, r=0, exposed=False, epsilon=0.1, v0=None, s=None, constant_beta=True)[source]#

Bases: EpidemicStateBase

SI compartmental epidemic model.

Parameters:
gGraph

Graph to be used for the dynamics

betafloat or EdgePropertyMap (optional, default: 1.)

Transmission probability. If an EdgePropertyMap object is passed, it must contain the transmission probability for every edge.

rfloat or VertexPropertyMap (optional, default: 0.)

Spontaneous infection probability.

exposedboolean (optional, default: False)

If True, an SEI model is simulated, with an additional “exposed” state.

epsilonfloat or VertexPropertyMap (optional, default: .1)

Susceptible to exposed transition probability. This only has an effect if exposed=True.

v0int or Vertex (optional, default: None)

Initial infectious vertex. If not provided, and if the global state is also not provided via paramter s, a random vertex will be chosen.

sVertexPropertyMap (optional, default: None)

Initial global state. If not provided, all vertices will be initialized to the susceptible state.

constant_betaboolean (optional, default: True)

If True, and beta is an edge property map, it will be assumed that the beta values do not change, such that the probability values can be pre-computed for efficiency. If beta is a float, this option has no effect.

Notes

This implements an SI epidemic process [pastor-satorras-epidemic-2015], where nodes in the susceptible state (value 0) are infected by neighbours in the infectious state (value 1).

If a node \(i\) is updated at time \(t\), the transition probabilities from state \(s_i(t)\) to state \(s_i(t+1)\) are given as follows:

  1. If \(s_i(t) = 0\), we have \(s_i(t+1) = 1\) with probability

    \[(1-r_i)\left[1-\prod_j(1-\beta_{ij})^{A_{ij}\delta_{s_j(t),1}}\right] + r_i,\]

    otherwise \(s_i(t+1) = 0\).

  2. If \(s_i(t) = 1\), we have \(s_i(t+1) = 1\) with probability 1.

If the option exposed == True is given, then the states transit first from 0 to -1 (exposed) with probability given by 1. above, and then finally from -1 to 1 with probability \(\epsilon_i\).

References

[pastor-satorras-epidemic-2015]

Romualdo Pastor-Satorras, Claudio Castellano, Piet Van Mieghem, and Alessandro Vespignani, “Epidemic processes in complex networks”, Rev. Mod. Phys. 87, 925 (2015) DOI: 10.1103/RevModPhys.87.925 [sci-hub, @tor], arXiv: 1408.2701

Examples

>>> g = gt.collection.data["pgp-strong-2009"]
>>> state = gt.SIState(g, beta=0.01)
>>> X = []
>>> for t in range(1000):
...     ret = state.iterate_sync()
...     X.append(state.get_state().fa.sum())

>>> figure(figsize=(6, 4))
<...>
>>> plot(X)
[...]
>>> xlabel(r"Time")
Text(...)
>>> ylabel(r"Infectious nodes")
Text(...)
>>> tight_layout()
>>> savefig("SI.svg")
../_images/SI.svg

Number of infectious nodes vs. time for an SI dynamics.#

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()#

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.

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()#

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.