graph_tool.dynamics.SIRState#
- class graph_tool.dynamics.SIRState(g, beta=1.0, gamma=0.1, r=0, exposed=False, epsilon=0.1, v0=None, s=None, constant_beta=True)[source]#
Bases:
DiscreteStateBaseSIR compartmental epidemic model.
- Parameters:
- g
Graph Graph to be used for the dynamics
- beta
floatorEdgePropertyMap(optional, default:1.) Transmission probability.
- gamma
floatorVertexPropertyMap(optional, default:.1) Recovery probability.
- r
floatorVertexPropertyMap(optional, default:0.) Spontaneous infection probability.
- exposed
boolean(optional, default:False) If
True, an SEIR model is simulated, with an additional “exposed” state.- epsilon
floatorVertexPropertyMap(optional, default:.1) Susceptible to exposed transition probability. This only has an effect if
exposed=True.- v0
intorVertex(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.- s
VertexPropertyMap(optional, default:None) Initial global state. If not provided, all vertices will be initialized to the susceptible state.
- constant_beta
boolean(optional, default:True) If
True, andbetais an edge property map, it will be assumed that thebetavalues do not change, such that the probability values can be pre-computed for efficiency. Ifbetais afloat, this option has no effect.
- g
Notes
This implements an SIR epidemic process [pastor-satorras-epidemic-2015], where nodes in the susceptible state (value 0) are infected by neighbours in the infectious state (value 1), which can then eventually recover to a recovered state (value 2).
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:
- 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\).
If \(s_i(t) = 1\), we have \(s_i(t+1) = 2\) with probability \(\gamma_i\), or \(s_i(t+1) = 1\) with probability \(1-\gamma_i\).
If the option
exposed == Trueis 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.SIRState(g, beta=0.01, gamma=0.0025) >>> S, X, R = [], [], [] >>> for t in range(2000): ... ret = state.iterate_sync() ... s = state.get_state().fa ... S.append((s == 0).sum()) ... X.append((s == 1).sum()) ... R.append((s == 2).sum()) >>> figure(figsize=(6, 4)) <...> >>> plot(S, label="Susceptible") [...] >>> plot(X, label="Infectious") [...] >>> plot(R, label="Recovered") [...] >>> xlabel(r"Time") Text(...) >>> ylabel(r"Number of nodes") Text(...) >>> legend(loc="best") <...> >>> tight_layout() >>> savefig("SIR.svg")
Number of susceptible, infectious, and recovered nodes vs. time for an SIR dynamics.#
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.