BiLouvain Method
BiLouvain Method
Physica A
journal homepage: www.elsevier.com/locate/physa
highlights
article info a b s t r a c t
Article history: Community structure is a common and important feature in many complex networks,
Received 29 March 2017 including bipartite networks, which are used as a standard model for many empirical
Received in revised form 15 June 2017 networks comprised of two types of nodes. In this paper, we propose a two-stage method
Available online 21 November 2017
for detecting community structure in bipartite networks. Firstly, we extend the widely-
Keywords:
used Louvain algorithm to bipartite networks. The effectiveness and efficiency of the
Community detection Louvain algorithm have been proved by many applications. However, there lacks a Louvain-
Bipartite networks like algorithm specially modified for bipartite networks. Based on bipartite modularity, a
Modularity optimization measure that extends unipartite modularity and that quantifies the strength of partitions in
Agglomerative clustering bipartite networks, we fill the gap by developing the Bi-Louvain algorithm that iteratively
groups the nodes in each part by turns. This algorithm in bipartite networks often produces
a balanced network structure with equal numbers of two types of nodes. Secondly, for
the balanced network yielded by the first algorithm, we use an agglomerative clustering
method to further cluster the network. We demonstrate that the calculation of the gain
of modularity of each aggregation, and the operation of joining two communities can be
compactly calculated by matrix operations for all pairs of communities simultaneously. At
last, a complete hierarchical community structure is unfolded. We apply our method to two
benchmark data sets and a large-scale data set from an e-commerce company, showing that
it effectively identifies community structure in bipartite networks.
© 2017 Elsevier B.V. All rights reserved.
1. Introduction
Network representation is the foundation for the studies of a large amount of very important problems. A seemingly
common feature discovered among numerous empirical networks is community structure, which represents the clustering
of network nodes with densely distributed edges within groups but sparser connections between them [1]. Community
*
Corresponding author at: Center for Intelligent and Networked Systems (CFINS), Department of Automation, Tsinghua University, Beijing 100084,
China.
E-mail addresses: [email protected] (C. Zhou), [email protected] (Q. Zhao).
https://doi.org/10.1016/j.physa.2017.11.089
0378-4371/© 2017 Elsevier B.V. All rights reserved.
1680 C. Zhou et al. / Physica A 492 (2018) 1679–1693
structure not only reveals coarse-grained connections in networks, but also plays important roles in the functioning of
networks [2,3].
Several community detection algorithms are developed to properly identify community structure. A good partition
produces optimal or near-optimal values of some criteria, and possibly, reveals hierarchical organization of community
structure under different resolutions. Traditionally, graph partitioning and hierarchical clustering algorithms, such as
agglomerative algorithms and their divisive counterparts, are implemented to solve the problem of community detection [1].
Since Newman and Girvan introduced the definition of modularity [4], it rapidly becomes a popular criterion that measures
the quality of partitions. Modularity reflects the proportion of edges formed within communities, relative to the proportion
of edges formed between communities. The authors defined a null model, which persists the degree of nodes, to measure the
randomness of edges formed between nodes. Since a high value of modularity indicates a good partition, maximizing this
criterion by optimization techniques has been a popular topic during the last decade [5–10]. However, it is intractable to find
the exact optimal solution to the problem. Hence, lots of approximate algorithms are developed. Among these algorithms, the
greedy approach introduced by Blondel et al. [11] (the so-called Louvain algorithm) has been proved to be among the most
efficient algorithms with excellent performances. The Louvain algorithm consists of two steps. In the first step, modularity
is optimized locally in the neighborhood of each node. After this step, it aggregates the nodes in the same communities
into supernodes and forms a new coarse-grained network. The procedures are iteratively performed in more and more
concentrated networks until the value of modularity does not increase by any movement of node in the network. Although
modularity-based methods and the Louvain algorithm do have some limitations [12,13], they are still widely used to analyze
large-scale real-world problems.
A particular and ubiquitous class of networks is bipartite networks, in which nodes are divided into two disjoint classes
and edges are only allowed to connect different classes of nodes. Bipartite networks are the natural models for many real-
world systems, such as people attending events, authorship of scientific papers, consumer buying products, etc. Community
structure in bipartite networks not only reveals the extent to which nodes in one part are related to nodes in the other
part, but also clusters similar nodes within the same part into groups. In order to discover community structure in bipartite
networks, a particular modularity measure for bipartite networks was proposed by Barber [14], and several algorithms are
developed, such as BRIM [14], label propagation [15–17], etc.
The Louvain algorithm for unipartite networks performs well under lots of situations, and it has been implemented
by several popular software packages to deal with large-scale community detection problems. However, it seems rare
that existing algorithms for bipartite community detection adopt the idea of the Louvain algorithm. We believe that the
challenges are two-fold. Firstly, the identities of nodes will not be retained if nodes in different parts are aggregated into
supernodes, which is the consequences if we directly perform the first step of the unipartite Louvain algorithm. For instance,
it makes sense that several consumers are aggregated into a group of consumers with similar purchasing behavior, however,
the identity of a supernode comprised of both consumers and products seems ambiguous. Secondly, a modified Louvain
tailored for bipartite networks often produces balanced bipartite networks, which is not suitable for some applications due
to resolution problems.
In view of these challenges, we develop a new community detection method for bipartite networks. Our algorithm
consists of two stages. At first, we derive the formula of the gain of bipartite modularity. Based on the formula, we carry
out a Louvain-like algorithm to cluster the nodes in one part and therefore, the size of the part is reduced to a smaller level.
Then the algorithm is carried out in the other part. The procedure is performed iteratively between the two parts by turns.
And the size of the network is unceasingly reduced until the original unbalanced bipartite network becomes balanced. At
this moment, a single community contains only one (super-)node in each part, and the value of modularity will not increase
any more by moving any nodes into any communities. Our algorithm then moves to the second stage. We perform an
agglomerative clustering algorithm to iteratively combine a pair of balanced communities hierarchically. We demonstrate
that the calculation of the gain of modularity of each aggregation, and the operation of joining two communities can be
compactly calculated by matrix operations for all pairs of communities simultaneously. At last, a complete hierarchical
community structure is unfolded. We can choose a partition with the highest modularity or with a proper number of
communities for applications. We test our method by several standard benchmark data sets. In addition, in order to reveal
similarities of purchasing behaviors among users, we apply our method to a large-scale data set from an e-commerce
company. The results show that our method effectively identifies community structure in bipartite networks.
2. Method
In this section, we first review the computation of the gain of unipartite modularity when moving a node into a
community, which is the key principle of local optimization of modularity. Then we introduce the computation of the gain
of bipartite modularity and a novel algorithm, which we call Bi-Louvain, that optimizes bipartite modularity using a local
searching heuristic. At last, we discuss the balanced community structure produced by our algorithm, and we propose an
agglomerative clustering method to further optimize bipartite modularity.
A network is commonly modeled mathematically as a graph. For simplicity, we discuss only unweighted graphs in this
paper. Our method can be easily extended to weighted graphs. Consider a simple, unweighted network G with n nodes and
C. Zhou et al. / Physica A 492 (2018) 1679–1693 1681
where Aij is the ijth element of the adjacency matrix of G , ki is the degree of node i, ci represents the community to which
i is assigned, and the function δ (u, v ) is 1 if u = v and 0 otherwise. It measures the fraction of edges within communities
minus the expectation of the same value if each edge is randomly positioned between two nodes according to a probability
proportional to both degrees of the two nodes. This probabilistic generation of a network is often referred as the null model.
A high value of modularity implies a strong community structure. It is widely accepted that a modularity value higher than
0.3 indicates significant community structure.
The term∑ Aij δ (ci , cj ) in Eq. (1) indicates the ijth edge inside the community ∑where node i and j are located. And the
summation i,j is over all pairs of nodes (both ijth and jith). Hence, ∑ the term i,j Aij δ (ci , cj ) indicates the double of the
sum of the number of edges inside all communities. Similarly, the term i,j ki kj δ (ci , cj ) indicates the sum of the square of the
degrees of all nodes inside all communities. Hence, modularity can be re-wrote as
(Φ tot )2
[ ]
1 ∑
Q = Φcin − c (2)
2m 2m
c ∈C
Φcin ( Φ tot )2
c
( k )2
i
Qsep = − − (4)
2m 2m 2m
The first two terms in Eq. (4) indicate the modularity of community c. The term 0 − (ki /(2m))2 is the modularity of the
single-node community formed by node i. Then the gain of modularity ∆Q can be calculated as follows
ki,in 2ki Φctot
∆Q = Qcomb − Qsep = − (5)
m (2m)2
The computation of ∆Q is repeated for each community to which the neighbors of node i belong. And node i will be
placed into the community with the maximum gain of modularity, but only if the gain is positive. This local optimization
procedure is in part the reason for the efficiency of the Louvain algorithm.
The Louvain algorithm is a heuristic method that locally optimizes unipartite modularity. The algorithm is divided into
an assignment step and an aggregation step. Initially, every node is treated as a single community. In the assignment step,
the gain of modularity is evaluated for moving a node from its original community into one of its neighbors community. This
evaluation is carried out for every neighbor of the node, and the node is then placed in the community with the maximum
positive gain. The above procedure will be repeated for every node with possibly multiple loops, until no movement around
neighborhood will improve modularity anymore. In the aggregation step, the nodes in the same community are merged into
a single supernode. Then a coarse-grained new network emerges. Edges between communities are added up to form new
edges between supernodes. Edges within the same communities lead to self-loops of supernodes. Then the first step will be
carried out again with the new network. The above two steps are iterated until a maximal modularity is attained.
The algorithm gradually aggregates networks from fine to coarse scales. Hence, it unfolds a complete hierarchical
community structure. The algorithm offers a compromise between the optimal modularity and computational efficiency.
The Louvain algorithm has been proved to have excellent performance and efficiency [19].
1682 C. Zhou et al. / Physica A 492 (2018) 1679–1693
The development of the Louvain algorithm is built upon the definition of unipartite modularity, which offers the easy
computation of the gain of modularity. The gain of bipartite modularity can also be easily computed according to Barber’s
bipartite modularity. Therefore, a Louvain-like algorithm can also be proposed for community detection in bipartite networks
in much the same fashion. To our best knowledge, however, similar idea has not been thoroughly investigated so far.
A bipartite graph H is a graph in which the set of nodes can be partitioned into two disjoint subsets X and Y so that every
edge is only allowed to join one node in X and the other one in Y . By convention, nodes are separated by two colors, say red
and blue, to represent the sets they belong to. Suppose H consists of p red nodes and q blue nodes, the (p + q) × (p + q)
adjacency matrix of H can be expressed as the following off-diagonal form
[ ]
Op×p Bp×q
A(p+q)×(p+q) =
BTq×p Oq×q
where O represents a block matrix with all its elements equal to zero. Block matrix B, known as the bipartite adjacency,
indicates the connections between red nodes and blue ones. It is a p × q matrix defined as B := (Bij ), where Bij is 1 if there
is an edge joining node∑ i ∈ X and node∑ j ∈ Y , or 0 otherwise. B contains all the information of the connections in a bipartite
q p
network.
∑ We ∑use d i = j Bij and gj = i Bij to represent the degree of node i ∈ X and node j ∈ Y , respectively. It is obvious
that i di = g
j j .
Commonly used definitions of community structure in bipartite networks are ill-suited [20], since that nodes of the same
type are more likely to be clustered together under existing assortativity-based definitions of community structure [21].
In addition, the resulting community structure based on one-mode projection of bipartite graphs has been demonstrated
unreliable or incorrect [22]. However, Barber [14] proposed a definition of modularity tailored to bipartite graphs, to evaluate
the goodness of partitioning both types of nodes into communities simultaneously. In this study, communities are detected
by optimizing Barber’s definition of bipartite modularity.
Specific constraints should be considered in the definition of bipartite modularity, such as the fact that nodes of the
same type are not allowed to be connected. Barber [14] redefined the null model based on bipartite adjacency matrix B of a
network. The bipartite modularity of a partition is defined as
p q
1 ∑ ∑( di gj )
Q = Bij − δ (ri , sj ) (6)
m m
i=1 j=1
where di is the degree of the ith red node, gj is the degree of the jth blue node, and ri , sj represent the communities to which
node i and j are assigned. This definition is reasonable for bipartite networks since it precludes edges between the nodes of
the same color, and the null model retains the bipartite structure.
Now we show the computation of the gain of bipartite modularity when an isolated node i is moved into community c.
Without loss of generality, we consider moving an isolated red node into a community. The gain of moving a blue node can
be obtained by symmetry. We first re-write Eq. (6) according to the transformation from Eq. (1) to Eq. (2). By the sum over
all communities, Eq. (6) is equivalent to
Ψcr · Ψcb
( )
1 ∑
Q = Ψcin − (7)
m m
c ∈C
where Ψcin represents the number of all the edges inside community c. Note that, compared to Φcin in Eq. (2), there is no
need to double the sum of edges here. Ψcr and Ψcb represent the sum of the degrees of all red nodes and all blue nodes in
community c, respectively. If an isolated red node i and a community c are regarded as a single community, the combined
modularity is
Ψcin + kbi,in (Ψcr + ki ) · Ψcb
Qcomb = −
m m2
where kbi,in represents the number of all the edges between the red node i and all the blue nodes in community c. The
modularity of the trivial community comprised of the single red node i is 0, since both Ψcin and Ψcb are 0. Hence, the modularity
when c and i are separated is
Ψcin Ψcr · Ψcb
Qsep = −
m m2
Hence, ∆Q can be obtained by
kbi,in ki · Ψcb
∆Q = Qcomb − Qsep = − (8)
m m2
C. Zhou et al. / Physica A 492 (2018) 1679–1693 1683
Fig. 1. Visualization of the assignment and aggregation steps of the Bi-Louvain algorithm. (a) Each node constitutes a single-node community initially,
and the algorithm is carried out in the larger part at first. (b) Each node in the right part will be assigned to a community. Communities are indicated by
different colors. (c) Then the right part is aggregated to a smaller scale according to community assignment. Now the left part becomes the larger one. (d)
The above procedures will be carried out again in the left part. (e) At last, a network with balanced community structure emerges. (For interpretation of
the references to color in this figure legend, the reader is referred to the web version of this article.)
The gain of modularity when an isolated blue node is moved into a community can be derived in a similar way. In addition,
the gain of modularity for moving a node out from its original community c0 into a new community c1 can be decomposed
into the gain of moving the node into c1 minus the gain of moving it into c0 .
The computation of the gain of modularity for moving a red/blue node is repeated for each community to which the
blue/red neighbors of the node belong. And the node will be placed into the community with the maximal gain, but only if
this gain is positive. The above procedure allows us to develop a Louvain-like algorithm for community detection in bipartite
networks.
We now introduce the so-called Bi-Louvain algorithm that optimizes bipartite modularity in a greedy manner to discover
community structure in bipartite networks.
Recall that the unipartite Louvain algorithm is divided into an assignment step and an aggregation step. And the two
steps are iterated until convergence. Our Bi-Louvain algorithm is divided into four steps. At first, an assignment step and
an aggregation step are performed for the red part, and then for the blue part. These steps are repeated iteratively until
convergence. The assignment step is similar to that in the unipartite Louvain, except that the gain of modularity is computed
according to the definition of bipartite modularity, and that the neighbors of a node are of the opposite color. In the
aggregation step, only the nodes in the same community and of the same color are merged together. The aggregation in
a part shrinks the size (number of nodes) of the part into a level equivalent to or smaller than that of the other part. After the
execution of the two steps in the larger part, it becomes the smaller one. We formalize the above statement by a conjecture.
Conjecture 1. After applying Bi-Louvain algorithm in the larger part of a bipartite network, the larger part will become the smaller
one.
We provide a theoretical analysis of Conjecture 1 in Appendix A. Our algorithm guarantees that the statement is true. Then
the two steps continue in the other part (the currently larger one). Hence, the two steps are always carried out in the larger
part. As a consequence, the size of each part is unceasingly compressed by turns. And therefore a hierarchical community
structure will be unfolded. The steps in one iteration of the Bi-Louvain algorithm are visualized in Fig. 1.
We discuss the details of the assignment and the aggregation steps. Suppose the red part is larger. In the assignment step,
the algorithm computes the gain of bipartite modularity, according to Eq. (8), when a red node is moved out from its original
community into the community in which one of its blue neighbors lies. The gain is computed for all distinct communities
in which its neighbors lie. Then this red node is moved into the community with the largest positive gain temporarily. This
procedure will be looped for all red nodes until bipartite modularity cannot be increased by any movement. Now every red
node has been assigned into a community, while the communities of blue nodes remain unchanged.
In the aggregation step, what the algorithm does is very simple. Since the assignment procedure only changes the
communities of red nodes, our algorithm just aggregates the red nodes in the same communities into red supernodes. Since
that there are no edges between the nodes of the same color, the aggregated supernodes have no self-loops. The edges
incident to the red nodes in the same community are also aggregated into a single weighted edge. The red supernodes
1684 C. Zhou et al. / Physica A 492 (2018) 1679–1693
Fig. 2. Combination of two balanced communities into a single one. k1 , k2 , d1 , d2 are the degrees of corresponding nodes. w1 , w2 , v1 , v2 are the weights of
corresponding edges.
combined with the blue nodes consist of a new coarse-grained bipartite network. And now the two-step procedure will be
carried out in the blue part. Note that the total number of communities assigned to the red nodes is equal to or less than the
number of the blue nodes. Hence, after the aggregation step, the larger part has been reduced to a level that is very likely to
be smaller than the size of the smaller part. Now the smaller part becomes the larger one and the larger part becomes the
smaller one, and the next iteration of our algorithm begins.
The assignment and the aggregation procedures in the blue part is symmetric to those in the red part. The algorithm stops
when no single movement will increase bipartite modularity any more. The pseudocode of Bi-Louvain algorithm is provided
in Appendix B.
In the Bi-Louvain algorithm, the reason that the size of one part can be further reduced into a smaller level is that the
size of this part is larger than that of the other. Once that the size of the red part is equal to the size of the blue part after
an iteration, every red node has been assigned to a community with only its corresponding blue counterpart, and a one–
one mapping community structure appears. This balanced community structure consists of equal number of red nodes and
blue nodes in the final aggregated network. In practice, our algorithm may produce balanced bipartite networks with too
many communities, which is still impractical in some real-world applications due to this resolution issue. At this point, our
local optimization algorithm for maximizing bipartite modularity gets caught in local maxima, which means any movement
among the neighborhood of a node cannot improve the value of bipartite modularity. If the size of the network is very large, it
is very much possible that the number of balanced community is very large. Therefore, we cannot obtain a fully compressed
structure with an enough small number of communities. To deal with this problem, we use a hierarchical clustering method
to further aggregate balanced communities.
Newman [6] proposed a fast method for community detection based on hierarchical clustering of the nodes in networks.
Similar to the method, our clustering procedures also run in an agglomerative manner to tackle our resolution issue. We
iteratively combine two communities into a single one until the number of communities reaches a pre-set number, or the
whole network is aggregated into a single trivial community. During one iteration, the gain of modularity for combining
every pair of balanced communities is computed. The two communities with the largest gain are chosen to merge together.
By aggregating the nodes with the same colors, two communities comprised of four nodes are merged into one community
of two nodes.
Specifically, in each step, the modularity gain for combining two communities is computed as follows. Note that each
community consists of one red node and one blue node when the network becomes balanced. Combining two communities
corresponds to combining two pairs of nodes. As shown in Fig. 2, we use different shapes to distinguish the types of nodes,
and use different colors to indicate the communities they belong to. k1 , k2 , d1 , d2 are the degrees of corresponding nodes. w1 ,
w2 , v1 , v2 are the weights of corresponding edges. When two pairs of nodes, i.e. two original communities are considered as
a single large community, the modularity can be obtained according to Eq. (8) as
[ ]
1 (k1 + k2 )(d1 + d2 )
Qcomb = w1 + w2 + v1 + v2 −
m m
When they are considered as two separate communities, the modularity is
[ ]
1 ( k1 d1 ) ( k2 d2 )
Qsep = w1 − + w2 −
m m m
Hence, the gain of modularity when combining two communities can be obtained by
( )
1 k1 d2 + k2 d1
∆Qagg = Qcomb − Qsep = v1 + v2 − (9)
m m
The computation of modularity gain when combining two communities is quite simple. And it can be more efficient by
using some high-performance sparse matrix techniques [23]. More details on the implementation of matrix operations will
C. Zhou et al. / Physica A 492 (2018) 1679–1693 1685
Fig. 3. Joining a pair of communities by matrix operations. Communities i and j are joined together by adding the ith and jth rows as a single row, and the
ith and jth columns as a single column of matrix R. The dimension of the matrix is reduced from N × N to (N − 1) × (N − 1).
be introduced in the next section. Once the gains are computed for all pairs of communities, the pair with the largest gain
is eventually combined into a single one at current step. The combination of two communities can also be implemented by
some row and column operations of matrices, which will be introduced later.
For the balanced community structure produced by the Bi-Louvain algorithm, the above agglomerative clustering method
further yields a multi-scale community structure. The optimization of bipartite modularity by this method is not confined
around the neighborhoods of nodes. Now we are allowed to obtain a community partition of a bipartite network with a
desired scale. And the goodness of the partition is guaranteed by the unceasingly optimized bipartite modularity.
3. Implementation details
In this section, we first introduce a matrix-based implementation of the agglomerative clustering algorithm for balanced
community structure. The implementation allows us to speed up the clustering algorithm based on sparse matrix techniques.
In addition, we analyze the computational complexity of our Bi-Louvain algorithm and the agglomerative clustering
algorithm for balanced communities.
In the worst case, the computation of ∆Qagg is repeated for every pair of communities in the balanced bipartite network.
The computation cost limits the application of the algorithm to large-scale problems. Here we introduce a method based
on matrix operations in order to obtain the modularity gains of joining two communities for all pairs simultaneously. These
gains are originally computed one by one according to Eq. (9).
Let R denote the matrix that represents the connections between the red part and the blue part when the original bipartite
network H becomes balanced. Let N denote the number of communities when balanced bipartite network appears, which
also means that there are N red supernodes and N blue ones. The element Rij of RN ×N represents the weight of the edge
between the ith red node and the jth blue node. Rii is the weight of edge within community i. Hence, the degrees of all red
nodes and blue ones can be represented by vector d and g respectively as follows
d = R · e = (d1 , d2 , . . . , dN )T
g = RT · e = (g1 , g2 , . . . , gN )T
where e = (1, 1, . . . , 1)T is a column vector with all its elements equal to 1 and with a proper dimension. Let S denote the
similarity matrix whose element Sij is the modularity gain of joining community i and j, where i ̸ = j. S can be obtained
according to Eq. (9) as
1( d · g T + g · dT )
S= R + RT − (10)
m m
Similarity matrix S is clearly symmetric. The elements on the diagonal of S are trivial. In practice, in order to locate the pair
of communities with the maximal gain, we can set the diagonal elements to negative infinity. According to Eq. (10), we are
allowed to obtain the modularity gains for all pairs of communities simultaneously.
Suppose the subscripts of the largest element of S at current step are i and j. It means that community i and j are about
to be joined together as a single one. Since Sij = Sji , without loss of generality, we assume that i < j. After the joining,
the N × N dimension matrix R becomes a (N − 1) × (N − 1) matrix R′ . Since that the red nodes in community i and j are
joined as a single red node, the edges incident to the original two red nodes are now incident to a single one. To achieve
this, we can just add the ith and jth rows of R as a single row. For the blue part, the ith and jth columns are added together
as a single column. Hence, the joining of two communities is equivalent to adding the corresponding rows and columns in
matrix R. Fig. 3 illustrates the operations. After one such manipulation, the dimension of matrix R will be decreased by one.
This procedure will be performed iteratively to matrix R until it shrinks to a proper dimension.
The main advantage of the matrix form implementation for computing ∆Qagg and joining selected communities is that,
when the balanced network structure is sparse, we are allowed to use several specialized techniques for manipulating sparse
1686 C. Zhou et al. / Physica A 492 (2018) 1679–1693
matrices to improve the efficiency of our algorithm. Since these techniques are not the main focus of the present paper, the
details of the techniques will not be discussed here. The operations of sparse matrices are already embedded as standard
toolkits in several mainstream programming languages. We adopt an off-the-shelf package in Python in the implementation
of our algorithm.
Many experiments suggest that the unipartite Louvain algorithm is essentially linear in the number of edges on typical and
sparse data. This efficiency benefits from local optimal searching and the easy computation of modularity gain. By comparing
Eq. (8) to Eq. (5), the complexity of computing unipartite modularity gain and bipartite modularity gain is the same. In
addition, compared with random iterations over all nodes in the unipartite Louvain, our Bi-Louvain algorithm randomly
iterates over red nodes and then blue nodes successively, which does not increase computation complexity either. And our
following experiments will show that the number of communities decrease drastically after the first a few iterations.
Agglomerative clustering procedure begins when balanced bipartite networks appear. The computation of ∆Qagg is with
constant time complexity. During each iteration, the computation will be repeated for every pair of balanced communities
which are connected. The computation of ∆Qagg takes worst-case time O(N 2 ) in each iteration. If the connection between
communities is sparse, which means the number of connected communities M approximately equals cN where c ≪ N,
the time complexity of the computation in each iteration is then O(N). Combining two communities takes worst-case time
O(N). And there are at most N − 1 community join operations. Hence, the agglomerative clustering algorithm runs in time
O(N 3 ) for densely connected communities, or O(N 2 ) for a sparse community structure. Note that N, the number of balanced
communities, is much less than the number of nodes in the original network.
4. Results
In this section, we report several experimental results about community detection in bipartite networks produced by
our two-stage method. Our method is applied to a network showing the participation of people in social events, and to a
network showing the interlocks among firms in Scotland. These two data sets are recognized as benchmarks for testing the
performance of community detection methods in bipartite networks. And they are both public available.
The Southern Women data set, collected by Davis et al. [24] in the American South during the 1930s, shows the
interactions among 18 women met in 14 informal social events. The initial purpose of the study is to examine the
correspondence between social class and informal contacts. Since that the data is embedded with a natural bipartite network
structure, and that it is small, it has been much well studied by network scientists. The network is connected and unweighted.
We identify community structure in the Southern Women data set using our Bi-Louvain algorithm at first. Since that the
results produced by Louvain-like algorithms depend on the order of nodes during each iteration, we randomize the order
and repeat the experiment several times for a relatively good result. Then 5 communities are identified, which are shown
in Fig. 4 with different colors indicating different communities. This partition yields a bipartite modularity of Q = 0.31978.
The nodes representing women and the nodes representing events co-exist in each community, which means the aggregated
bipartite network structure is balanced. Then our agglomerative clustering algorithm is performed on the balanced network.
The results show that, if we join together the yellow and the blue communities shown in Fig. 4, the bipartite modularity will
be increased by ∆Qagg = 0.00454. And further combination of any two communities will not increase Q any more. At last,
we obtain a modularity of Q = 0.32433 with four communities. Compared to several existing results shown in Table 1, this
quality is indeed not the highest, as Barber reported a partition with its modularity equals to 0.34554 yielded by the BRIM
algorithm [14]. However, our result outperforms the results produced by other methods, such as the spectral bipartition
method, the original community assignment by Davis, the divisions suggested by Doreian et al. [25] and the partition found
by using unipartite projection. The result reported by Liu and Murata [17] with their LP&BRIM algorithm is 0.32117, which
is slightly lower than our result. In view of the wide applications of the Louvain algorithm, which we use for reference, our
algorithm yields a comparably good partition.
This data set shows a network of the corporate interlocks in Scotland during 1904–1905. The network contains 136
multiple directors of 108 joint stock companies. There is an unweighted link between a person and a company if the
person sits on the corporate board of the company. However, this bipartite network is not connected. We extract the largest
connected component, which consists of 131 directors and 86 companies. The community detection method will only be
applied to the largest subnetwork.
Since the order of nodes in each iteration has been randomized, and the size of the above network is small, our Bi-
Louvain algorithm is repeatedly carried out in this network for 1000 times. The largest modularity found by our algorithm
is Q = 0.55385. And the corresponding partition contains 58 communities, as shown in Fig. 5. Round nodes represent
C. Zhou et al. / Physica A 492 (2018) 1679–1693 1687
Fig. 4. Communities detected by our two-stage method in the Southern Women data set. 5 communities are identified by the Bi-Louvain algorithm at first
with a maximal bipartite modularity. Then the yellow and the blue communities are joined together to produce a higher modularity, which is 0.32433. (For
interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.)
Table 1
Comparison of values of modularity in the Southern Women network.
Reference Method Maximal modularity
Ours Bi-Louvain 0.32433
BRIM 0.34554
Spectral 0.32117
Davis 1 0.31057
Barbera
Davis 2 0.31839
Doreian 0.29390
Unipartite 0.21866
Liu & Muratab LP & BRIM 0.32117
a
These 6 values of modularity are reported by Barber in Table I of his paper
[14].
b
This value is reported by Liu and Murata [17].
Fig. 5. Communities detected by our Bi-Louvain algorithm in the Scotland Corporate Interlocks network. Two types of nodes are differentiated by two
shapes. Different communities are represented by different colors. The light-colored number beside each cluster corresponds to the community represented
by the same number in Fig. 6. (For interpretation of the references to color in this figure legend, the reader is referred to the web version of this article.)
directors, and square nodes represent companies. Different colors indicate different communities. In Barber’s paper, the
modularities yielded by the BRIM algorithm with two different initialization strategies are 0.56634 and 0.39873, respectively.
The above comparison shows that the partition found by using our Bi-Louvain algorithm seems to be comparable to the
1688 C. Zhou et al. / Physica A 492 (2018) 1679–1693
Fig. 6. Dendrogram for agglomerative clustering of balanced communities in Scotland Corporate Interlocks network. Two communities are joined together
in each step.
Fig. 7. Bipartite modularity variation in the Scotland Corporate Interlocks network. Each point indicates the combination of two balanced communities.
As the communities are gradually joined, bipartite modularity increases at first, and then decreases rapidly. The red vertical line indicates that, when the
number of communities decreases to 13, the maximum value of modularity (Q = 0.69298) appears.
partitions found by BRIM. However, Barber claimed that, in contrast to the results yielded by BRIM with a third initialization
strategy, the above two results are poor solutions. The author adopted a method that varies the allowed maximum number
of communities during repeated experiments, to search for the partition with the largest modularity. Better partitions are
found by the third method. Recall that our agglomerative clustering algorithm further improves the quality of a balanced
partition by iteratively joining communities together. Compared with Barber’s third method, our method also varies the
number of the final communities, but in a gradually decreasing way within just one run.
By applying the agglomerative clustering algorithm to the balanced network yielded by the Bi-Louvain algorithm in
the Scotland Corporate Interlocks network, bipartite modularity varies after each combination of two communities. The
dendrogram, that shows the order and the position of each combination of two communities, is shown in Fig. 6. And
the variation of bipartite modularity resulted from each combination in Fig. 6 is shown in Fig. 7. As the communities are
gradually joined, bipartite modularity increases at first, and then decreases rapidly during the last a few joining operations.
The red vertical line indicates that, when the number of communities decreases to 13, the maximum value of modularity
(Q = 0.69298) appears. By comparison, Barber found roughly 20 communities with the highest modularity around Q = 0.67
by the BRIM algorithm.
In addition, Barber and Clark [16] investigated label-propagation algorithm (LPA) and its variants for identifying
community structure. LPA is an efficient community detection algorithm introduced by Raghavan et al. [15]. The variants of
LPA investigated in [16] include LPAb, a label-propagation algorithm for bipartite modularity; LPAr, LPA with additional
randomization when selecting labels; and Hybrid, an algorithm consisting of standard LPA followed by a modularity-
specialized LPA. The resulting maximal values of bipartite modularity found in the Scotland Corporate Interlocks network by
LPA and its variants, as well as by our Bi-Louvain algorithm and the BRIM algorithm mentioned above, are listed in Table 2.
Our Bi-Louvain algorithm yields the largest value of bipartite modularity among these methods. Although Zhan et al. [26]
reported that their MAGA algorithm, a method based on adaptive genetic algorithm, yields a partition with the maximal
modularity equals to 0.7093 in the Scotland Corporate Interlocks network, we believe that our method is more intuitive and
our result is comparable to the result in [26] for this data set. By comparisons, the partition discovered by our two-stage
method in this data set is of very high quality.
C. Zhou et al. / Physica A 492 (2018) 1679–1693 1689
Table 2
Comparison of values of maximal modularity in the Scotland Corporate In-
terlocks network.
Reference Method Maximal modularity
Ours Bi-Louvain 0.6930
Barbera BRIM ≈0.67
LPA 0.5782
LPAb 0.5783
Barber & Clarkb
LPAr 0.6552
Hybrid 0.5975
a
This value is reported by Barber [14]. There is no exact value of the maximal
modularity. We estimate it from the plot of Fig. 3 in the original paper.
b
These 4 values of modularity are reported by Barber and Clark in Table V of
his paper [16].
Fig. 8. Bipartite modularity variation in the dominant subnetwork extracted from the bipartite network of users and products. Each point indicates the
combination of two balanced communities. As the communities are gradually joined, bipartite modularity increases at first, and then decreases rapidly.
To further demonstrate the significance of our bipartite community detection algorithm in real world applications, we
adopt our algorithm to discover the similarities among online purchasing behaviors.
For this study, we obtain a large-scale data set from one of the largest e-commerce companies in China. The data set
contains the details about the orders placed by about 0.35 million online users during one year. The products purchased by
these users are organized by a three-level taxonomy, which is adopted to facilitate users to browse and search products. Each
first-level category can be further broken down into several second-level categories, and each second-level category can be
broken down into several third-level categories too. For each user Ui and each third-level category Vj (the most fine-grained
level), wij , which denotes the amount of products that Ui has purchased in category Vj during the one-year period, is recorded.
In order to discover the similarities of purchasing behavior among these online consumers, we first use a bipartite network
structure to represent the buyer–product relationship between users and the third-level categories. And then perform our
two-stage algorithm to co-cluster users and third-level categories into communities with similar purchasing inclinations.
One part of the bipartite network consists of 354,322 users, and the other part consists of 2938 third-level categories. The
weight of the edge in the bipartite network is represented by wij . The established network is connected.
Then our Bi-Louvain algorithm is carried out in this network. And 67 communities are discovered when the network
becomes balanced. The bipartite modularity Q is 0.36984 at this moment. We find that there is a dominant community
that contains almost 2/3 of the users and more than 3/4 of the categories in the bipartite network. We therefore extract
this core community as a subnetwork for further investigation. This subnetwork consists of 226,979 users and 2231 third-
level categories. We carry out Bi-Louvain algorithm in this subnetwork and discovered 1024 communities. There are no
overwhelmingly large communities found in this subnetwork. Then the agglomerative hierarchical clustering algorithm is
carried out for the balanced network. The change of bipartite modularity during the combinations of communities is shown
in Fig. 8. When the number of communities shrinks to 14, the maximum value of bipartite modularity, which is 0.37686
indicated by the red vertical line in Fig. 8, is achieved.
To verify the effectiveness of the partition with maximal value of bipartite modularity, we examine the nodes contained
in each community. At first, we count the number of users in each community. Some trivial communities with few users
will be ignored during subsequent investigations. We then select 8 communities with distinct concentrations of first-level
categories, and analyze the third-level categories contained in them.
1690 C. Zhou et al. / Physica A 492 (2018) 1679–1693
Fig. 9. The top 5 largest µ and their corresponding first-level categories in each of the 8 communities.
A good community partition will cluster the consumers with similar purchasing inclinations into the same groups, and
those with different inclinations into different groups. Hence, the effectiveness of our partition can be validated by probing
the level of concentration in each community, in terms of the homogeneity of products. Fortunately, existing taxonomy of
products provides a reliable way to measure the similarity between two different products. Products in different first-level
categories are quite different in their natural properties. Hence, we investigate the distribution of third-level categories in
the selected 8 communities for each first-level category. For first-level community i, let Ni denote the number of third-level
categories that i contains. Let nic denote the number of third-level categories contained in community c under first-level
category i. The ratio nic /Ni reflect the level of concentration of i in different communities. However, there are huge differences
in the volume of sales for different third-level categories. The differences may depend on market demand, price, production
capacity, etc. For example, generally speaking, the volume of sales of Chinese distilled spirits and beers are higher than wines
in China. We therefore use the volume of sales of a third-level category j under i, denoted as sij , to represent the importance
or popularity of the category j. Then the ratio for each first-level category i and each community c is calculated as
∑
j∈c sij
µic = ∑N (11)
i
j=1 sij
The denominator of Eq. (11) is the total volume of sales of first-level category i, and the numerator is the sum of sales of the
third-level categories of i contained in community c. The ratio µ indicates the weighted level of concentration of first-level
categories in different communities.
We plot the top 5 largest µ for each of the 8 communities in Fig. 9. The red horizontal line indicates µ = 0.8, which is a
relatively high level of concentration. If a µic of first-level category i in community c is very close to 1, it means that c covers
almost all the volume of sales of the first-level category i. For example, the third sub-figure in Fig. 9 indicates that almost all
C. Zhou et al. / Physica A 492 (2018) 1679–1693 1691
the events of buying cell phones are clustered in the third community. Several first-level categories are highly concentrated
in their corresponding communities.
In addition, it is noteworthy that by grouping similar purchasing behaviors, our community partition correctly classifies
first-level categories into groups in terms of the natural properties of these categories. For example, the first community
mainly reflects the inclination of buying housewares, and the third and fifth communities mainly reflect the inclination
of buying electronic and digital products. There is only one first-level category with its µ higher than 0.8 in the last
6 communities. It means that, in each of these 6 communities, the purchasing inclination of the users grouped in the
community can be simply represented by the corresponding first-level category with the highest µ. For example, the users
who grouped in the seventh community have an obvious tendency of buying home appliances. These users focus on only a
few particular categories.
The above results demonstrate that our community partition in this purchasing data set is, to some extent, reasonable and
interpretable. The results could provide useful information for targeted recommendations and intelligent marketing. This
experiment using large-scale real-world data further demonstrates the effectiveness of our two-step community detection
algorithm in bipartite networks.
5. Conclusion
We propose a novel community detection method in bipartite networks in this paper. Our original motivation is to extend
the widely-used Louvain algorithm to investigate community structure in bipartite networks. The Louvain algorithm uses
local moving heuristic to unfold a complete hierarchical community structure in networks. Many research works and real-
world applications demonstrate the efficiency and effectiveness of the algorithm. However, the Louvain algorithm is not
specially designed for finding communities in bipartite networks. In this paper, we first derive the formula of the gain of
bipartite modularity when moving a node into a community where the neighbors of the node lies. Then we propose the
so-called Bi-Louvain algorithm. During each iteration, the algorithm can be divided into a community assignment step and
an aggregation step in one part of a network, and the same two steps in the other part. The algorithm is always carried out in
the larger part, and shrinks the size of the part into a smaller scale. These steps are iteratively repeated and the two parts of
the network take turns decreasing their sizes. At last, a balanced bipartite network appears. In order to further optimize
modularity and obtain a complete hierarchical community structure, we use an agglomerative hierarchical clustering
method to iteratively join two balanced communities in a greedy manner. Finally, we obtain a complete hierarchical
community structure in bipartite networks. In real world applications, one can extract a partition of a network according to
a pre-set scale or the value of bipartite modularity, which indicates the goodness of the partition. Our algorithm is carried
out in two standard, public available benchmark data sets. The results are comparable to several common methods. We also
use our method to discover the similarities among online purchasing behaviors. The results show that the partition yielded
by our method correctly classifies consumers by their purchasing inclinations.
Our method is intuitive. The computations of the gain of bipartite modularity and the operations of matrices are easy to
implement. The heuristics can be used for many real-world applications, such as document clustering, consumer clustering,
designing community-based recommendation systems, etc. The proposed method could shed some light on the problem of
community detection in complex networks.
In the future, we plan to adopt the theory of Laplacian dynamics [27] to analyze the stability of the community structure
yielded by our method. We also plan to employ our method in designing community-based recommendation systems.
Acknowledgments
This work is supported by National Natural Science Foundation of China under Grant No. 61425027, Key R&D Project
of China under Grant No. 2016YFB0901901, 2017YFC0704100, the 111 International CollaborationProgram of China under
Grant B06002, and in part by the Special Fund of Suzhou-Tsinghua Innovation Leading Action under Project 2016SZ0202,
and Innovation Joint Research Center for Cyber-Physical-Society System.
Empirically, after applying the assignment and aggregation steps to the larger part of a bipartite network, the larger part
will become the smaller one. We now perform a theoretical analysis of the empirical finding by adopting the process of
mathematical proof of contradiction.
To raise a contradiction, we assume that after applying our Bi-Louvain algorithm in the previous larger part, it will still
be the larger one at present. Without loss of generality, we assume that after an iteration in the red part, the red part is still
the larger one and the blue part is the smaller one. Suppose there are Nr red nodes and Nb blue nodes (Nr > Nb ) after the
iteration.
At this point, any local movement of the red node cannot increase modularity Q . Since that the red nodes assigned in a
same cluster will be aggregated into a single red supernode, considering Nr > Nb , there at least exists an isolated red node,
1692 C. Zhou et al. / Physica A 492 (2018) 1679–1693
which has not been assigned to any blue node during the assignment step. Suppose the isolated red node is i. If node i will
not be assigned to any blue node, according to the computation of ∆Q in Eq. (8), we have
where m is the total number of edges in the bipartite network, kbi,in represents the number of edges between red node i and
the community in which blue node b is placed, Ψcb represents the sum of the degrees of all blue nodes in community c. By
the summation over b, we have
Nb
∑
(m · kbi,in − ki · Ψcb ) = m · ki − ki · m = 0 (A.2)
b=1
If Eq. (A.2) holds, we have m · kbi,in = ki · Ψcb hold for every b in {1, 2, . . . , Nb }. Hence,
kbi,in ki
= = const . (A.3)
Ψcb m
holds for every b in {1, 2, . . . , Nb }. This is a very extreme situation. One particular example is a complete bipartite graph with
equal weights on the edges after an iteration. However, for the isolated node i, if we assign node i into a randomly selected
community when ∆Qb = 0 for every b ∈ {1, 2, . . . , Nb } appears, the situation that Nr > Nb and that described by Eq. (A.3)
will not happen. Therefore, by adding this operation, our algorithm guarantees that the larger part will become the smaller
one after applying the assignment and aggregation steps.
References
[1] M. Girvan, M.E. Newman, Community structure in social and biological networks, Proc. Natl. Acad. Sci. 99 (12) (2002) 7821–7826.
[2] S. Fortunato, Community detection in graphs, Phys. Rep. 486 (3) (2010) 75–174.
[3] J. Shang, L. Liu, X. Li, F. Xie, C. Wu, Epidemic spreading on complex networks with overlapping and non-overlapping community structure, Physica A
419 (2015) 171–182.
[4] M.E. Newman, M. Girvan, Finding and evaluating community structure in networks, Phys. Rev. E 69 (2) (2004) 026113.
[5] A. Clauset, M.E. Newman, C. Moore, Finding community structure in very large networks, Phys. Rev. E 70 (6) (2004) 066111.
[6] M.E.J. Newman, Fast algorithm for detecting community structure in networks, Phys. Rev. E 69 (2004) 066133. http://dx.doi.org/10.1103/PhysRevE.
69.066133.
C. Zhou et al. / Physica A 492 (2018) 1679–1693 1693
[7] M.E. Newman, Finding community structure in networks using the eigenvectors of matrices, Phys. Rev. E 74 (3) (2006) 036104.
[8] M.E. Newman, Modularity and community structure in networks, Proc. Natl. Acad. Sci. 103 (23) (2006) 8577–8582.
[9] B.H. Good, Y.-A. de Montjoye, A. Clauset, Performance of modularity maximization in practical contexts, Phys. Rev. E 81 (4) (2010) 046106.
[10] J. Shang, L. Liu, X. Li, F. Xie, C. Wu, Targeted revision: A learning-based approach for incremental community detection in dynamic networks, Physica
A 443 (2016) 70–85.
[11] V.D. Blondel, J.-L. Guillaume, R. Lambiotte, E. Lefebvre, Fast unfolding of communities in large networks, J. Stat. Mech.: Theory Exp. 2008 (10) (2008)
P10008.
[12] A. Lancichinetti, S. Fortunato, Limits of modularity maximization in community detection, Phys. Rev. E 84 (6) (2011) 066122.
[13] K.R. Žalik, B. Žalik, A local multiresolution algorithm for detecting communities of unbalanced structures, Physica A 407 (2014) 380–393.
[14] M.J. Barber, Modularity and community detection in bipartite networks, Phys. Rev. E 76 (6) (2007) 066102.
[15] U.N. Raghavan, R. Albert, S. Kumara, Near linear time algorithm to detect community structures in large-scale networks, Phys. Rev. E 76 (3) (2007)
036106.
[16] M.J. Barber, J.W. Clark, Detecting network communities by propagating labels under constraints, Phys. Rev. E 80 (2) (2009) 026129.
[17] X. Liu, T. Murata, Community detection in large-scale bipartite networks, Inform Media Technol. 5 (1) (2010) 184–192.
[18] F. Radicchi, C. Castellano, F. Cecconi, V. Loreto, D. Parisi, Defining and identifying communities in networks, Proc. Natl. Acad. Sci. 101 (9) (2004) 2658–
2663.
[19] A. Lancichinetti, S. Fortunato, Community detection algorithms: A comparative analysis, Phys. Rev. E 80 (5) (2009) 056117.
[20] D.B. Larremore, A. Clauset, A.Z. Jacobs, Efficiently inferring community structure in bipartite networks, Phys. Rev. E 90 (2014) 012805. http://dx.doi.
org/10.1103/PhysRevE.90.012805.
[21] M.E.J. Newman, Mixing patterns in networks, Phys. Rev. E 67 (2003) 026126. http://dx.doi.org/10.1103/PhysRevE.67.026126.
[22] R. Guimerà, M. Sales-Pardo, L.A.N. Amaral, Module identification in bipartite and directed networks, Phys. Rev. E 76 (2007) 036102. http://dx.doi.org/
10.1103/PhysRevE.76.036102.
[23] J.R. Bunch, D.J. Rose, Sparse Matrix Computations, Academic Press, 2014.
[24] A. Davis, B.B. Gardner, M.R. Gardner, W.L. Warner, Deep South: A Sociological Anthropological Study of Caste and Class, University of Chicago Press,
1941.
[25] P. Doreian, V. Batagelj, A. Ferligoj, Generalized blockmodeling of two-mode network data, Social Netw. 26 (1) (2004) 29–53.
[26] W. Zhan, Z. Zhang, J. Guan, S. Zhou, Evolutionary method for finding communities in bipartite networks, Phys. Rev. E 83 (6) (2011) 066120.
[27] J.-C. Delvenne, S.N. Yaliraki, M. Barahona, Stability of graph communities across time scales, Proc. Natl. Acad. Sci. 107 (29) (2010) 12755–12760.