Modern socio-technological systems can be described as networks with naturally occurring spreading phenomena such as information propagation in social networks1,2, or the epidemic spread among individuals through their contact network3,4,5,6. In order to exactly solve the spreading process one must be able to evaluate the probabilistic evolution of the process configurations in time i.e. solve a set of coupled differential equations called master equation7,8,9,10 or Chapman-Kolmogorov equation. However, due to the exponential growth of possible configurations only in small number of special cases9,10 it is possible to solve the master equation directly. Therefore, different approximations are used: (i) neglecting dynamical correlations by assuming statistical independence at first neighbourhood, pair or node level in mean field approximations11,12,13,14,15,16, (ii) neglecting loops in the network structure with message passing or belief propagation techniques17,18,19, or (iii) neglecting the temporal evolution by mapping to the percolation process20,21,22. Alternative way is the simulation or sampling the statically correct process configurations or realizations with the dynamic Monte Carlo techniques23,24,25,26,27,28.

In this paper, we propose how to exactly transform the SIR spreading dynamics to a shortest path problem on an ensemble of weighted networks using a Monte Carlo approach. In this framework, weights represent interaction time delays along edges. We show the equivalence between the time respecting paths (shortest paths) on the constructed weighted networks and the propagation times of spreading dynamics. The mapping is applicable to the generalized Susceptible Infected Recovered (SIR) model5 without memory (exponential inter-event distribution/Poisson process) and with memory (arbitrary inter-event distributions). Contrary to the standard dynamic Monte Carlo methods23,24,25,26,27,28, we do not have to specify initial conditions upfront and we can sample new realizations from the previous ones by making local random Markov Chain transitions between the weighted networks. In a limit of infinite process time, we establish the connection with bond percolation theory20,21,29,30. In the special case of independently assigned edge weights, we establish the connection to the disordered in networks31,32,33,34,35. Finally, we show the applications to source detection18,19,36,37,38,39 and time-critical vaccination40,41,42.


Mapping SIR dynamics to weighted shortest paths

Let us start with the Poissonian SIR model, which is memoryless, such that the next state only depends on the present state of the system. This process is defined by two parameters (β, γ), which describe transitions where susceptible nodes become infected with rate β from infected neighbours and transitions where infected nodes recover with rate γ. This process has exponential inter-event time distributions: ψ(t) = βeβt (spread) and \(\varphi (t)=\gamma {e}^{-\gamma t}\) (recovery). However, many realistic processes have memory26 and their inter-event time distributions are non-exponential. Therefore, we allow for arbitrary inter-event density distributions \((\psi (t),\varphi (t))\) for generalized SIR processes.

For a given network G and class of generalized SIR spreading models, we show how to create weighted networks \(\{{{\mathscr{G}}}_{k}\}\) which encode realizations of the stochastic spreading dynamics. Each weighted network \({{\mathscr{G}}}_{k}\) (see Fig. 1) encodes one possible outcome of the spreading process from every potential source node in a network. In particular, a time-respecting weighted network instance \({{\mathscr{G}}}_{k}\) is created by taking the input network G and assigning weights to the edges of the network instance with the Inverse Smirnov transform43 as

