SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Layer-Neighbor Sampling — Defusing Neighborhood Explosion in GNNs
Muhammed Fatih Bahn*† balin@gatech.edu
Umit V. Catalyurek†† umit@gatech.edu
Graph Neural Networks (GNNs) have received significant attention recently, but training them at a large scale remains a challenge. Mini-batch training coupled with sampling is used to alleviate this challenge. However, existing approaches either suffer from the neighborhood explosion phenomenon or have suboptimal performance. To address these issues, we propose a new sampling algorithm called LAYER-neighBOR sampling (LABOR). It is designed to be a direct replacement for Neighbor Sampling (NS) with the same fanout hyperparameter while sampling up to 7 times fewer vertices, without sacrificing quality. By design, the variance of the estimator of each vertex matches NS from the point of view of a single vertex. Moreover, under the same vertex sampling budget constraints, LABOR converges faster than existing layer sampling approaches and can use up to 112 times larger batch sizes compared to NS.
Graph Neural Networks (GNN) [Hamilton et al., 2017, Kipf and Welling, 2017] have become a de facto models for representation learning on graph-structured data. Hence they have started being deployed in production systems [Ying et al., 2018, Niu et al., 2020]. These models iteratively update the node embeddings by passing messages along the direction of the edges in the given graph with nonlinearities between different layers. With  $l$  layers, the computed node embeddings contain information from the  $l$ -hop neighborhood of the seed vertex.
In the production setting, the GNN models need to be trained on billion-scale graphs [Ching et al., 2015, Ying et al., 2018]. The training of these models takes hours to days even on distributed systems [Zheng et al., 2022b,a]. As in general Deep Neural Networks (DNN), it is more efficient to use mini-batch training [Bertsekas, 1994] on GNNs, even though it is a bit trickier in this case. The node embeddings in GNNs depend recursively on their set of neighbors' embeddings, so when there are  $l$  layers, this dependency spans the  $l$ -hop neighborhood of the node. Real-world graphs usually have a very small diameter and if  $l$  is large, the  $l$ -hop neighborhood may very well span the entire graph, also known as the Neighborhood Explosion Phenomenon (NEP) [Zeng et al., 2020].
To solve these issues, researchers proposed sampling a subgraph of the  $l$ -hop neighborhood of the nodes in the batch. There are mainly three different approaches: Node-based, Layer-based and Subgraph-based methods. Node-based sampling methods [Hamilton et al., 2017, Chen et al., 2018a, Liu et al., 2020, Zhang et al., 2021] sample independently and recursively for each node. It was noticed that node-based methods sample subgraphs that are too shallow, i.e., with a low ratio of number of edges to nodes. Thus layer-based sampling methods were proposed [Chen et al., 2018b,
*Part of the GPU acceleration in this work was implemented during an internship at NVIDIA Corporation.
† School of Computational Science and Engineering, Georgia Institute of Technology, Atlanta, GA, USA
${}^{ \ddagger  }$  Amazon Web Services. This publication describes work performed at the Georgia Institute of Technology and is not associated with AWS.
Zou et al., 2019, Huang et al., 2018, Dong et al., 2021], where the sampling for the whole layer is done collectively. On the other hand subgraph sampling methods [Chiang et al., 2019, Zeng et al., 2020, Hu et al., 2020b, Zeng et al., 2021, Fey et al., 2021, Shi et al., 2023] do not use the recursive layer by layer sampling scheme used in the node- and layer-based sampling methods and instead tend to use the same subgraph for all of the layers. Some of these sampling methods take the magnitudes of embeddings into account [Liu et al., 2020, Zhang et al., 2021, Huang et al., 2018], while others, such as Chen et al. [2018a], Cong et al. [2021], Fey et al. [2021], Shi et al. [2023], cache the historical embeddings to reduce the variance of the computed approximate embeddings. There are methods of sampling from a vertex cache Dong et al. [2021] filled with popular vertices. Most of these approaches are orthogonal to each other and they can be incorporated into other sampling algorithms.
Node-based sampling methods suffer the most from the NEP but they guarantee a good approximation for each embedding by ensuring each vertex gets  $k$  neighbors which is the only hyperparameter of the sampling algorithm. Layer-based sampling methods do not suffer as much from the NEP because the number of vertices sampled is a hyperparameter but they can not guarantee that each vertex approximation is good enough and also their hyperparameters are hard to reason with, the number of nodes to sample at each layer depends highly on the graph structure (as the numbers in Table 2 show). Moreover, Table 4 in Chen et al. [2023] shows that they can be extremely sensitive to the chosen hyperparameters and final task performance can differ by up to  $15\%$  between choosing a fixed number or doubling the number of sampled vertices at each layer. It is also unclear why one should settle with doubling; tripling, or quadrupling could potentially improve the performance of the final trained model even further. Subgraph sampling methods usually sample sparser subgraphs compared to their node- and layer-based counterparts. Hence, in this paper, we focus on the node- and layer-based sampling methods and combine their advantages. The major contributions of this work can be listed as follows:
- We propose the use of Poisson Sampling for GNNs, taking advantage of its lower variance and computational efficiency against sampling without replacement. Applying it to the existing layer sampling method LADIES, we get the superior PLADIES method outperforming the former by up to  $2\%$  in terms of F1-score. Moreover, PLADIES is linear time, improving upon the recently proposed quadratic time debiasing technique in Chen et al. [2023].
- We propose a new sampling algorithm called LABOR, combining the advantages of neighbor and layer sampling approaches using Poisson Sampling. LABOR correlates the sampling procedures of the given set of seed nodes so that the sampled vertices from different seeds have a lot of overlap, resulting in a  $7 \times$  and  $4 \times$  reduction in the number of vertices and edges sampled compared to NS, respectively. Furthermore, LABOR can sample up to  $13 \times$  fewer edges compared to LADIES.
- We experimentally verify our findings and show that our proposed sampling algorithm LABOR outperforms both neighbor and layer sampling approaches. LABOR can enjoy a batch size of up to  $112 \times$  larger than NS while sampling the same number of vertices.
Graph Neural Networks: Given a directed graph  $\mathcal{G} = (V, E)$ , where  $V$  and  $E \subset V \times V$  are vertex and edge sets respectively,  $(t \rightarrow s) \in E$  denotes an edge from a source vertex  $t \in V$  to a destination vertex  $s \in V$ , and  $A_{ts}$  denotes the corresponding edge weight if provided. If we have a batch of seed vertices  $S \subset V$ , let us define  $l$ -hop neighborhood  $N^l(S)$  for the incoming edges as follows:
$$
N (s) = \{t | (t \rightarrow s) \in E \}, N ^ {1} (S) = N (S) = \cup_ {s \in S} N (s), N ^ {l} (S) = N \left(N ^ {(l - 1)} (S)\right) \tag {1}
$$
Let us also define the degree  $d_{s}$  of vertex  $s$  as  $d_{s} = |N(s)|$ . To simplify, let's assume uniform edge weights,  $A_{ts} = 1, \forall (t \to s) \in E$ . Then, our goal is to estimate the following for each vertex  $s \in S$ , where  $H_{t}^{(l-1)}$  is defined as the embedding of the vertex  $t$  at layer  $l-1$ , and  $W^{(l-1)}$  is the trainable weight matrix at layer  $l-1$ , and  $\sigma$  is the nonlinear activation function [Hamilton et al., 2017]:
$$
Z _ {s} ^ {l} = \frac {1}{d _ {s}} \sum_ {t \rightarrow s} H _ {t} ^ {(l - 1)} W ^ {(l - 1)}, H _ {s} ^ {l} = \sigma \left(Z _ {s} ^ {l}\right) \tag {2}
$$
Exact Stochastic Gradient Descent: If we have a node prediction task and  $V_{t} \subseteq V$  is the set of training vertices,  $y_{s}, s \in V_{t}$  are the labels of the prediction task, and  $\ell$  is the loss function for
the prediction task, then our goal is to minimize the following loss function:  $\frac{1}{|V_t|}\sum_{s\in V_t}\ell (y_s,Z_s^l)$ . Replacing  $V_{t}$  in the loss function with  $S\subset V_{t}$  for each iteration of gradient descent, we get stochastic gradient descent for GNNs. However with  $l$  layers, the computation dependency is on  $N^{l}(S)$ , which reaches large portion of the real world graphs, i.e.  $|N^{l}(S)|\approx |V|$ , making each iteration costly both in terms of computation and memory.
Neighbor Sampling: Neighbor sampling approach was proposed by Hamilton et al. [2017] to approximate  $Z_{s}^{(l)}$  for each  $s \in S$  with a subset of  $N^l (S)$ . Given a fanout hyperparameter  $k$ , this subset is computed recursively by randomly picking  $k$  neighbors for each  $s \in S$  from  $N(s)$  to form the next layer  $S^1$ , that is a subset of  $N^1 (S)$ . If  $d_{s} \leq k$ , then the exact neighborhood  $N(s)$  is used. For the next layer,  $S^1$  is treated as the new set of seed vertices and this procedure is applied recursively.
Revisiting LADIES, Dependent Layer-based Sampling: From now on, we will drop the layer notation and focus on a single layer, and also ignore the nonlinearities. Let us define  $M_{t} = H_{t}W$  as a shorthand notation. Then our goal is to approximate:
$$
H _ {s} = \frac {1}{d _ {s}} \sum_ {t \rightarrow s} M _ {t} \tag {3}
$$
If we assign probabilities  $\pi_t > 0, \forall t \in N(S)$  and normalize it so that  $\sum_{t \in N(S)} \pi_t = 1$ , then use sampling with replacement to sample  $T \subset N(S)$  with  $|T| = n$ , where  $n$  is the number of vertices to sample given as input to the LADIES algorithm and  $T$  is a multi-set possibly with multiple copies of the same vertices, and let  $\tilde{d}_s = |T \cap N(s)|$  which is the number of sampled vertices for a given vertex  $s$ , we get the following two possible estimators for each vertex  $s \in S$ :
$$
H _ {s} ^ {\prime} = \frac {1}{n d _ {s}} \sum_ {t \in T \cap N (s)} \frac {M _ {t}}{\pi_ {t}} \tag {4a}
$$
$$
H _ {s} ^ {\prime \prime} = \frac {\sum_ {t \in T \cap N (s)} \frac {M _ {t}}{\pi_ {t}}}{\sum_ {t \in T \cap N (s)} \frac {1}{\pi_ {t}}} \quad (4 b)
$$
Note that  $H_{s}^{\prime}$  in (4a) is the Thompson-Horvitz estimator and the  $H_{s}^{\prime \prime}$  in (4b) is the Hajek estimator. For a comparison between the two and how to get an even better estimator by combining them, see Khan and Ugander [2021]. The formulation in the LADIES paper uses  $H_{s}^{\prime}$ , but it proposes to row-normalize the sampled adjacency matrix, meaning they use  $H_{s}^{\prime \prime}$  in their implementation. However, analyzing the variance of the Thompson-Horvitz estimator is simpler and its variance serves as an upper bound for the variance of the Hajek estimator when  $|M_{t}|$  and  $\pi_t$  are uncorrelated [Khan and Ugander, 2021, Dorfman, 1997], which we assume to be true in our case. Note that the variance analysis is simplified to be element-wise for all vectors involved.
$$
\operatorname {V a r} \left(H _ {s} ^ {\prime \prime}\right) \leq \operatorname {V a r} \left(H _ {s} ^ {\prime}\right) = \frac {1}{\tilde {d} _ {s} d _ {s} ^ {2}} \sum_ {t \rightarrow s} \pi_ {t} \sum_ {t ^ {\prime} \rightarrow s} \frac {\operatorname {V a r} \left(M _ {t ^ {\prime}}\right)}{\pi_ {t ^ {\prime}}} \tag {5}
$$
Since we do not have access to the computed embeddings and to simplify the analysis, we assume that  $\operatorname{Var}(M_t) = 1$  from now on. One can see that  $\operatorname{Var}(H_s')$  is minimized when  $\pi_t = p, \forall t \to s$  under the constraint  $\sum_{t \to s} \pi_t \leq pd_s$  for some constant  $p \in [0,1]$ , hence any deviation from uniformity increases the variance. The variance is also smaller the larger  $\tilde{d}_s$  is. However, in theory and in practice, there is no guarantee that each vertex  $s \in S$  will get any neighbors in  $T$ , not to mention equal numbers of neighbors. Some vertices will have pretty good estimators with thousands of samples and very low variances, while others might not even get a single neighbor sampled. For this reason, we designed LABOR so that every vertex in  $S$  will sample enough neighbors in expectation.
While LADIES is optimal from an approximate matrix multiplication perspective [Chen et al., 2023], it is far from optimal in the case of nonlinearities and multiple layers. Even if there is a single layer, then the used loss functions are nonlinear. Moreover, the existence of nonlinearities in-between layers and the fact that there are multiple layers exacerbates this issue and necessitates that each vertex gets a good enough estimator with low enough variance. Also, LADIES gives a formulation using sampling with replacement instead of without replacement and that is sub-optimal from the variance perspective while its implementation uses sampling without replacement without taking care of the bias created thereby. In the next section, we will show how all of these problems are addressed by our newly proposed Poisson sampling framework and LABOR sampling.
3 Proposed Layer Sampling Methods
Node-based sampling methods suffer from sampling too shallow subgraphs leading to NEP in just a few hops (e.g., see Table 2). Layer sampling methods Zou et al. [2019] attempt to fix this by sampling a fixed number of vertices in each layer, however they can not ensure that the estimators for the vertices are of high quality, and it is hard to reason how to choose the number of vertices to sample in each layer. LADIES Zou et al. [2019] proposes using the same number for each layer while papers evaluating it found it is better to sample an increasing number of vertices in each layer Liu et al. [2020], Chen et al. [2023]. There is no systematic way to choose how many vertices to sample in each layer for the LADIES method, and since each graph has different density and connectivity structure, this choice highly depends on the graph in question. Therefore, due to its simplicity and high quality results, Neighbor Sampling currently seems to be the most popular sampling approach and there exists high quality implementations on both CPUs and GPUs in the popular GNN frameworks Wang et al. [2019], Fey and Lenssen [2019].
We propose a new approach that combines the advantages of layer and neighbor sampling approaches using a vertex-centric variance-based framework, reducing the number of sampled vertices drastically while ensuring the training quality does not suffer and matches the quality of neighbor sampling. Another advantage of our method is that the user only needs to choose the batch size and the fanout hyperparameters as in the Neighbor Sampling approach, the algorithm itself then samples the minimum number of vertices in the later layers in an unbiased way while ensuring each vertex gets enough neighbors and a good approximation.
We achieve all the previously mentioned good properties with the help of Poisson Sampling. So, the next section will demonstrate applying Poisson Sampling to Layer Sampling, and then we will show how the advantages of Layer and Neighbor Sampling methods can be combined into LABOR while getting rid of their cons altogether.
3.1 Poisson Layer Sampling (PLADIES)
In layer sampling, the main idea can be summarized as individual vertices making correlated decisions while sampling their neighbors, because in the end if a vertex  $t$  is sampled, all edges into the seed vertices  $S$ , i.e.,  $t \to s$ ,  $s \in S$ , are added to the sampled subgraph. This can be interpreted as vertices in  $S$  making a collective decision on whether to sample  $t$ , or not.
The other thing to keep in mind is that the existing layer sampling methods use sampling with replacement when doing importance sampling with unequal probabilities, because it is nontrivial to compute the inclusion probabilities in the without replacement case. The Hajek estimator in the without replacement case with equal probabilities becomes:
$$
H _ {s} ^ {\prime \prime} = \frac {\sum_ {t \in T \cap N (s)} \frac {M _ {t}}{\bar {\pi} _ {t}}}{\sum_ {t \in T \cap N (s)} \frac {1}{\bar {\pi} _ {t}}} = \frac {\sum_ {t \in T \cap N (s)} M _ {t} | N (S) |}{\sum_ {t \in T \cap N (s)} | N (S) |} = \frac {1}{\tilde {d} _ {s}} \sum_ {t \in T \cap N (s)} M _ {t} \tag {6}
$$
and it has the variance:
$$
\operatorname {V a r} \left(H _ {s} ^ {\prime \prime}\right) = \frac {d _ {s} - \tilde {d} _ {s}}{d _ {s} - 1} \frac {1}{\tilde {d} _ {s}} \tag {7}
$$
Let us show how one can do layer sampling using Poisson sampling (PLADIES). Given  $n \in \mathbb{Z}^+$  and unnormalized probabilities  $\pi_t \in [0, \infty), \forall t \in N(S)$ , we can ensure that  $\sum_{t \in N(S)} \pi_t = n$  by finding a solution of  $\sum_{t \in N(S)} \min(1, c\pi_t) = n$  for  $c \in \mathbb{R}^+$  in linear time and redefining  $\pi_t \gets \min(1, c\pi_t)$  so that  $\pi_t \in [0, 1]$ . Then we include  $t \in N(S)$  in our sample  $T$  with probability  $\pi_t$  by flipping a coin for it, i.e., we sample  $r_t \sim U(0, 1)$  and include  $t \in T$  if  $r_t \leq \pi_t$ . In the end,  $E[|T|] = n$  and we can still use the Hajek estimator  $H_s''$  or the Horvitz Thomson estimator  $H_s'$  to estimate  $H_s$ . Doing layer sampling this way is unbiased by construction and achieves the same goal in linear time in contrast to the quadratic time debiasing approach explained in Chen et al. [2023], further discussion can be found in Appendix A.7. The variance then approximately becomes [Williams et al., 1998], see Appendix A.1 for a derivation:
$$
\operatorname {V a r} \left(H _ {s} ^ {\prime \prime}\right) \leq \operatorname {V a r} \left(H _ {s} ^ {\prime}\right) = \frac {1}{d _ {s} ^ {2}} \sum_ {t \rightarrow s} \frac {1}{\pi_ {t}} - \frac {1}{d _ {s}} \tag {8}
$$
One can notice that the minus term  $\frac{1}{d_s}$  enables the variance to converge to 0, if all  $\pi_t = 1$  and we get the exact result. However, in the sampling with replacement case, the variance goes to 0 only as the sample size goes to infinity.
3.2 LABOR: Layer Neighbor Sampling
The design philosophy of LABOR Sampling is to create a direct alternative to Neighbor Sampling while incorporating the advantages of layer sampling. Mimicking Layer Sampling with Poisson Sampling in Section 3.1 still has the disadvantage that  $\tilde{d}_s$  varies wildly for different  $s$ . To overcome this and mimic Neighbor Sampling where  $E[\tilde{d}_s] = \min(d_s, k)$ , where  $k$  is a given fanout hyperparameter, we proceed as follows: for given  $\pi_t \geq 0, \forall t \in N(S)$  denoting unnormalized probabilities, for a given  $s$ , let us define  $c_s$  as the quantity satisfying the following equality if  $k < d_s$ , otherwise  $c_s = \max_{t \to s} \frac{1}{\pi_t}$ :
$$
\frac {1}{d _ {s} ^ {2}} \sum_ {t \rightarrow s} \frac {1}{\min  \left(1 , c _ {s} \pi_ {t}\right)} - \frac {1}{d _ {s}} = \frac {1}{k} - \frac {1}{d _ {s}} \tag {9}
$$
Note that  $\frac{1}{k} -\frac{1}{d_s}$  is the variance when  $\pi_t = \frac{k}{d_s},\forall t\in N(s)$  so that  $E[\tilde{d}_s] = k$  . Also note that:
$$
\frac {d _ {s}}{d _ {s} - 1} \left(\frac {1}{k} - \frac {1}{d _ {s}}\right) - \frac {d _ {s} - k}{d _ {s} - 1} \frac {1}{k} = \frac {d _ {s} - k}{k \left(d _ {s} - 1\right)} - \frac {d _ {s} - k}{d _ {s} - 1} \frac {1}{k} = 0 \tag {10}
$$
meaning that the variance target we set through (9) is equal to Neighbor Sampling's variance in (7) after calibrating with  $\frac{d_s}{d_s - 1}$  Ohlsson [1998] and it will result in  $E[\tilde{d}_s]\geq k$  with strict equality in the uniform probability case. Then each vertex  $s\in S$  samples  $t\to s$  with probability  $c_{s}\pi_{t}$ . To keep the collective decision making, we sample  $r_t\sim U(0,1),\forall t\in N(S)$  and vertex  $s$  samples vertex  $t$  if and only if  $r_t\leq c_s\pi_t$ . Note that if we use a uniform random variable for each edge  $r_{ts}$  instead of each vertex  $r_t$ , and if  $\pi$  is uniformly initialized, then we get the same behavior as Neighbor Sampling.
3.2.1 Importance Sampling
Given the sampling procedure above, one wonders how different choices of  $\pi \geq 0$  will affect  $|T|$ , the total number of unique vertices sampled. We can compute its expected value as follows:
$$
\begin{array}{l} E [ | T | ] = \sum_ {t \in N (S)} \mathbb {P} (t \in T) \\ = \sum_ {t \in N (S)} \min  \left(1, \pi_ {t} \max  _ {t \rightarrow s} c _ {s}\right) \tag {11} \\ \end{array}
$$
In particular, we need to minimize  $E[[T]]$ :
$$
\pi^ {*} = \underset {\pi \geq 0} {\arg \min } \sum_ {t \in N (S)} \min  \left(1, \pi_ {t} \max  _ {t \rightarrow s} c _ {s}\right) \tag {12}
$$
Note that for any given  $\pi \geq 0$ ,  $E[|T|]$  is the same for any vector multiple  $x\pi, x \in \mathbb{R}^{+}$ , meaning the objective function is homogeneous of degree 0.
3.2.2 Computing  $c$  and  $\pi^{*}$
$c_{s}$  was defined to be the scalar satisfying the following equality involving the variance of the estimator of  $H_{s}$ :
$$
\frac {1}{d _ {s} ^ {2}} \sum_ {t \rightarrow s} \frac {1}{\min  \left(1 , c _ {s} \pi_ {t}\right)} - \frac {1}{d _ {s}} = \frac {1}{k} - \frac {1}{d _ {s}} \tag {13}
$$
If we rearrange the terms, we get:
$$
\sum_ {t \rightarrow s} \frac {1}{\min  \left(1 , c _ {s} \pi_ {t}\right)} = \frac {d _ {s} ^ {2}}{k} \tag {14}
$$
One can see that the left-hand side of the equality is monotonically decreasing with respect to  $c_{s} \geq 0$ . Thus one can use binary search to find the  $c_{s}$  satisfying the above equality to any precision needed. But we opt to use the following iterative algorithm to compute it:
$$
v _ {s} ^ {(0)} = 0, c _ {s} ^ {(0)} = \frac {k}{d _ {s} ^ {2}} \sum_ {t \rightarrow s} \frac {1}{\pi_ {t}} \tag {15}
$$
$$
\begin{array}{l} c _ {s} ^ {(i + 1)} = \frac {c _ {s} ^ {(i)}}{\frac {d _ {s} ^ {2}}{k} - v _ {s} ^ {(i)}} \left(- v _ {s} ^ {(i)} + \sum_ {t \rightarrow s} \frac {1}{\min \left(1 , c _ {s} ^ {(i)} \pi_ {t}\right)}\right) (16) \\ v _ {s} ^ {(i + 1)} = \sum_ {t \rightarrow s} \mathbb {1} \left[ c _ {s} ^ {(i + 1)} \pi_ {t} \geq 1 \right] (17) \\ \end{array}
$$
This iterative algorithm converges in at most  $d_{s}$  steps and the convergence is exact and monotonic from below. One can also implement it in linear time  $\mathcal{O}(d_s)$  if  $\{\pi_t\mid t\to s\}$  is sorted and making use of precomputed prefix sum arrays. Note that  $c = c(\pi)$ , meaning that  $c$  is a function of the given probability vector  $\pi$ . To compute  $\pi^{*}$ , we use a similar fixed point iteration as follows:
$$
\pi^ {(0)} = 1, \forall t \in N (S): \pi_ {t} ^ {(i + 1)} = \pi_ {t} ^ {(i)} \max  _ {t \rightarrow s} c _ {s} (\pi^ {(i)}) \tag {18}
$$
Algorithm 1 LABOR-i for uniform edge weights  
1: Input: seed vertices  $S$ , # iters  $i$ , fanout  $k$   
2: Output: sampled edges  $E'$  and weights  $A'$   
3:  $T \gets \{t \mid t \in N(S)\}$   
4:  $c_s = \frac{k}{d_s}, \forall s \in S$   
5:  $\pi_t \gets 1, \forall t \in T$   
6: while  $i > 0$  do  
7: for all  $s \in S$  do  
8: Solve (14) for  $c_s$   
9: for all  $t \in T$  do  
10:  $\pi_t \gets \pi_t \max_{t \to s} c_s$   
11:  $i \gets i - 1$   
12:  $r_t \sim U(0,1), \forall t \in T$   
13:  $E' \gets []$   
14:  $A' \gets []$   
15: for all  $s \in S$  do  
16:  $w \gets 0$   
17: for all  $t \in N(s)$  do  
18: if  $r_t \leq c_s\pi_t$  then  
19:  $E'.\text{append}(t \to s)$   
20:  $w \gets w + \frac{1}{\min(1,c_s\pi_t)}$   
21: for all  $t \in N(s)$  do  
22: if  $r_t \leq c_s\pi_t$  then  
23:  $A'.\text{append}(\frac{1}{\min(1,c_s\pi_t)}w)$