{'fraction_non_alphanumeric': 0.03986304719980435, 'fraction_numerical': 0.008253851797505502, 'mean_word_length': 4.3531336933398785, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Graph Degree Linkage: Agglomerative Clustering on a Directed Graph

This paper proposes a simple but effective graph-based agglomerative algorithm, for clustering high-dimensional data. We explore the different roles of two fundamental concepts in graph theory, indegree and outdegree, in the context of clustering. The average indegree reflects the density near a sample, and the average outdegree characterizes the local geometry around a sample. Based on such insights, we define the affinity measure of clusters via the product of average indegree and average outdegree. The product-based affinity makes our algorithm robust to noise. The algorithm has three main advantages: good performance, easy implementation, and high computational efficiency. We test the algorithm on two fundamental computer vision problems: image clustering and object matching. Extensive experiments demonstrate that it outperforms the state-of-the-arts in both applications.


Introduction
Many problems in computer vision involve clustering. Partitional clustering, such as k-means [1], determines all clusters at once, while agglomerative clustering [1] begins with a large number of small clusters, and iteratively selects two clusters with the largest affinity under some measures to merge, until some stopping condition is reached. Agglomerative clustering has been studied for more than half a century, and used in many applications [1], because it is conceptually simple and produces an informative hierarchical structure of clusters.
Classical agglomerative clustering algorithms have several limitations [1], which have restricted their wider applications in computer vision. The data in computer vision applications are usually high dimensional. The distributions of data clusters are often in different densities, sizes, and shapes, and form manifold structures. In addition, there are often noise and outliers in data. The conventional agglomerative clustering algorithms, such as the well-known linkage methods [1], usually fail to tackle these challenges. As their affinities are directly computed using pairwise distances between samples and cannot capture the global manifold structures in high-dimensional spaces, 1 The code and supplemental materials are publicly available at http://mmlab.ie.cuhk.edu.hk/research/gdl/. (a) Indegree can be use to detect the change of densities. The density in Cluster a is high, and the density in Cluster b is low. The vertices inside Cluster a are strongly connected, but there is no outedge to vertices outside Cluster a. So the indegree of k from Cluster a is nonzero, while the indegree of i (a vertex in Cluster b) and j (an outlier) from Cluster a are zero. If an undirected graph is considered without separating indegrees and outdegrees, both i and j have the same degree from Cluster a as k. (b) The product of the indegree and outdegree is an affinity measure robust to noisy edges between the two clusters. Under this measure, Cluster a and Cluster b have a zero affinity, i.e., the sum of product of indegree and outdegree for all vertices is 0, and thus they are separated well.
these algorithms have problems of clustering high-dimensional data, and are quite sensitive to noise and outliers [1].
To tackle these problems, we propose a simple and fast graph-based agglomerative clustering algorithm. The graph representation of data has been extensively exploited in various machine learning topics [2,3,4,5,6], but has rarely been utilized in agglomerative clustering. Our algorithm builds K-nearest-neighbor (K-NN) graphs using the pairwise distances between samples, since studies [4] show the effectiveness of using local neighborhood graphs to model data lying on a low-dimensional manifold embedded in a high-dimensional space.
We use the indegree and outdegree, fundamental concepts in graph theory, to characterize the affinity between two clusters. The outdegree of a vertex to a cluster measures the similarity between the vertex and the cluster. If many of the K-NNs of the vertex belong the cluster, the outdegree is large. The outdegree can capture the manifold structures in the high dimensional space. The indegree of a vertex from a cluster reflects the density near the vertex. It is effective for detecting the change of densities, which often occurs at the boundary of clusters. Therefore, we use it to separate clusters close in space but different in densities, and also reduce the effect of noise. An example is shown in Fig. 1(a). To our best knowledge, properties of the indegree and outdegree have not been explored by any existing clustering algorithm, although they were successfully applied in analysis of complex networks such as World Wide Web [9] and social networks [10] and showed interesting results. Our affinity measure between two clusters is defined as follows. First, the structural affinity from a vertex to a cluster is defined via the product of the average indegree from the cluster and average outdegree to the cluster. Intuitively, if a vertex belongs to a cluster, it should be strongly connected to the cluster, i.e., both its indegree and outdegree are large. Otherwise, either the indegree or outdegree is small. Therefore, the product of indegree and outdegree can be a good affinity measure ( Fig. 1(b)). We show that the correlation between the inter-cluster indegree and outdegree is weak across different vertices, if the two clusters belong to different ground-truth clusters, using synthetic data in Fig. 3. Then, the affinity between two clusters is naturally the aggregated affinity measure for all the vertices in the two clusters.
Our algorithm has three main advantages as follows. First of all, it has outstanding performance, especially on noisy data and multiscale data (i.e., clusters in different densities). The visual comparisons with linkage methods [1], graph-based average linkage, affinity propagation (AP) [7], spectral clustering (SC) [3], and directed graph spectral clustering (DGSC) [8] on synthetic multiscale data are shown in Fig. 2. Noise and multiple scales can degrade the performance of spectral clustering greatly [11], while the indegree and outdegree in our algorithm detect the boundary of scales automatically 2 and reduce the effect of noise. In Sec. 4, extensive experiments on real data, including imagery data and feature correspondence data, demonstrate its superiority over state-of-the-art methods. These experiments aim at two fundamental problems in computer vision, i.e., image clustering and object matching, and the results suggest many potential applications of our work.
Second, it is easy to implement. This affinity measure can be expressed in a matrix form and implemented with vector additions and inner-products. Therefore, our algorithm can be implemented without any dependency on external numerical libraries, such as eigen-decomposition which was extensively employed by many clustering algorithms [2,3,12].
Finally, it is very fast. We propose an acceleration method for our algorithm. In practice, our algorithm is much faster than spectral clustering [2,3], especially on largescale data.

Related Work
The literature dedicated to agglomerative clustering is abundant [1,13,14]. Linkages [1], e.g., average linkage, define the affinity based on pairwise distances between samples. Since pairwise distances do not well capture the global structures of data, these methods fail on clustering data with complex structures and are sensitive to noise [1] (see the example in Fig. 2). Many variants of linkage methods, such as DBSCAN [15], have been proposed in the data mining community and show satisfactory performance. However, they usually fail to tackle the great challenge from high-dimensional spaces, because their sophisticated affinity measures are based on observations from low-dimensional data [16].
Several algorithms [17,18,19] has attempted to perform agglomerative clustering on the graph representation of data. Chameleon [17] defines the cluster affinity from relative interconnectivity and relative closeness, both of which are based on a min-cut bisection of clusters. Although good performance was shown on 2D toy datasets, it suffers from high computational cost because its affinity measure is based on a min-cut algorithm. Zell [18] describes the structure of a cluster via the zeta function and defined the affinity based on the structural changes after merging. It needs to compute matrix inverse in each affinity computation, so it is much slower than our simple algorithm (see Sec. 4.1). Felzenszwalb and Huttenlocher proposed an effective algorithm for image segmentation [19].
Besides agglomerative clustering, K-means [1] and spectral clustering [2,3,20] are among the most widely used clustering algorithms. However, K-means is sensitive to the initialization and difficult to handle clusters with varying densities and sizes, or manifold shapes. Although spectral clustering can handle the manifold data well, its performance usually degrades greatly with the existence of noise and outliers, because the eigenvectors of graph Laplacian are sensitive to noisy perturbations [5]. Affinity Propagation [7] explores the intrinsic data structures by message passing among data points. Although it performs well on high-dimensional data, it usually requires considerable run-time, especially when the preference value cannot be manually set.
Directed graphs have been studied for spectral clustering (e.g., [8]). However, these methods symmetrize the directed graph before the clustering task. In contrast, we only symmetrize the affinity between two clusters, while keep the directed graph during the clustering process. Therefore, our algorithm utilizes more information from the asymmetry and is more robust to noisy edges (see Fig. 2 for a comparison between DGSC [8] and our algorithm).

Neighborhood Graph
Given a set of samples X = {x 1 , x 2 , ..., x n }, we build a directed graph G = (V, E), where V is the set of vertices corresponding to the samples in X , and E is the set of edges connecting vertices. The graph is associated with a weighted adjacency matrix W = [w ij ], where w ij is the weight of the edge from vertex i to vertex j. w ij = 0 if and only if there is no edge from i to j.
To capture the manifold structures in high-dimensional spaces, we use the K-NN graph, in which the weights are defined as where dist(i, j) is the distance between x i and x j , N K i is the set of K-nearest neighbors of x i , and σ 2 is set as K and a are free parameters to be set. In a K-NN graph, there is an edge pointing from

Algorithm Overview
The graph degree linkage (GDL) algorithm begins with a number of initial small clusters, and iteratively selects two clusters with the maximum affinity to merge. The affinities are computed on the K-NN graph, based on the indegree and outdegree of vertices in the two clusters. The initial small clusters are simply constructed as weakly connected components of a K 0 -NN graph, where the neighborhood size K 0 is small, typically as 1 or 2. Then, each component is an initial cluster, and each sample is assigned to only one cluster.

Definition 1 A connected component of an undirected graph is a maximal connected subgraph in which any two vertices are connected to each other by paths. A weakly connected component of a directed graph is a connected component of the undirected graph produced by replacing all of its directed edges with undirected edges.
The GDL algorithm is presented as Algorithm 1, with details given in the following subsection.

Affinity Measure via Product of Indegree and Outdegree
The affinity measure between two clusters is the key of an agglomerative clustering algorithm. Our affinity measure is based on indegree and outdegree in the graph representation. For simplicity, we start from measuring the affinity between a vertex and a cluster.
Indegree and outdegree. Considering a vertex and a cluster, the connectivity between them by inedges and outedges can be quantified using the concepts of indegree and outdegree.

Algorithm 1 Graph Degree Linkage (GDL)
Input: a set of n samples X = {x1, x2, · · · , xn}, and the target number of clusters nT . Build the K 0 -NN graph, and detect its weakly connected components as initial clusters. Denote the set of initial clusters as V c = {C1, · · · , Cn c }, where nc is the number of clusters. Build the K-NN graph, and get the weighted adjacency matrix W. while nc > nT do Search two clusters Ca and C b , such that {Ca, is the affinity measure between Ca and C b , computed using Eq. (5).

Definition 2 Given a vertex i, the average indegree from and the average outdegree to a cluster C is defined as deg
As we stated in Sec. 1, the indegree measures the density near sample i, and the outdegree characterizes the K-NN similarity from vertex i to cluster C. We use the size of the cluster to normalize the degrees, otherwise, the algorithm may favor of merging large clusters instead of merging small clusters with dense connections. We find that in practice the normalized degrees work much better than the unnormalized degrees.
Affinity between a vertex and a cluster. A vertex should be merged to a cluster if it is strongly connected to the cluster by both inedges and outedges. Mathematically, the correlation of two types of degree is weak, if the vertex and the cluster belong to different ground-truth clusters, and strong, otherwise. To verify this intuition, we show such statistics on synthetic data in Fig. 3. Therefore, we define the affinity as the product of the average indegree and average outdegree, i.e., This affinity is robust to noisy edges between different ground-truth clusters because the product can be zero if the inedges and outedges do not coincide. Affinity between two clusters. Following the above, we define the asymmetric affinity from cluster C b to cluster C a by summing up with respect to all the vertices in C b , i.e., Finally, we have the symmetric affinity used in our algorithm as Efficient computation of affinity. Our affinity measure can be computed efficiently using the following theorem.

Theorem 1
The affinity between C a and C b defined in Eq. (4) can be expressed in the matrix form To verify the robustness of the product of indegree and outdegree as an affinity measure from a vertex i to a cluster C, we compare statistics in two cases: i and C belong to different ground-truth clusters, e.g., i ∈ C1 and C = C2 as in (a), and i and C are in the same ground-truth cluster, e.g., i ∈ C1 and C = C1 as in (b). We see that, in the first case, the product is a quantity more robust than the indegree or outdegree. where W Ca,C b is the submatrix of W whose row indices correspond to the vertices in C a and column indices correspond to the vertices in C b , i.e., the weights of edges from C a to C b , and 1 L is an all-one vector of length L.

Remark 1 The computation is reduced to vector additions and inner-products. So, our algorithm is easy to implement.
Proof. It is easy to see that where [v] i is the i-th element of vector v. Then, by Eq. (3), we can obtain the following lemma.
Comparison to average linkage. The GDL algorithm is different from average linkage in the following three aspects. First of all, the conventional average linkage is based on pairwise distances [1]. Although we find that average linkage has much better performance on the K-NN graph than pairwise distances, we are unaware of any literature which studied the graph-based average linkage algorithm. Second, graph-based average linkage simply symmetrizes the directed graph by setting w ij = w ji = (w ij + w ji )/2, while our algorithm uses the directed graph. Third, graph-based average linkage can be interpreted as defining the affinity measure ]/2 using our indegree-outdegree framework. The sum of the indegree and outdegree is not as robust as the product of them to noise. Experimental results in Fig.  2 and Sec. 4.1 demonstrate the superiority of GDL to graph-based average linkage.

Implementations of GDL
We present two implementations of the GDL algorithm: an exact algorithm via an efficient update formula and an approximate algorithm called Accelerated GDL (AGDL). Both implementations have the time complexity of O(n 2 ) (see Theorem 3).
Update formula. In each iteration, we select two clusters C a and C b with the largest affinity and merge them as C ab = C a ∪ C b . Then, we need to update the asymmetric affinity A C ab →Cc and A Cc→C ab , for any other cluster C c .
Using Lemma 2, we find that A C ab →Cc can be computed as follows.
By storing all the asymmetric affinities, the update is simple. As the same update formula cannot be applied to A Cc→C ab , we have to compute it directly using Eq. (8). However, the total complexity is O(n) in each iteration, due to the row sparsity of W (see Sec. 7 in the supplemental materials for details).
The GDL algorithm with the update formula (GDL-U) is presented as Algorithm 2 in the supplemental materials.
Accelerated GDL. Although the GDL-U algorithm is simple and fast, we further propose AGDL. The major computational cost is on computing the affinities. To reduce the number of affinities computed in each iteration, AGDL maintains a neighbor set of size K c for each cluster in V c , to approximate its K c -nearest cluster set. Then, finding the maximum affinity among all pairs of clusters can then be approximated by searching it in all the neighbor sets. Updating the neighbor sets involves computation of the affinity between the new cluster and a small set of clusters, instead of all the other clusters.
Denote the neighbor set of a cluster C as N C . Initially N C consists of C's K c -nearest clusters. Once two clusters C a and C b are merged, we need to update the neighbor sets which include C a or C b , and create the neighbor set of C a ∪ C b . We utilize two assumptions that (1) if C a or C b is among the K c -nearest clusters of C c , C a ∪ C b is probably among the K c -nearest clusters of C c ; (2) if C c is among the K c -nearest clusters of C a or C b , C c is probably among the K c -nearest clusters of C a ∪ C b . So, the new cluster C a ∪ C b is added to the neighbor sets which include C a or C b previously. To create the neighbor set for C a ∪ C b , we select the K c -nearest clusters from N Ca ∪ N C b .
The AGDL algorithm is summarized in Algorithm 3 in the supplemental materials.

Time Complexity Analysis
We have the following theorem about the time complexity of the GDL, GDL-U and AGDL algorithms (please refer to Sec. 7 in the supplemental materials for the proof).

Experiments
In this section, we demonstrate the effectiveness of GDL and AGDL on image clustering and object matching. All the experiments are run in MATLAB on a PC with 3.20GHz CPU and 8G memory.

Image Clustering
We carry out experiments on six publicly available image benchmarks, including object image databases (COIL-20 and COIL-100), hand-written digit databases (MNIST and USPS), and facial image databases (Extended Yale-B, FRGC ver2.0). 3 For MNIST, we use all the images in the testing set. For FRGC ver2.0, we use all the facial images in the training set of experiment 4. The statistics of all the datasets are presented in Table  2. We adopt widely used features for different kinds of images: the intensities of pixels as features and Euclidean distance for object and digit images, and local binary patterns (LBP) as features and χ 2 distance for facial images. We compare the GDL-U and AGDL with eight representative algorithms, i.e., kmedoids (k-med) [1], average linkage (Link) [1], graph-based average linkage (G-Link), normalized cuts (NCuts) [2] 4 , NJW spectral clustering (NJW-SC) [3], directed graph spectral clustering (DGSC) [8], self-tuning spectral clustering (STSC) [11] and Zell [18]. Here we use k-medoids instead of k-means because it can handle the case where distances between points are not measured by Euclidean distances. To fairly compare the graph-based algorithms, we fix K = 20 and select a with the best performance from the set {10 i , i ∈ [−2 : 0.5 : 2]} on all the datasets. For our algorithms, the parameters are fixed as K 0 = 1, K c = 10. The numbers of ground-truth clusters are used as the input of all algorithms (e.g., n T in our algorithm).
We adopt the widely used Normalized Mutual Information (NMI) [12] to quantitatively evaluate the performance of clustering algorithms. The NMI quantifies the normalized statistical information shared between two distributions. A larger NMI value indicates a better clustering result.  The results measured in NMI are given in Table 1. k-medoids and average linkage perform similar, as they heavily rely on the computation of pairwise distances and thus are sensitive to noise, and cannot well capture the complex cluster structures in the real data sets. NCuts, NJW-SC, and Zell have good performance on most data sets, as they capture the underlying manifold structures of the data. STSC works fine on some synthetic multiscale datasets in [11] but its results are worse than ours on several real datasets in comparison. Note that STSC adaptively estimated the parameter σ 2 at every point to reflect the variation of local density while ours explores indgree/outdegree and fixes σ 2 as constant. The effective and robust affinity measure for agglomerative clustering makes our GDL-U and AGDL algorithm performs the best among all the algorithms. The AGDL's results are nearly the same as GDL-U.
Compared to other graph-based algorithms, GDL-U and AGDL are more robust to the parameter σ for building the graph, as well as the noise in the data (see Fig. 4). The noise added to images can degrade the performance of other algorithms greatly, but our performance is barely affected.
For the graph-based algorithms, we show their time cost in Table 2. AGDL costs the least amount of time among all the algorithms. GDL is faster than NCuts, NJW-SC, and DGSC, and is much faster than Zell. G-Link, which has worse performance than AGDL, is comparable to AGDL on time cost.

Feature Correspondence Clustering for Object Matching
We show the effectiveness of our clustering algorithm in the presence of outliers via feature correspondence clustering. Feature correspondence clustering is commonly used for robust object matching [21,14,22], which can deal with geometric distortions of objects across images and is a fundamental problem in computer vision. We demonstrate that our algorithm can be effectively integrated with the framework of feature correspondence clustering. Therefore, it has a range of potential applications, such as object recognition, image retrieval, and 3D reconstruction.
We compare with two recent state-of-the-art methods, i.e., agglomerative correspondence clustering (ACC) [14] and graph shift (GS) [22]. 5 Overview of experiments. We follow the experiments in the ACC paper [14]. We use composite images and their warped versions (Fig. 5(a)) to simulate cluttered scenes where deformable objects appear. Then we can use the ground-truth for performance evaluation. Namely, we compute the precision and recall rates of detected correspondences (Fig. 5(c)), given a set of correspondences with ground-truth ( Fig. 5(b)). A good clustering algorithm can group inliers and separate outliers. It is a more direct way of evaluating the performance of clustering algorithms than other experiments, such as object recognition. Experimental settings. We generate a pair of 3 × 3 tiled images that contain M common sub-image(s). The common sub-images are randomly selected from the model images of the ETHZ toys dataset 6 , and the non-common sub-images are from test images of the same dataset. The positions of all sub-images are randomly determined. When M > 1, the common sub-images are chosen as different objects. To simulate deformation, one of the paired images is warped using the thin-plate spline (TPS) model. An example of paired test images are shown in Fig. 5(a). 9 × 9 crossing points from a 10 × 10 meshgrid on the image are chosen as the control points of the TPS model. Then, all the control points are perturbed by Gaussian noise of N (0, σ 2 n ) independently, and the TPS warping is applied based on the perturbations of control points. To obtain the candidate correspondences between two tiled images, features are extracted by the MSER detector, and the best 3, 000 correspondences are collected according to similarity of the SIFT descriptors. Using the warping model, each correspondence has a ground-truth label: true if its error is smaller than three pixels, and false otherwise. Fig.  5(b) shows the correspondences as lines, among which the yellow ones represent true correspondences. Then, the performance of different algorithms are quantitatively eval-uated. We use the F-score, a traditional statistical measure of accuracy, which is defined as [precision · recall/(precision + recall)].
Parameters of ACC and GS. As we strictly follow the test protocol in the ACC paper [14], we use the default parameters in their codes. For GS, we compute the affinity matrix W ij = max(β − d ij /σ 2 s , 0) as the paper [22], where d ij is the distance between correspondence i and correspondence j as defined in the ACC paper [14]. β, σ s and other parameters in GS are tuned to be the best.
Parameters of AGDL. For our AGDL algorithm (i.e., Algorithm 3), the parameters are fixed as n T = 50, a = 10, K = 35, K 0 = 2, and K c = 10. We found that the GDL works well in a large range of n T , as the number of ground-truth clusters (i.e., M ) is very small and we can eliminate the outlier clusters by postprocessing. 7 Results. As shown in Fig. 6, we vary the number of outliers, the level of deformation, and the number of common sub-images, and compare the F-scores of detected correspondences by different algorithms. Both ACC and GS perform excellently on this task. It is challenging to beat them, which are very recent methods designed specifically for object matching. However, our simple clustering algorithm outperforms them. We find our AGDL algorithm performs consistently better than both ACC and GS under different settings. AGDL has a higher F-score than both in 95.6% of the random trials under all the setting combinations. We attribute the success of AGDL to the effective cluster affinity measure which is robust to noise and outliers.

Conclusion
We present a fast and effective method for agglomerative clustering on a directed graph. Our algorithm is based on indegree and outdegree, fundamental concepts in graph theory. The indegree and outdegree have been widely studied in complex networks, but have not received much attention in clustering. We analyze their roles in modeling the structures of data, and show their power via the proposed graph degree linkage algorithm. We demonstrated the superiority of this simple algorithm on image clustering and object matching. We believe our work provides not only a simple and powerful clustering algorithm to many applications in computer vision, but also an insightful analysis of the graph representation of data via indegree and outdegree.

Implementations of GDL Algorithm 2 Graph Degree Linkage with the update formula (GDL-U)
Input: a set of n samples X = {x1, x2, · · · , xn}, and the target number of clusters nT . Build the K 0 -NN graph, and detect its weakly connected components as initial clusters. Denote the set of initial clusters as V c = {C1, · · · , Cn c }, where nc is the number of clusters. Build the K-NN graph, and get the weighted adjacency matrix W. Initialize the asymmetric affinity table AC a →C b for Ca, C b ∈ V c . while nc > nT do Search two clusters Ca and C b , such that {Ca, For all Cc, compute AC ab →Cc using the update formula, i.e., Eq. (9), and AC c →C ab using Eq. (8). end while Output: V c .

Algorithm 3 Accelerated Graph Degree Linkage (AGDL)
Input: a set of n sample vectors X = {x1, x2, · · · , xn}, and the target number of clusters nT . Build the K 0 -NN graph, and detect its weakly connected components as initial clusters. Denote the set of initial clusters as V c = {C1, · · · , Cn c }, where nc is the number of clusters. Build the K-NN graph, and get the weighted adjacency matrix W. Create a neighbor set for each cluster in V c , and initialize it as the K c -nearest cluster set. while nc > nT do Search two clusters Ca and C b from the affinity of pairs of clusters associated with the neighbor sets, such that {Ca, For all Cc, such that Ca ∈ NC c or C b ∈ NC c , add C ab to NC c , and compute the affinity AC ab ,Cc ; Find the K c -nearest clusters for C ab in the set NC a ∪ NC b , to form NC ab ; Remove Ca and C b from the neighbor sets, and remove NC a and NC b . end while Output: V c .

Proof of Theorem 3
Proof. For (a), we analyze the time complexity for each part of the GDL algorithm.
(1) The directed graph construction has a complexity of at most O(Kn 2 ) (naive implementation). Note that n ≫ K, and thus we omit K in the complexities hereinafter.
(2) The complexity of constructing initial clusters is O(n), as the number of edges in the graph G is O(K 0 n), where K 0 is 1 or 2. (3) In our clustering algorithm, we use an n c × n c table to store the affinities between clusters. As the initial clusters are of small sizes, we can assume O(1) complexity for computing the affinity between each pair of two clusters. So, it requires a complexity of O(n 2 0 ) to initialize the table, where n 0 is the number of initial clusters (n 0 < n).
(4) In each iteration, it costs O(n 2 c ) to find the maximum value in the cluster affinity table. To update the cluster affinity table after merging the two clusters with maximum affinity value, we need to compute (n c − 1) affinities, and each affinity is computed with complexity of O(|C a | + |C b |) using Eq. (5) (because W is a sparse matrix with K nonzero elements in each row). Therefore, the complexity for each iteration is at most O(n c n). For (b), we can reduce the complexity in each iteration from O(n c n) in (a) to O(n). We can maintain a table to store the nearest cluster of each cluster. 8 In each iteration, finding the maximum value and updating the table cost approximately O(n c ). For the affinity table, the updating scheme of A C ab →Cc as in Eq. 9 costs O(n c ) for all the new affinities. To compute A Cc→C ab , the total complexity for all the new affinities is less than the complexity of computing W C ab , * W * ,C ab , which is O(nK), as W C ab , * is Ksparse in each row. W C ab , * is the submatrix of W whose row indices correspond to the vertices in C ab and column indices are from 1 to n.
Finally, the total complexity for GDL-U is O(n 2 ).
For (c), there are several differences in the AGDL: -In (3), we use the neighbor sets of clusters instead of the cluster affinity table. The construction of all the neighbor sets costs O(K c n 2 0 ). -In (4), we need to find the maximum affinity value in the neighbor sets (with complexity of O(K c n c ) and compute O(K c (1 + τ )) affinities to update the neighbor sets with complexity of O(K c n)). Because the size of the union of neighbor sets of C a and C b is less than 2K c ), and for real data, we can assume that the number of clusters whose neighbor set includes C a or C b is less than 2τ K c , where τ is usually a small constant close to 1. Therefore, the complexity for each iteration is at most O(n).
So, the time complexity of the AGDL algorithm is O(n 2 ).

Quantitative Results in Clustering Error for Image Clustering
The quantitative results, measured in CE [12], are given in Table 3. The CE is defined as the minimum overall error rate among all possible permutation mappings between true class labels and clusters. A smaller CE value indicates a better clustering result.

Outlier Elimination for Object Matching
For AGDL, we observe that there are many inedges and outedges inside a cluster of inliers, while less edges inside a cluster of outliers because outliers are in low density regions. Inspired by this, we define the connectivity score of a cluster C as i∈C deg − i (C) + deg + i (C) . We find that there are always large differences between the scores of inlier clusters and outlier clusters (see Fig. 7). Therefore, we rank the final clusters by their connectivity scores. Namely, we sort their scores in descending order, and then search the largest gap between two consecutive scores. The set of clusters are divided into two subsets without intersection. The subset of clusters with small scores is treated as the collection of outliers and removed. For ACC and GS, we use their default methods for outlier elimination.