$${\rho }_{i,j}=\{\begin{array}{ll}{{\rm{\Psi }}}^{-1}(x): & {{\rm{\Psi }}}^{-1}(x)\le {{\rm{\Phi }}}^{-1}(y)\\ \infty : & {{\rm{\Psi }}}^{-1}(x) > {{\rm{\Phi }}}^{-1}(y),\end{array}$$

where x and y are uniform random numbers [0, 1], Φ−1(x) and Ψ−1(y) are inverse functions of the cumulative inter-event distributions \({\rm{\Phi }}(t)={\int }_{0}^{t}dt^{\prime} \varphi (t^{\prime} )\) and \({\rm{\Psi }}(t)={\int }_{0}^{t}dt^{\prime} \psi (t^{\prime} )\). The quantities Ψ−1(y) and Φ−1(x) respectively represent the samples of the transmission and recovery time obtained with the Inverse Smirnov transform of inter-event distributions. In the special case of the Poissonian SIR process one obtains

$${\rho }_{i,j}=\{\begin{array}{ll}-\,\mathrm{ln}(x)/\beta : & -\,\mathrm{ln}(x)/\beta \le -\,\mathrm{ln}(y)/\gamma \\ \infty : & -\,\mathrm{ln}(x)/\beta > -\,\mathrm{ln}(y)/\gamma .\end{array}$$
Figure 1
figure 1

The mapping of spreading dynamics to an ensemble of weighted networks. The weights represent the propagation time delays. Each weighted network represents one realization of the stochastic dynamics from an arbitrary source node. The propagation time from the source node to any other node is equal to the shortest path length in weighted network (color coded). The dotted line represents edges with infinite edge weight.

If nodes recover faster than a transmission occurs, the weight is set to infinity to indicate no transmission through the edge.

We denote the distance as shortest paths on weighted networks, \({d}_{{{\mathscr{G}}}_{k}}({v}_{i},{v}_{j})={{\rm{\min }}}_{{\chi }_{ij}}{\sum }_{(k,l)\in {\chi }_{ij}}{\rho }_{k,l}\), where χ ij is the set of all possible paths from node v i to node v j on network \({{\mathscr{G}}}_{k}\) and ρk,l denotes the weights defined in Eq. (1). Importantly, this distance is equivalent to the propagation time from node i to j, i.e. \(t({v}_{i}\to {v}_{j})={d}_{{{\mathscr{G}}}_{k}}({v}_{i},{v}_{j})\) (time respecting path equivalence, see Supplementary information, Sec. 1). The run-time complexity of finding shortest paths44 from specific source node to others is O(E + N log N), where N denotes the number of nodes and E number of edges in a network. The exact mapping is done by generating a random variable y for each node and variable x for each edge. This takes all dynamical correlations into the account and generates the ensemble of directed weighted networks. A simplified mean-field mapping can be obtained by generating random variables x and y per each edge, independently. This simplified mean-field mapping holds when β γ (SI case) and generates the ensemble of undirected weighted networks (see Supplementary information, Sec. 5 and 6. for more details). In the section Additional information of this paper, we provide a link to the code that implements the proposed mapping.

Sampling methods for simulation

The instances of the ensemble of weighted networks can be sampled either (i) independently, or (ii) by traversing elements of the ensemble with Markov Chain.

The Markov Chain (rejection-free Gibbs sampler – see Supplementary information, Sec. 3) consists of transitions \({W}_{i,j}=w({{\mathscr{G}}}_{i}\to {{\mathscr{G}}}_{j})\) over the set of weighted networks \(\{{{\mathscr{G}}}_{k}\}\), where each weighted network corresponds to one realization of the spreading process from every potential source node. This allows us to construct transitions between weighted networks by changing the weights in the first neighbourhood of a randomly selected node for exact mapping or by assigning a new weight to the randomly selected edge for a mean-field mapping, both according to Eq. (1) (see Fig. 2). The existence of a stationary distribution of this Markov Chain is guaranteed by detailed balance property and the uniqueness by ergodicity (see Supplementary information, Sec. 3). In other words, the Gibbs sampling—as well as independent sampling—constructs the probability distribution \(P({\mathscr{G}})\) of the weighted network ensemble, such that it is a statistically exact representation of the stochastic process. From the ensemble of weighted networks, due to ergodicity, the expectation \(\langle f({\mathscr{G}})\rangle \) can be estimated as the average over n samples of weighted networks:

$$\langle \,f({\mathscr{G}})\rangle =\sum _{{{\mathscr{G}}}_{k}}P({{\mathscr{G}}}_{k})f({{\mathscr{G}}}_{k})\approx 1/n\sum _{k=1}^{n}f({{\mathscr{G}}}_{k})$$
Figure 2
figure 2

Markov Chain Monte Carlo sampling. The transitions Wi,j = w(G i G j ) between different instances of weighted networks in the ensemble. Randomization of the weight of an edge (denoted by red) corresponds to the transition between the states (realizations of the process).

By changing functions \(f({\mathscr{G}})\), we estimate different properties such as total outbreak size, temporal evolution, expected propagation time or source likelihood (see Supplementary information, Sec. 4). The same estimation formula 3 can be applied to the independent sampling. The convergence rate of independent estimation are bounded with the Berry–Esseen inequality as O(n−1/2). If all to all shortest paths need to be calculated, after each weight change in Markov Chain transition, shortest paths can be dynamically recalculated45,46 with computational complexity O(N2log3N), where N denotes the number of nodes in a network (see Supplementary information, Sec. 8 for more details). In Fig. 3, we demonstrate that the estimations converge to the analytical solution on a toy network model. This confirms that the shortest paths in the ensemble of weighted networks are taking into the account stochastic spreading along all possible paths in the original unweighted network.

Figure 3
figure 3

Toy network model example. (a) Sketch of simple toy network, that consists of n c chains with l nodes. The probability that source node s infects destination node d can be calculated analytically (see supplementary information, Sec. 5. for details) and is given by \(P(s\to d)=1-{\sum }_{j=0}^{{n}_{c}}{p}_{n,j}\cdot {(1-{p}_{\mathrm{1,1}}^{l})}^{j}\). The term pn,k, denotes transmissibility for the first neighborhood Eq. 10 for Poissionan SIR process and Eq. 9 for generalized non-Markovian process. (b) Simulation results on the toy network with n = 20, l = 3 with Poisson SIR (β = 1, γ = 1). The blue curve represents the estimations with the exact mapping (conditional independence among edge weights), the red curve represents the mean-field mapping (weights are independent) and the black dotted line represents the analytical solution (see supplementary information, Sec. 5. for a million size toy network experiment).

Relation to bond percolation

In the following, we state the connection to percolation theory. From the perspective of source node v i , the shortest path \({d}_{{\mathscr{G}}}({v}_{i},{v}_{j})\) indicates the first infection time of node v j . Therefore all nodes that are not reachable within the temporal distance t stay in the susceptible state. If a node is reachable within the temporal distance t, then it was infected. By letting t go to infinity we obtain asymptotic realization equivalence to bond percolation. In particular, the size of the set of nodes v j that are reachable in any finite time from the source node v i , \(|{S}_{p}({v}_{i})|\), is given by

$$|{S}_{p}({v}_{i})|=\mathop{\mathrm{lim}}\limits_{t\to \infty }|\{d({v}_{i},{v}_{j}) < t\}\mathrm{|.}$$

The full proof is given in the Supplementary information, Sec. 2. and holds for simplified mean-field mapping, where edge weights are independent.

Hence, |S p (v i )| denotes the size of the connected bond percolation component, where the transmissibility parameter29 from source v i is given by

$$p={\int }_{0}^{\infty }d\tau {\varphi }_{i}(\tau ){\int }_{0}^{\tau }d\tau ^{\prime} {\psi }_{i}(\tau ^{\prime} ).$$

In Fig. 4, we present the experiments where the equivalence to bond percolation is validated. The transmissibility quantifies the probability that an infected node transmits infection along a link to a susceptible neighbour before it recovers. The second integral accounts for the conditional probability of transmission up to the fixed recovery time, and the first integral account for all possible recovery times τ. Furthermore, to take dynamical correlations into the account that were previously missing in29, we generalize and formalize the transmissibility for the first neighborhood or, more precisely, the probability p n,k that k out of n directed links will be active

$${p}_{n,k}={\int }_{0}^{\infty }\varphi (\tau )d\tau (\begin{array}{c}n\\ k\end{array}){(1-{\rm{\Psi }}(\tau ))}^{(n-k)}{\rm{\Psi }}{(\tau )}^{k},$$

where \({\rm{\Psi }}(\tau )={\int }_{0}^{\tau }\psi (t)dt\). For Poissionan process this becomes

$${p}_{n,k}=(\begin{array}{c}n\\ k\end{array})\frac{\gamma }{\beta }\frac{{\rm{\Gamma }}(k+1){\rm{\Gamma }}(\frac{\gamma +\beta (n-k)}{\beta })}{{\rm{\Gamma }}(k+1+\frac{\gamma +\beta (n-k)}{\beta })}.$$
Figure 4
figure 4

Equivalence to bond percolation. Average outbreak size in time estimated with the proposed mapping and comparison with bond percolation late-time outbreak size (dotted lines), see Eq. 4. In a limit of infinite time the mapping becomes equivalent to the bond percolation. Results were obtained for the SIR dynamics (continuous time) with different transmission rates β (0.3, 0.03, 0.003, 0.0003) and recovery rate γ = 0.001 and with n = 104 simulations on the 4-connected two dimensional regular lattice (11 × 11).

The generalized transmissibility for the first neighborhood Eq. 7 establishes the connection to semi-directed bond percolation30 (see Supplementary information, Sec. 5 and 6). To have exact mapping of the SIR process to percolation, having a single percolation parameter p is no longer accurate when βγ and generalized transmissibility pn,k for the first neighborhood is needed to capture all dynamical correlations.

Relation to disordered networks

The question how the average propagation time between two individuals scales with the system size is crucial for many real applications and of special theoretic interest. In particular, if this distance scales logarithmically with the system size, an epidemic can spread nearly instantaneously in arbitrary large networks. However, if it scales like Nσ, in large enough systems the disease will not spread through the network in realistic timescales. We can address this question for the SI-model (γ = 0) in an elegant fashion by establishing an analogy to the shortest path problem in disordered networks31,32,33,34,35, which are generated by assigning weights ρ independently to edges drawn from some distribution f(ρ). In31 the authors have shown that the shortest path length from node v i to node v j in these weighted networks scales differently with the system size depending on f(ρ), and distinguish between strong and weak disorder. The shortest path length is defined as \(d({v}_{i},{v}_{j})={{\rm{\min }}}_{{\chi }_{ij}}{\sum }_{(k,l)\in {\chi }_{ij}}{\rho }_{k,l}\), where χ ij is the set of all possible paths. For the example of Erdos-Renyi networks, in the case of strong disorder the shortest path length scales as \(\langle d\rangle \propto {N}^{1/3}\), and for weak disorder as \(\langle d\rangle \propto \,\mathrm{log}\,N\). The temporal distance we have defined earlier is equivalent to the shortest paths on weighted graphs. Therefore, we can use this analogy to study the scaling of the average propagation time with the system size. From31 it is know that if f(ρ) is taken as the exponential distribution, only weak disorder can occur, and the average distance scales with the logarithm of the systems size for Erdos-Renyi networks. This means that for the memory-less spreading process, where ψ(·) is the exponential distribution, the average propagation time scales with the logarithm of the system size and diseases spread quickly in systems of any size. However, if the inter-event distribution is for instance given by a lognormal distribution (non-Markovian case), we know from31 that strong disorder can occur such that the average distance and hence the average propagation time scales like \(\langle d\rangle \propto {N}^{1/3}\). In this case, the finite time properties of the spreading process are drastically different to the non-Markovian case, as the average propagation time becomes very large as the size of the system increases, such that the disease will not spread globally in realistic timescales. To conclude, although it has recently been shown that the infinite time steady states of non-Markovian processes can be mapped to Markovian ones47, their finite time dynamics can be dramatically different.

Dataset availability

All data that we used in our analysis are freely available48,49,50.

Main code available at


Expected propagation time between node pairs

Starting from a given node, what is the expected time after which the disease reaches each other node in the network? The answer to this question is encoded in the ensemble of weighted networks. For SI processes (γ = 0), the expected propagation time is always finite and can be estimated as the average over n samples of weighted networks as \({D}_{ij}=\mathrm{1/}n{\sum }_{k=1\,}^{n}f({{\mathscr{G}}}_{k})\), where \(f({{\mathscr{G}}}_{k})={d}_{{{\mathscr{G}}}_{k}}({v}_{i},{v}_{j})\) denotes the length of weighted shortest path between v i and v j . Note, that for the SIR process, the expected propagation time is not finite i.e. it diverges. In Fig. 5(a), we show an explicit example from the perspective of a specific source node. The advantage of the temporal maps we have created is they encode this type of information between all possible node pairs. The result is shown in Fig. 5(b–d) for three empirical networks: the email network48, the airport network39, and the Petser online social network49. The plots show the average temporal distance or expected propagation time D ij for each pair of nodes i,j, and therefore encompass information about the expected spreading dynamics. In particular, we have ordered the nodes by their characteristic spreading timescale, which we define as the expected time after which a given node infects \(\overline{N}\) other nodes, τ i , as

$${\tau }_{i}=t{|}_{\sum _{j\ne i}{\rm{\Theta }}(t-{D}_{ij})=\overline{N}},$$

where Θ() denotes the Heaviside step function, which is one when tD ij and zero otherwise. A small value of τ i means that node i is of high importance or influence. This ordering of nodes displays the smooth gradient of the average temporal distance between pairs of nodes on all three empirical networks.

Figure 5
figure 5

The expected propagation time D ij on empirical networks. The average propagation time is calculated as the average shortest path distances in the ensemble of weighted networks (mapped dynamics). (a) Nodes in the email network network are placed on a circle, where the angular coordinate represents the average propagation time from the source node (black) with index 500, increasing in the clockwise direction (from blue to red). The average propagation time D ij for: (b) the email network48 (β = 0.01), (c) the airport network (β estimated from flux data see Supplementary information, Sec. 7), (d) the Petster network49 (β = 0.01). Nodes are ordered by their characteristic spreading timescale τ i , see Eq. 8) with condition \(\overline{N}=N\mathrm{/2}\).

Source detection

For a given snapshot r* of a spreading process at time t0 on a network, how does one detect the source node that generated the snapshot? Source detection18,19,36,37,38,39 is an important theoretical and practical problem in network science. It is at least as hard as any problem in NP-complete class37,51, because it belongs to #P-complete class52. We approach the problem by probabilistic kernel estimations36,53 of the likelihood that source node generated the observed snapshot. Our framework can be used to perform this task, as the ensemble of weighted networks encompasses information about different realizations of the spreading process from all possible sources.

For the observed realization r*, our source probability estimates for every node v i are constructed from ensemble averages \({s}_{i}\propto {\sum }_{j}^{m}f({{\mathscr{G}}}_{j})\). From weighted network \({{\mathscr{G}}}_{j}\), we extract realization based on temporal distances and calculate the similarity φ j [0,1] to the observed realization r*. Similarity φ j is the normalized number of equal corresponding states between two realizations. Finally, we use the Gaussian kernel function

$$f({{\mathscr{G}}}_{j})=exp(\,-\,{({\phi }_{j}-\mathrm{1)}}^{2}/{a}^{2})$$

for probability estimations36,53 (see Supplementary information, Sec. 4 for more details). We compare our source probability estimations with direct Monte Carlo approach36 and topological distance approach54. The direct Monte Carlo approach generates large number of simulations n = 106–108, from each potential source node v i , and source probability estimation is s i n i , where n i is the number of simulations that match the observed realization r*. The topological distance approach calculates the average topological distance 〈d i 〉 from each potential source v i to other infected nodes in the observed realization r* and source estimation is s i d i −1. The result is shown in Fig. 6, where source ranked probability estimates for different methods are shown. Indeed, the method based on the ensemble of weighted networks (n = 105 instances) performs better than a topological distance estimation54 and correctly assigns a high probability to the source candidate identified by the direct Monte Carlo method36.

Figure 6
figure 6

Source detection. We compare source detection performance for different methods for the SIR model: (a) β = 0.7, γ = 0.3 and (b) β = 0.7, γ = 0.7 at time T = 5 (discrete time) on the 4-connected lattice (30 × 30 nodes). For each observed realization, we rank nodes according to their estimated probability score according to the Direct Monte Carlo method36, in case of a tie we prioritize the node with a higher estimator according to the temporal distance method. We compare different methods as explained in the text: Direct Monte Carlo source probability ranking, source detection ranking by topological distance54, and the estimation from our mapping (temporal distance). Results are averaged over 30 observed realizations and error bars show one standard deviation, from top to bottom.

Time critical vaccination

Now, let us consider the following vaccination scenario. We observe at time t0 the outbreak of a disease and we have a certain amount, m, of vaccines, see Fig. 7(a). We can vaccinate m individuals instantaneously, but the vaccines will only be effective after some time Δt (a vaccinated individual can get infected before t0 + Δt, and in this case this vaccine portion is wasted, see Fig. 7(b). Who shall we vaccinate? Our framework can be used to improve the vaccination strategy. The idea is that, at time t0, we vaccinate only individuals who—with high probability—will not get infected before t0 + Δt. Therefore, we estimate the probability that a node i will not be infected before t0 + Δt as

$${\tilde{p}}_{i}=1/n\sum _{k=1}^{n}{\rm{\Theta }}({d}_{{{\mathscr{G}}}_{k}}({v}_{\theta },{v}_{i})-{t}_{0}-{\rm{\Delta }}t),$$

where θ denotes the source node and Θ() is one when \({d}_{{{\mathscr{G}}}_{k}}({v}_{\theta },{v}_{i})\ge {t}_{0}+{\rm{\Delta }}t\) and zero otherwise. We vaccinate nodes proportional to \(\tilde{p}\). In Fig. 7(b,c) we show using empirical Petster network that this procedure performs better than randomly choosing from all susceptible nodes at t0. Interestingly, vaccinating proportional to degree (hubs strategy) performs even worse than the fully random strategy, since the hubs usually are infected earlier, which increases the chance to waste vaccine portions.

Figure 7
figure 7

Time critical vaccination. (a) Shows an illustration of the time critical vaccination process. Vaccination candidates are highlighted by the diamond symbols. Red note denote infected individuals, and blue nodes are susceptible. In (b) and (c), we show the total number of infected nodes up to time t for the different vaccination strategies described in the text (m = 0.2 of the total number of nodes). The first dashed vertical line denotes T0 = 3, and the second one T0 + τ = 13. In (b) for the discrete time SIR β = 0.03,γ = 0.01 and in (c) for the discrete time SIR β = 0.05,γ = 0.01 with source node 10 in the Petster network.


We have mapped spreading dynamics on networks to an ensemble of weighted networks. This mapping allows us to define a temporal distance as shortest paths between nodes on an ensemble of weighted networks. We concentrate on the stochastic formulation of the generalized continuous and discrete time Susceptible Infected Recovered (SIR) spreading dynamics without memory (exponential inter-event distribution) and with memory (arbitrary inter-event distributions).

The problem of shortest path with the stochastic independent and identically distributed weights (i.i.d.) has been extensively researched in theoretical computer science55,56,57,58, probability theory59,60 and statistical physics community31,32,33,34,35. However, the general SIR dynamics is exactly represented with networks where the edge weights are conditionally independent random variables and only in special case of spreading they become independent variables e.g. SI dynamics (γ = 0) or SIR dynamics with fixed recovery time (ψ(t) = δ(tT)). Thus, our mapping to the ensemble of weighted networks, provides additional dynamical interpretation of the shortest paths problem in disordered networks. Previously, only the Independent Cascade spreading models (edge weights are i.i.d.) were connected to the problem of shortest paths61 on networks, but with no connections to disordered networks or bond percolation literature.

In contrast to message passing, our framework is applicable for arbitrary network structures without neglecting loops in the network structure. Furthermore, our method takes into account dynamical correlations between node states overcoming the assumptions of mean-field like approximations12,14. In contrast to the well known historical Gillespie or kinetic Monte Carlo methods23,24,25,26,27,28,36, we do not have to specify initial conditions upfront and we can sample new realizations from the previous ones by making local random perturbations on the weighted networks. We have shown that for some non-Markovian processes, the average propagation time can scale as a polynomial with the system size, even if the underlying network is small world. In stark contrast to the Markovian case, this means that for large enough systems the disease does not spread globally in a realistic timescale. We have shown that our framework allows for direct applications like ranking of nodes according to their characteristic spreading timescale, source detection and time-critical vaccination. Combining our mapping framework with existing vaccination strategies is likely to further improve the results, especially when time is a crucial factor.

Note that previous studies39,62,63,64 for estimating the spreading arrival times were concentrated on a global disease spread with different approximations and theoretical understanding of effective distances65 for metapopulation models. However, the exact mathematical equivalences for mapping generalized spreading dynamics at a microscopic level were still lacking. Furthermore, in a limit of infinite process time, we establish the connection with bond percolation theory. Previously the outcome in infinite time of the SIR process have been successfully mapped to the percolation20,21,29,30 but not for the finite time. Contrary to previous state-of-the-art source inference studies18,19,36, estimations with our method require same computational effort to sample realizations at an arbitrary point in time t not only for discrete time but also for continuous time dynamics.