Appendix B Algorithms Here we adopt a standard notation (pseudocode ) for defining algorithms [33 , 154 ]. Assignment of a value α to a variable β is denoted by β ← α . The branching probability P α , β is represented as P [ α , β ] if it is stored in matrix form , and as P [ β ] [ α ] if it is stored in the form of adjacency lists .
Algorithm B.1: Calculate the pathway sum 𝒮 α , β C N Require: Chain nodes are numbered
0 , 1 , 2 , … , N − 1 Require: 1 < N Require: α , β ∈ { 0 , 1 , 2 , … , N − 1 } Require: P [ i , j ] is the probability of branching from node
j to node
i 1: if α < β then 2: h ← 1 ; t ← N − 2 ; s ← 1 3: else 4: h ← N − 2 ; t ← 1 ; s ← − 1 5: end if 6: L ← 1 7: for all i ∈ { h , h + s , h + 2 s , … , α } do 8: L ← 1 ∕ ( 1 − P [ i − s , i ] P [ i , i − s ] L ) 9: end for 10: Π ← 1 11: for all i ∈ { α + s , α + 2 s , α + 3 s , … , β } do 12: Π ← P [ i − s , i ] LΠ 13: L ← 1 ∕ ( 1 − P [ i − s , i ] P [ i , i − s ] L ) 14: end for 15: R ← 1 16: for all i ∈ { t , t − s , t − 2 s , … , β } do 17: R ← 1 ∕ ( 1 − P [ i + s , i ] P [ i , i + s ] R ) 18: end for 19: return LRΠ ∕ ( L − LR + R )
Algorithm B.2: Calculate the pathway sum 𝒮 a , b G N Require: 1 < N Require: a , b ∈ { 0 , 1 , 2 , … , N − 1 } Require: W is a boolean array of size
N with every element initially set to True
Require: N W is the number of True elements in array
W (initialised to
N )
Require: P [ i , j ] is the probability of branching from node
j to node
i Require: AdjIn [ i ] and
AdjOut [ i ] are the lists of indices of all nodes connected to node
i via incoming and outgoing edges, respectively
Recursive function F ( α , β , W , N W ) 1: W [ β ] ← False
2: N W ← N W − 1 3: if α = β and
N W = 0 then 4: Σ ← 1 5: else 6: Σ ← 0 . 0 7: for all i ∈ AdjOut [ β ] do 8: for all j ∈ AdjIn [ β ] do 9: if W [ i ] and W [ j ] then 10: Σ ← Σ + P [ β , j ] F ( j , i , W , N W ) P [ i , β ] 11: end if 12: end for 13: end for 14: Σ ← 1 ∕ ( 1 − Σ ) 15: if α ≠ β then 16: Λ ← 0 . 0 17: for all i ∈ AdjOut [ β ] do 18: if W[i] then 19: Λ ← Λ + F ( α , i , W , N W ) P ( i , β ) 20: end if 21: end for 22: Σ ← ΣΛ 23: end if 24: end if 25: W [ β ] ← True
26: N W ← N W + 1 27: return Σ
Algorithm B.3: Calculate the pathway sum 𝒮 α , β 𝒢 N from every source to every sink, and the mean escape time for every source in a dense graph 𝒢 N Require: Nodes are numbered
0 , 1 , 2 , … , N − 1 Require: Sink nodes are indexed first, source nodes - last
Require: i is the index of the first intermediate node
Require: s is the index of the first source node
Require: In case there are no intermediate nodes
i = s , otherwise
i < s Require: 1 < N Require: i , s ∈ { 0 , 1 , 2 , … , N − 1 } Require: τ [ α ] is the waiting time for node
α ,
α ∈ { i , i + 1 , i + 2 , … , N − 1 } Require: P [ i , j ] is the probability of branching from node
j to node
i 1: for all γ ∈ { i , i + 1 , i + 2 , … , s − 1 } do 2: for all β ∈ { γ + 1 , γ + 2 , … , N − 1 } do 3: if P [ γ , β ] > 0 then 4: τ [ β ] ← ( τ [ β ] + τ [ γ ] P [ γ , β ] ) ∕ ( 1 − P [ β , γ ] P [ γ , β ] ) 5: for all α ∈ { 0 , 1 , 2 , … , N − 1 } do 6: if α ≠ β and α ≠ γ then 7: P [ α , β ] ← ( P [ α , β ] + P [ α , γ ] P [ γ , β ] ) ∕ ( 1 − P [ β , γ ] P [ γ , β ] ) 8: end if 9: end for 10: P [ γ , β ] ← 0 . 0 11: end if 12: end for 13: for all α ∈ { 0 , 1 , 2 , … , N − 1 } do 14: P [ α , γ ] ← 0 . 0 15: end for 16: end for 17: for all α ∈ { s , s + 1 , s + 2 , … , N − 1 } do 18: for all β ∈ { s , s + 1 , s + 2 , … , N − 1 } do 19: if α ≠ β and P [ α , β ] > 0 then 20: P α , β ← P [ α , β ] 21: P β , α ← P [ β , α ] 22: T ← τ [ α ] 23: τ [ α ] ← ( τ [ α ] + τ [ β ] P β , α ) ∕ ( 1 − P α , β P β , α ) 24: τ [ β ] ← ( τ [ β ] + T P α , β ) ∕ ( 1 − P α , β P β , α ) 25: for all γ ∈ { 0 , 1 , 2 , … , i − 1 } ∪ { s , s + 1 , s + 2 , … , N − 1 } do 26: T ← P [ γ , α ] 27: P [ γ , α ] ← ( P [ γ , α ] + P [ γ , β ] P β , α ) ∕ ( 1 − P α , β P β , α ) 28: P [ γ , β ] ← ( P [ γ , β ] + T P α , β ) ∕ ( 1 − P α , β P β , α ) 29: end for 30: P [ α , β ] ← 0 . 0 31: P [ β , α ] ← 0 . 0 32: end if 33: end for 34: end for
Algorithm B.4: Detach node γ from an arbitrary graph 𝒢 N Require: 1 < N Require: γ ∈ { 0 , 1 , 2 , … , N − 1 } Require: τ [ i ] is the waiting time for node
i Require: Adj [ i ] is the ordered list of indices of all nodes connected to node
i via outgoing edges
Require: | Adj [ i ] | is the cardinality of
Adj [ i ] Require: Adj [ i ] [ j ] is the index of the
j th neighbour of node
i Require: P [ i ] is the ordered list of probabilities of leaving node
i via outgoing edges,
| P [ i ] | = | Adj [ i ] | Require: P [ i ] [ j ] is the probability of branching from node
i to node
Adj [ i ] [ j ] 1: for all β γ ∈ { 0 , 1 , 2 , … , | Adj [ γ ] | − 1 } do 2: β ← Adj [ γ ] [ β γ ] 3: γ β ← − 1 4: for all i ∈ { 0 , 1 , 2 , … , | Adj [ β ] | − 1 } do 5: if Adj [ β ] [ i ] = γ then 6: γ β ← i 7: break 8: end if 9: end for 10: if not γ β = − 1 then 11: P β , β ← 1 ∕ ( 1 − P [ β ] [ γ β ] P [ γ ] [ β γ ] ) 12: P β , γ ← P [ β ] [ γ β ] 13: Adj [ β ] ← { Adj [ β ] [ 0 ] , Adj [ β ] [ 1 ] , … , Adj [ β ] [ γ β − 1 ] , Adj [ β ] [ γ β + 1 ] , … } 14: P [ β ] ← { P [ β ] [ 0 ] , P [ β ] [ 1 ] , … , P [ β ] [ γ β − 1 ] , P [ β ] [ γ β + 1 ] , … } 15: for all α γ ∈ { 0 , 1 , 2 , … , | Adj [ γ ] | − 1 } do 16: α ← Adj [ γ ] [ α γ ] 17: if not α = β then 18: if exists edge β → α then 19: for all i ∈ { 0 , 1 , 2 , … , | Adj [ β ] | − 1 } do 20: if Adj [ β ] [ i ] = α then 21: P [ β ] [ i ] ← P [ β ] [ i ] + P β , γ P [ γ ] [ α γ ] 22: break 23: end if 24: end for 25: else 26: Adj [ β ] ← { α , Adj [ β ] [ 0 ] , Adj [ β ] [ 1 ] , Adj [ β ] [ 2 ] , … } 27: P [ β ] ← { P β , γ P [ γ ] [ α γ ] , P [ β ] [ 0 ] , P [ β ] [ 1 ] , P [ β ] [ 2 ] , … } 28: end if 29: end if 30: end for 31: for all i ∈ { 0 , 1 , 2 , … , | P [ β ] | − 1 } do 32: P [ β ] [ i ] ← P [ β ] [ i ] P β , β 33: end for 34: τ β ← τ β + P β , γ τ γ P β , β 35: end if 36: end for