A Local Clustering Algorithm for Massive Graphs and its Application to Nearly-Linear Time Graph Partitioning
Daniel A. Spielman, Shang-Hua Teng
Introduction
Given a vertex of interest in a massive graph, we would like to find a small cluster around that vertex, in time proportional to the size of the cluster. The algorithm we introduce will solve this problem while only examining vertices near the initial vertex, under some reasonable notion of nearness. We call such an algorithm a local algorithm.
Our local clustering algorithm provides a very powerful primitive for the design of fast graph algorithms. In Section 3 of this paper, we use it to design the first nearly-linear time algorithm for graph partitioning that produces a partition of nearly-optimal balance among those approximating a target conductance. In the papers [ST08b] and [ST08a], we proceed to use this graph partitioning algorithm to design nearly-linear time algorithms for sparsifying graphs and for solving symmetric, diagonally-dominant linear systems.
We say that a graph algorithm is a local algorithm if it is given a particular vertex as input, and at each step after the first only examines vertices connected to those it has seen before. The use of a local algorithm naturally leads to the question of in which order one should explore the vertices of a graph. While it may be natural to explore vertices in order of shortest-path distance from the input vertex, such an ordering is a poor choice in graphs of low-diameter, such as social network graphs [LH08]. We suggest first processing the vertices that are most likely to occur in short random walks from at the input vertex. That is, we consider a vertex to be near the input vertex if it is likely to appear in a short random walk from the input vertex.
In Section 3, we use a local graph exploration process to find a cluster that is near the input vertex. Following Kannan, Vempala and Vetta [KVV04], we say that a set of vertices is a good cluster if it has low conductance; that is, if it has many more external than internal edges. We give an efficient local clustering algorithm, Nibble, that runs in time proportional to the size of the cluster it outputs. Although our algorithm may not find a local cluster for some input vertices, we will show that it is usually successful. In particular, we prove the following theorem: There exists a constant such that for any target conductance and any cluster of conductance at most , when given a random vertex sampled according to degree inside , Nibble will return a cluster mostly inside and with conductance at most , with probability at least .
The local clustering algorithm Nibble makes a novel use of random walks. For a positive integer , suppose is the probability distribution of the -step random walk starting at . As the support of —the set of nodes with positive probability—could grow rapidly, Nibble maintains a truncated version of the distribution. At each step of the truncated random walks, Nibble looks a for cluster among only nodes with high probability. The truncation is critical to ensure that the clustering algorithm is output sensitive. It guarantees that the size of the support of the distribution that Nibble maintains is not too much larger than the size of the cluster it produces. The cluster that Nibble produces is local to the starting vertex in the sense that it consists of nodes that are among the most favored destinations of random walks starting from .
By using the personal PageRank vector [PBMW98] to define nearness, Andersen, Chung and Lang [ACL06], have produced an improved version of our algorithm Nibble, which they call PageRank-Nibble. Following this work, other local algorithms have been designed by Andersen et. al. [ABC+07] for approximately computing Personal PageRank vectors, by Andersen [And08] for finding dense subgraphs and by Andersen, Chung and Lang [ACL07] for partitioning directed graphs.
2 Nearly Linear-Time Algorithms
Our local clustering algorithm provides a powerful tool for designing fast graph algorithms. In this paper and its two companion papers, we show how to use it to design randomized, nearly linear-time algorithms for several important graph-theoretic and numerical problems.
The need for algorithms whose running time is linear or nearly linear in their input size has increased as algorithms handle larger inputs. For example, in circuit design and simulation, an Intel Dual Core Itanium processor has more than one billion transistors, which is more than 100 times the number of transistors that the Pentium had in 2000 [Cor05]; in scientific computing, one often needs to solve linear systems that involve hundreds of millions of variables [SLM+02]; in modern information infrastructure, the web has grown into a graph of hundreds billions of nodes [GS05]. As a result of this rapid growth in problem size, what used to be considered an efficient algorithm, such as a -time algorithm, may no longer be adequate for solving problems of these scales. Space complexity poses an even greater problem.
Many basic graph-theoretic problems such as connectivity and topological sorting can be solved in linear or nearly-linear time. The efficient algorithms for these problems are built on linear-time primitives such as Breadth-First-Search (BFS) and Depth-First-Search (DFS). Minimum Spanning Trees (MST) and Shortest-Path Trees are examples of other commonly used nearly linear-time primitives. We hope to build up the library of nearly-linear time graph algorithms that may be used as primitives. While the analyzable variants of the algorithms we present here, and even their improved versions by Andersen, Chung and Lang [ACL06], may not be immediately useful in practice, we believe practical algorithms may be derived from them by making less conservative choices of parameters.
Our local clustering algorithm provides an exciting new primitive for developing nearly linear-time graph algorithms. Because its running time is proportional to the size of the cluster it produces, we can repeatedly apply it remove many clusters from a graph, all within nearly-linear time.
In the second part of this paper, we use Nibble as a subroutine to construct a randomized graph partitioning algorithm that runs in nearly-linear time. To the best of our knowledge, this is the first nearly linear-time partitioning algorithm that finds an approximate sparsest cut with approximately optimal balance. In our first companion paper [ST08b], we apply this new partitioning algorithm to develop a nearly-linear-time algorithm for producing spectral sparsifiers of graphs. We begin that paper by extending the partitioning algorithm of this paper to obtain a stronger guarantee on its output: if it outputs a small set, then the complement must be contained in a subgraph whose conductance is higher than the target.
Clusters and Conductance
Let be an undirected graph with . A cluster of is a subset of that is richly intra-connected but sparsely connected with the rest of the graph. The quality of a cluster can be measured by its conductance, the ratio of the number of its external connections to the number of its total connections.
We let denote the degree of vertex . For , we define (often called the volume of ). So, . Let be the set of edges connecting a vertex in with a vertex in . We define the conductance of a set of vertices , written by
We sometime refer to a subset of as a cut of and refer to as a partition of . The balance of a cut or a partition is then equal to
We call a sparsest cut of if and .
In the construction of a partition of , we will be concerned with vertex-induced subgraphs of . However, when measuring the conductance and volumes of vertices in these vertex-induced subgraphs, we will continue to measure the volume according to the degrees of vertices in the original graph. For clarity, we define the conductance of a set in the subgraph induced by by
For convenience, we define and, for , .
For , we let denote the subgraph of induced by the vertices in . We introduce the notation to denote graph to which self-loops have been added so that every vertex in has the same degree as in . Each self-loop adds 1 to the degree. We remark that if is the subgraph of induced on the vertices in , then
So, when we prove lower bounds on , we obtain lower bounds on .
Clustering is an optimization problem: Given an undirected graph and a conductance parameter, find a cluster such that , or determine no such cluster exists. The problem is NP-complete (see, for example [LR99] or [SS06]). But, approximation algorithms exist. Leighton and Rao [LR99] used linear programming to obtain -approximations of the sparsest cut. Arora, Rao and Vazirani [ARV04] improved this to through semi-definite programming. Faster algorithms obtaining similar guarantees have been constructed by Arora, Hazan and Kale [AHK04], Khandekar, Rao and Vazirani [KRV06], Arora and Kale [AK07], and Orecchia, Schulman, Vazirani, and Vishnoi [OSVV08].
The algorithm Nibble works by approximately computing the distribution of a few steps of the random walk starting at a seed vertex . It is implicit in the analysis of the volume estimation algorithm of Lovász and Simonovits [LS93] that one can find a cut with small conductance from the distributions of the steps of the random walk starting at any vertex from which the walk does not mix rapidly. We will observe that a random vertex in a set of low conductance is probably such a vertex. We then extend the analysis of Lovász and Simonovits to show one can find a cut with small conductance from approximations of these distributions, and that these approximations can be computed quickly. In particular, we will truncate all small probabilities that appear in the distributions to 0. In this way, we reduce the work required to compute our approximations.
For the rest of this section, we will work with a graph with vertices and edges, so that . We will allow some of these edges to be self-loops. Except for the self-loops, which we allow to occur with multiplicities, the graph is assumed to be unweighted. We will let be the adjacency matrix of this graph. That is,
We define the following two vectors supported on a set of vertices :
We will consider the random walk that at each time step stays at the current vertex with probability , and otherwise moves to the endpoint of a random edge attached to the current vertex. Thus, self-loops increase the chance the walk stays at the current vertex. For example, if a vertex has edges, one of which is a self-loop, then when the walk is at this vertex it has a chance of staying at that vertex, and a chance of moving to each of its neighbors.
The matrix realizing this walk can be expressed by , where is the degree of node , and is the diagonal matrix with diagonal entries . Typically, a random walk starts at a node . In this case, the distribution of the random walk at time evolves according to .
We note that is the steady-state distribution of the random walk, and that is the restriction of that walk to the set .
We will use the truncation operation defined by
Our algorithm, Nibble, will generate the sequence of vectors starting at by the rules
That is, at each time step, we will evolve the random walk one step from the current density, and then round every that is less than to 0. Note that and are not necessarily probability vectors, as their components may sum to less than .
In the statement of the algorithm and its analysis, we will use the following notation. For a vector , we let be the set of vertices maximizing , breaking ties lexicographically. That is, where is the permutation such that
for all , and when these two ratios are equal. We then set
Note that always equals .
Following Lovász and Simonovits [LS90], we set
This function is essentially the same as the function defined by Lovász and Simonovits—it only differs by a linear transformation.
We remark that for , , and that is linear in between these points. Finally, we let denote the partial derivative of with respect to , with the convention that for ,
where is the permutation specified above so that .
As is non-increasing, is a non-increasing function in and is a concave function in .
During the course of our exposition, we will need to set many constants, which we collect here for convenience. For each, we provide a suitable value and indicate where it is first used in the paper.
The following is an exhaustive list of the inequalities we require these constants to satisfy.
Given a , we set constants that will play a prominent role in our analysis:
Condition (C.1) guarantees that the set has low conductance. Condition (C.2) ensures that it does not contain too much volume, while condition (C.3) ensures that it does not contain too little. Condition (C.4) guarantees that many elements of have large probability mass. While it would be more natural to define condition (C.4) as a constraint on instead of , our proof of correctness requires the latter.
In the rest of this section, we will prove the following theorem on the performance of Nibble.
Nibble can be implemented so that on all inputs, it runs in time . Moreover, Nibble satisfies the following properties.
When is non-empty,
, and
and imply .
2 Basic Inequalities about Random Walks
We first establish some basic inequalities that will be useful in our analysis. Readers who are eager to see the analysis of Nibble can first skip this subsection. Suppose is an undirected graph. Recall , where is the adjacency matrix of .
Applying the transformation , we see that it is equivalent to show that for all
To prove this, we note that , and the sum of the entries in each row of this matrix is 1. ∎
For a set , we define the matrix to be the diagonal matrix such that if and otherwise.
For every , all non-negative vectors and , and every ,
as , , , and are all non-negative. The proposition now follows by induction. ∎
For all and for all ,
Note that is the distribution after a single-step walk from a random vertex in and {\mbox{\boldmath1}}^{T}D_{S}(M\psi_{S}) is the probability that the walk stays inside . Thus, {\mbox{\boldmath1}}^{T}(D_{S}M)^{t}\psi_{S} is the probability that a -step walk starting from a random vertex in stays entirely in .
We first prove by induction that for all ,
The base case, , follows from the fact that . To complete the induction, observe that if is a non-negative vector such that , then
where the second-to-last inequality follows from Proposition 2.2.
from which the proposition follows, as {\mbox{\boldmath1}}^{T}\psi_{S}=1.
Observing that {\mbox{\boldmath1}}^{T}M={\mbox{\boldmath1}}^{T}, we compute
3 The Analysis of Nibble
Our analysis of Nibble consists of three main steps. First, we define the sets mentioned in Theorem 2.1 and establish property (N.2). We then refine the structure of to define sets and prove property (N.3). The sets and are defined in terms of the distributions of random walks from a vertex in , without reference to the truncation we perform in the algorithm. We then analyze the impact of truncation used in Nibble and extend the theory of Lovász and Simonovits [LS93] to truncated random walks.
Step 1: SgS^{g} and its properties
For each set , we define to be the set of nodes in such that for all ,
Note that denotes the probability that a -step random walk starting from terminates outside . Roughly speaking, is the set of vertices such that a random walk from it is reasonably likely to still be in after time steps. We will prove the following bound on the volume of .
Let , and let be the diagonal matrix such that if and otherwise. For ,
as {\mbox{\boldmath1}}^{T}(D_{S}M)^{t}\chi_{v} is a non-increasing function of . Define
So, , and it suffices to prove that .
We now prove the following lemma, which says that if Nibble is started from any with parameter and returns a non-empty set , then .
Let be a set of vertices such that . If Nibble is run with parameter , is started at a , and outputs a non-empty set , then .
For , let be given by (1) and (2). Then, for ,
where the second inequality follows from the definition of .
Let be the index of the step at which the set is generated. Let be the least integer such that . Condition (C.3) implies . As is non-increasing in its second argument and constant between and , Condition guarantees that for all ,
by (4). So, , and, as ,
Step 2: Refining SgS^{g}
Before defining the sets , we first recall some of the facts we can infer about the function from the work of Lovász and Simonovits. These facts will motivate our definitions and analysis.
In the first part of the proof of Lemma 1.4 of [LS90], Lovász and Simonovits prove
For every non-negative vector and every ,
For each , is a concave function that starts at and goes to . Lemma 2.9 says that for each , the curve defined by lies below the curve defined by . In particular,
If none of the sets has conductance less than , then Lovász and Simonovits prove a bound on how far below the curve of must lie. The following Lemma is a special case of Lemma 1.4 of [LS93], restricted to points of the form . Lovász and Simonovits [LS90] claim that the following is true for all , but point out in the journal version of their paper [LS93] that this claim was false. Fortunately, we do not need the stronger claim.
For any non-negative vector , if , then for ,
where denotes .
The mistake in [LS90] is the assertion in the beginning of the proof that the inequality holds for all if it holds for all of form .
When this lemma applies, one may draw a chord across the curve of around of width proportional to , and know that lies below. Thus, we know that if none of the sets has conductance less than , then the curve will approach a straight line. On the other hand, Proposition 2.5 will tell us that some point of lies well above this line (see Lemma 2.14).
We write instead of when is clear from context. Define
The quantities are well-defined and the sets partition . Moreover, for all .
Finally, to show that , we apply Lemma 2.9 to show
As is non-decreasing and
Step 3: Clustering and truncated random walks
We now establish that vectors produced by the truncated random walk do not differ too much from those produced by the standard random walk.
The left-hand inequalities of (20) are trivial. To prove the right-hand inequality of (20), we consider , observe that by definition
and then apply Proposition 2.2. Inequality (21) then follows from (3). ∎
Let be a set of vertices such that and , and let lie in . Define by running Nibble is with parameter .
Let be a set of vertices such that and , and let lie in . If Nibble is run with parameter , then for all , condition (C.4) is satisfied.
where the first inequality follows from Lemma 2.13 and the second follows from Lemma 2.9.
As is non-increasing in and , we have
where the second inequality follows from Lemma 2.9 and the definition of , and the last follows from (23).
If , then and we have , and so
If , then , and so for all , which implies
It remains to show that conditions (C.1–3) are met for some . We will do this by showing that if at least one of these conditions fail for every and every , then the curve will be too low, in violation of Lemma 2.14.
We will prove by induction that the conditions of the lemma imply that for all and all ,
The base case is when , in which case (24) is satisfied because
For , .
For , we have as both are at , the right-hand term dominates at , the left-hand term is linear in this region, and the right-hand term is concave.
For , we note that at , , and that we already know the right-hand term dominates at . The inequality then follows from the facts that left-hand term is linear in this region, and the right-hand term is concave.
Lovász and Simonovits [LS90] observe that
We now prove that (24) holds for , assuming it holds for , by considering three cases. As the right-hand side is concave and the left-hand side is piecewise-linear between points of the form , it suffices to prove the inequality at the points . If and , then (24) holds trivially. Similarly, if , then (24) holds trivially as well, as the left-hand side is at most 1, and the right hand side is at least 1. In the other cases, we have , in which case we may apply Lemma 2.10 to show that for
We now observe that has been chosen to ensure
Let be a set of vertices such that and , and let lie in . If Nibble is run with parameter , then there exists a and a for which conditions (C.1-3) are satisfied.
4 Proof of Theorem 2.1
Fact (N.1) follows from conditions (C.1) and (C.2) in the algorithm. Given a set satisfying , the lower bound on the volume of the set is established in Lemma 2.7. If and , then Lemmas 2.17 and 2.15 show that the algorithm will output a non-empty set. Finally, lemma 2.8 tells us that if , and the algorithm outputs a non-empty set , then it satisfies .
It remains to bound the running time of Nibble. The algorithm will run for iterations. We will now show that with the correct implementation, each iteration takes time . Instead of performing a dense vector multiplication in step (3.a), the algorithm should keep track of the set of vertices at which . Call this set . The set can be computed in time in step (3.b). Given knowledge of , the multiplication in step (3.a) can be performed in time proportional to
Finally, the computation in step (3.c) might require sorting the vectors in according to , which could take time at most . Thus, the run-time of Nibble is bounded by
Nearly Linear-Time Graph Partitioning
In this section, we apply Nibble to design a partitioning algorithm Partition. This new algorithm runs in nearly linear-time. It computes an approximate sparsest cut with approximately optimal balance. In particular, we prove that there exists a constant such that for any graph that has a cut of sparsity and balance , with high probability, Partition finds a cut with and . Actually, Partition satisfies an even stronger guarantee: with high probability either the cut it outputs is well balanced,
or touches most of the edges touching ,
The expected running time of Partition is . Thus, it can be used to quickly find crude cuts.
Partition calls Nibble via a routine called Random Nibble that calls Nibble with carefully chosen random parameters. Random Nibble has a very small expected running time, and is expected to remove a similarly small fraction of any set with small conductance.
(1) Choose a vertex according to . (2) Choose a in according to (3) .
Let be the number of edges in . The expected running time of Random Nibble is . If the set output by Random Nibble is non-empty, it satisfies
.
The expected running time of Random Nibble may be upper bounded by
Parts (R.1) and (R.2) follow directly from part (N.1) of Theorem 2.1. To prove part (R.3), define by
So, . For each , the chance that lands in is . Moreover, the chance that is at least . If lands in , then by part (N.3) of Theorem 2.1, satisfies
2 Partition
We now define Partition and analyze its performance. First, define
, where is a graph, . (0) Set , and . (1) While and , (a) Set . (b) Set (c) Set . (2) Set .
On input a graph with edges, the expected running time of Partition is . Let be the output of , where is a graph and . Then
,
If then , and
then with probability at least , .
In particular, with probability at least either
, or
.
Property (P.3) is a little unusual and deserves some explanation. It says that for every set of low conductance, with high probability either is a large fraction of , or it is a large fraction of the entire graph. While we would like to pick just one of these properties and guarantee that it holds with high probability, this would be unreasonable: on one hand, there might be no big set of small conductance; and, on the other hand, even if is small the algorithm might cut out a large set that completely avoids .
The bound on the expected running time of Partition is immediate from the bound on the running time of RandomNibble.
Let be the iteration at which Partition stops, so that . To prove (P.1), note that and so . By part (R.2) of Lemma 3.1, . So,
So, if , then . On the other hand, we established above that , from which it follows that
Let . To prove part (P.3), let satisfy (28) and consider what happens if we ignore the second condition in the while loop and run Partition for all potential iterations, obtaining cuts . Let
hold at iteration , then with probability at least , one of these conditions will be satisfied by iteration . Thus, after all iterations, one of conditions or will be satisfied with probability at least . If the algorithm runs for fewer iterations, then condition is satisfied.
To simplify notation, let and , for . Assume that
For , define the random variable
As each set is a subset of , and the are mutually disjoint, we will always have
and note that this ensures . Moreover, if , then will hold.
We need to show that, with probability at least , either an event holds, or . To this end, we now show that if neither nor holds, then . If , then
We also have , so the conditions of part of Lemma 3.1 are satisfied and
So, for all we have , and so . On the other hand,
This implies that with probability at least either or some event holds, which is what we needed to show. ∎