Motif-based community detection in heterogeneous multilayer networks

Multilayer networks composed of intralayer edges and interlayer edges are an important type of complex networks. Considering the heterogeneity of nodes and edges, it is necessary to design more reasonable and diverse community detection methods for multilayer networks. Existing research on community detection in multilayer networks mainly focuses on multiplexing networks (where the nodes are homogeneous and the edges are heterogeneous), but few studies have focused on heterogeneous multilayer networks where both nodes and edges represent different semantics. In this paper, we studied community detection on heterogeneous multilayer networks and proposed a motif-based detection algorithm. First, the communities and motifs of multilayer networks are defined, especially the interlayer motifs. Then, the modularity of multilayer networks based on these motifs is designed, and the community structure of the multilayer network is detected by maximizing the modularity of multilayer networks. Finally, we verify the effectiveness of the detection algorithm on synthetic networks. In the experiments on synthetic networks, comparing with the classical community detection algorithms (without considering interlayer heterogeneity), the motif-based modularity community detection algorithm can obtain better results under different evaluation indexes, and we found that there exists a certain relationship between motifs and communities. In addition, the proposed algorithm is applied in the empirical network, which shows its practicability in the real world. This study provides a solution for the investigation of heterogeneous information in multilayer networks.


Related work
Current research for multilayer networks involves a variety of forms of multilayer networks, especially multirelational networks.One of these classes refers to networks in which different layers of networks represent different interactions between the same individuals (nodes in different layers may be missing and increasing, but the vast majority of nodes in different layers of networks are consistent).Take two-layer social network as an example, the nodes represent users, and the connected edges refer to the network built by two kinds of relationships (e.g., interaction, following, etc.) of these users.There is a one-to-one correspondence between the nodes in different layers of the network, but there are no substantial edges, all such networks are called multiplexed networks.
At present, many researches on community detection are based on multiplex networks, in 2019, Alimadadi et al. 40 proposed a semi-supervised joint symmetric non-negative matrix decomposition using topological information of the network as well as prior information algorithm for community detection in multilayer networks; in 2022, Venturini et al. 41 investigated multilayer networks with the same set of nodes but without interlayer contiguous edges and proposed a filter-based multi-objective optimization approach for community detection by maximizing the modularity of different layers; in 2022, Ortiz-Bouza et al. 42 proposed a multiple orthogonal nonnegative matrix TriFactorization method to achieve the detection of cross-layer communities in multilayer networks as well as unique communities on a single layer; in 2023, Roozbahani et al. 43 designed a multi-relational directed network based on a semi-supervised approach for overlapping community detection; in 2023, Cai et al. 12 proposed a graph convolution fusion model based on intralayer and interlayer information to achieve community detection for multiplexing networks.These studies are based on the topology information of the network, and some studies are based on the motif.In 2018, Pizzuti et al. 44 proposed a motif-based community detection method based on multi-objective optimization, the main idea of which is based on the number of motifs; in 2023, Li et al. 45 proposed a community detection algorithm for multiplexing networks based on motif awareness, which reduces the loss of information during network aggregation and improves the quality of community detection.
The other category refers to networks in which other interrelationships are added to the underlying relationships.In the case of two-layer networks, for example, a two-layer network with interlayer edges is constructed by introducing a third type of interaction between individuals (e.g., friendship) into the two-layer network as an interlayer edge of the network.In 2020, Contisciani et al. 46 proposed a principled probabilistic approach for community detection in multilayer networks by fusing the attributes of nodes and network structure information; in 2022, Al-sharoa et al. 3 proposed a joint non-negative matrix decomposition method for the community detection of multilayer networks by dividing the multilayer network design into a combination of multiplexing and dichotomous networks.
However, in the existing studies, there are few studies focusing on community detection in heterogeneous multilayer networks, and most of the existing studies are directed to the robustness 22,23 and cascade failure 24 of the network, and there are almost no studies on the community division of the network.We consider the design of a method for community detection for multilayer networks that are heterogeneous in terms of both nodes and edges.

Community structure of heterogeneous multilayer networks
In multiplexing networks, because the nodes in different layers represent the same individuals, community detection needs to integrate the information of all layers and obtain a unified community detection result of the multiplexing network.However, for the heterogeneous multilayer network, because the nodes at different layers are not consistent, it is necessary to combine the information of intralayer edges and interlayer edges to make the nodes at different layers get a unified division.As shown in Fig. 1a, taking two-layer networks as an example, layer L 1 and layer L 2 are two networks constructed based on the intralayer edges, a bipartite network can be constructed based on the interlayer edges.For this two-layer network, G = {G in ,G out } , where G in represents the set of intralayer networks and G out represents the set of interlayer networks.
, where L 1 and L 2 represent different layers of the multilayer network.Because the nodes of each layer in the net- work represent a type of individuals, N L 1 ( N L 2 ) is used to represent the nodes of layer L 1 ( L 2 ), E L 1 ( E L 2 ) is used to represent the intralayer edges of layer L 1 ( L 2 ), and E L 1 L 2 is used to represent the interlayer edges between layer L 1 and layer L 2 .
Next, the community structure of heterogeneous multilayer networks is described in detail.In Fig. 1a, different colors represent different communities.To community C 1 , it includes three parts: , and the joined edges between the nodes (1, 2, 6, 8, 9, 10 and 17) of the two parts.In the layer of L 1 , the nodes (1, 2, 6) in C L 1 1 are closely connected, and these nodes are more sparsely connected to nodes in C L 1 2 and C L 1 3 in L 1 .In the layer of L 2 , the nodes (8, 9, 10 and 17) in C L 2 1 are closely connected, and these nodes are more sparsely connected to nodes in C L 2 2 and C L 2 3 in L 2 .For interlayer edges, C L 1 1 and C L 2 1 belong to the same community, the edges between nodes in C L 1 1 of layer L 1 and nodes in C L 2 1 of layer L 2 are close, the edges between the nodes in C L 1 1 and the nodes in C L 2 2 or C L 2 3 are sparser, the edges between the nodes in C L 2 1 and the nodes in C L 1 2 or C L 1 3 are sparser.The same is true for the other communities ( C 2 and C 3 ).
Most of the existing studies on community detection methods for multilayer networks are based on the edge information in the network, and rarely consider the local structure (e.g., motif) that can be constructed by the edges in the network.As a special kind of multilayer network, there have been some studies proposing community detection for multiplexing networks based on motifs 38,47 , and better results have been achieved.In heterogeneous multilayer networks, due to the heterogeneity of both its nodes and edges, simply using edges for community detection of the network can not make good use of the heterogeneous characteristics of the network.Motif, as a www.nature.com/scientificreports/local network structure formed by the combination of nodes and edges, is able to interpret the heterogeneity of the network in a better way, and utilize the information of the network in a more comprehensive way.Therefore, in the next study of community detection for heterogeneous networks, we consider to do it based on motifs.

The proposed CDMMHN method
We consider designing an algorithm to break through the heterogeneity of multilayer networks and achieve the detection of community structures in multilayer networks where both nodes and edges are heterogeneous.
Because motifs can well describe the heterogeneity of edges in more general multilayer networks, this section modifies a function of motif-based modularity for multilayer networks, and proposes a community detection algorithm suitable for heterogeneous multilayer networks.

Traditional modularity function of multilayer networks
The traditional modularity function for multilayer networks targets multiplexing networks, referring to multilayer networks with consistent nodes and different edge semantics., the modularity 27 is calculated as: where, A t ij represents the adjacency matrix of the network, t represents the layer of the network, d t i represents the degree of node i in the network on layer t, m t represents the number of edges in the current layer (layer t) of the network, δ(g t i ,g t j ) determines whether node i in layer t and node j in layer t belong to the same community.If node i and node j are in the same community, δ(g t i ,g t j ) = 1 , and if node i and node j are in the different com- munity, δ(g t i ,g t j ) = 0 .π t i refers to the parent of node i, which is the node that has a relationship with node i at another layer, and in a multiplexing network, it refers to node i at another layer.δ(g t−1 π t i ,g t i ) determines whether node i in layer t and its parent node (node i in layer t − 1 ) belong to the same community.If they are in the same community, δ(g t−1 = 1 , and if they are not in the same community, δ(g t−1

Motif-based modularity function of multilayer networks
Because of the heterogeneity of edges in multilayer networks, the motif is considered to study the network structure in multilayer networks.For a heterogeneous multilayer network, the edges of the same layer are homogenous, so the motif structure in the layer is consistent with the single-layer network.However, due to the heterogeneity of the two nodes that make up the connecting edges between layers, the traditional method compresses the twolayer network and puts all edges on the single-layer network, which cannot reflect the heterogeneity of nodes in different layers and the heterogeneity of edges in the network.Therefore, we redefine the motif structure of multilayer networks with heterogeneous nodes and edges.Triangles are a more classical higher-order structure that is often used for community detection research 45,48,49 .In 2016 Benson et al. 37 proposed a variety of triangular subgraphs with orientations (only two structures, closed triangles and open triangles, are applicable to undirected networks) and experimentally demonstrated that triangular subgraphs are very important for social networks.In the study, we consider the three-node motif structure.
Motifs refers to subgraphs that have a much higher probability of occurring in a real network than in a random network, and for the three-node subgraph, the number of closed triangles occurring in the network is much higher than in a random network.Therefore, for the intra-layer motifs, we chose the structure shown in Fig. 1b.For the interlayer modal of the heterogeneous multilayer network, since the composition of closed triangles requires intra-layer edges, the interlayer motif chooses an open triangle structure, which means that both edges composing the motif are heterogeneous edges, which is able to show the heterogeneity of the edges.If the structure of Fig. 1b is chosen as the interlayer modifiers, the heterogeneity of the interlayer edges cannot be represented.The structure of the intralayer motif is shown in Fig. 1b, and the interlayer motif of the network comes in two forms, as shown in Fig. 1c,d.Because the nodes of the multilayer network are heterogeneous, nodes of different layers refer to different individuals, so the layer where the fixed node of the motif is selected has an impact on the structure of the motif.The network layer to which the fixed node belongs is different, and the motif structure is inconsistent.We take the red nodes in the figure as fixed nodes, in Fig. 1c structure 17-2-9 (or in Fig. 1d structure 2-17-1) is defined as a regular triplet.For the structure 17-2-9 in Fig. 1c, the fixed-node 17 and node 9 belong to layer L 2 and they have the same properties.The fixed-node 17 and node 2 belong to differ- ent layers and have different properties.Therefore, the connection structure that includes a fixed node, a node that is homogeneous to the fixed node, and a node that is heterogeneous to the fixed node is called the regular triplet (the structure 2-17-1 in Fig. 1d also applies).Besides, the structure consisting of nodes 5-15-7 in Fig. 1c (or structure 9-2-10 in Fig. 1d) is defined as an inverted triplet, in which the connection structure that includes a fixed node, two nodes that are heterogeneous to the fixed node.
In addition, for different fixed nodes, the number of nodes that can form regular triples and have heterogeneity with them is different.For example, in Fig. 1a, node 12 as a fixed node can form regular triplets with node 3 and node 4.Among them, there are two regular triples with node 3 (12-3-11, 12-3-13), and one regular triplet with node 4 (12-4-13).However, for any fixed node, the other two nodes which can form an inverted triple with the fixed node belong to different layers.For any node that has a different property from the fixed node, the number of inverted triples that can be formed with the fixed node is the same.For example, in Fig. 1a, node 12 as a fixed node can form inverted triples with node 3, node 4 and node 5.For any of them, the number of inverted triples that can be formed with a fixed node is 3 (3-12-4, 3-12-5, 4-12-5).Compared with the regular triple, the (1) intralayer modularity interlayer modularity www.nature.com/scientificreports/function of nodes is not discriminative, so the inverted triple is not considered in the experiment.This paper studies the community structure of multilayer networks based on the above motif structure.
In more general multilayer networks, different from the multiplexing network, the network individuals in different layers are different, there are multiple nodes in neighboring layers connected to the same node.Therefore, considering the motif can reflect the heterogeneity of the network, a calculation method of motif-based modularity for more general multilayer networks is designed.The modularity obtained based on the motif can be calculated as: where µ 1 = T t=1 i,j∈N t W t ij , µ 2 = T t=1 i∈N t w iπ t i , W t ij represents the adjacency matrix based on the number of the intralayer motif of t layer network, t represents the layer of the network, w t is the motif number of intralayer that can be formed in layer t, w t i represents the motif number of intralayer that node i can form in layer t. δ(g t i , g t j ) determines whether node i in layer t and node j in layer t belong to the same community.If so, δ(g t i , g t j ) = 1 , and if not, δ(g t i , g t j ) = 0 .π t i refers to the set of nodes in other layers that can form the motif with nodes i in t layer.δ(g t+1 determines whether node i in layer t and its parent node (the set of nodes in layer t + 1 that can form the interlayer motif with node i) belong to the same community.w iπ t i refers to the number of the interlayer motif that can be formed by node i and its parent node.For example, as shown in Fig. 1a, for node 9 in layer L 2 , nodes 2 and 5 can form regular triplets with it.For node 5, only one regular triplet can be formed.For node 2, there are two regular triplets can be formed.Set node 9 as fixed node i, for the interlayer edge(2-9), w iπ t i = 2 , for the interlayer edge(5-9), w iπ t i = 1.

Community detection algorithm by motif-based modularity for heterogeneous multilayer networks
Next, based on the modularity function of the motifs, we design a community detection algorithm for heterogeneous multilayer networks.For a multilayer network with t layers, the network structure is represented by a In the process of research, we use the two-layer network for research, and the matrix of the two-layer network can be expressed as , where A L 1 and B L 2 represent the information matrix of the intralayer structure of the network in the different layer.The number of nodes in the network at layer L 1 is n 1 , the number of nodes in the network at layer L 2 is n 2 .And there is no self-loop between nodes.The matrix C L 1 L 2 is used to represent interlayer edges of a multilayer network.Take C L 1 L 2 for example, , where c a 1 b 1 represents whether the node a 1 at layer L 1 and the node b 1 at layer L 2 have edge.If there is, c a 1 b 1 = 1 , otherwise c a 1 b 1 = 0 .On the basis of the edge matrix, the intralayer and interlayer motif in the network are cal- culated respectively, so as to obtain the network motif matrix W (the intralayer and interlayer motif with three , where W L 1 motif and W L 2 motif both represent the intralayer motif matrix.Take W L 1 motif for example, represents the intralayer motif matrix obtained from the network at layer L 1 , where, w a 1 a 2 represents the number of intralayer motif obtained from the node a 1 and the node a 2 at layer L 1 .For the interlayer network, take intralayer modularity interlayer modularity , www.nature.com/scientificreports/refers to the number matrix of interlayer motif obtained from L 1 -based network, where w L 1 a 1 b 1 refers to node a 1 in the network of layer L 1 as the fixed-node, the number of interlayer motifs that can be formed by an edge of the node a 1 in the network at layer L 1 and the node b 1 in the network at layer L 2 .W L 2 L 1 motif refers to the number matrix of interlayer motif obtained from L 2 -based network. We use motif-based modularity to detect communities in heterogeneous multilayer networks, the implementation process of the algorithm is shown in algorithm 1.Firstly, the motif matrix of the network W is obtained according to the structure matrix G.In the design, in order to improve the efficiency of the algorithm, we use the community detection algorithm for a single-layer network to divide the community of the network with fewer nodes (default n 1 < n 2 ), the community ids obtained is denoted as g L 1 , g L 2 can be obtained according to the relationship between the number of motifs among layers, but considering that there are few edges between layers, it is not possible to obtain the belonging community of all nodes in the L 2 layer.So we consider using the community detection algorithm for a single-layer network to get the initial community ids of nodes in the network of layer L 2 , integrating all community ids in the initial community g t = (g L 1 , g L 2 ) .Using the original community to calculate modularity, and then transforming the community ids of nodes, updated community id and modularity (Step6 in algorithm 1).In the process of Step7 in algorithm 1, we need to reach the final result of the conditions if the modularity reaches its maximum value or the number of communities in different layers is the same.The final output Q new and g new meet the conditions.In the process, it should be noted that the com- munity of nodes at different layers should be unified to ensure the correctness of the community results and the correlation between nodes at different layers.
Algorithm 1. Community Detection by Motif-Based Modularity for Heterogeneous Two-layer Networks.
In the processing, there are two aspects need to be noticed.First, in the iteration, the calculation of the modularity of heterogeneous multilayer networks contains two parts, intralayer modularity and interlayer modularity.The community detection of nodes in different layers can be realized by calculating the intralayer modularity, the calculation of interlayer modularity is to unify the community of nodes of different layers, to realize the integration of multilayer information.Take a two-layer network as an example, the intralayer modularity includes the modularity calculation of the layer L 1 and the modularity calculation of the layer L 2 .For the two-layer network, interlayer modularity includes modularity calculation that takes layer L 1 as the base network, changes the com- munity number of nodes in layer L 2 , and takes layer L 2 as the base network, change the community number of nodes in layer L 1 .Second, because there are few edges between layers in multilayer networks, the community ids of two nodes in different layers can be obtained in the following three ways: 1) When two nodes can form the interlayer motif, these two nodes are likely to the same community.2) When two nodes cannot form the interlayer motif, but there is an edge between them, these two nodes are likely to the same community.3) When two nodes cannot form the interlayer motif and they are not connected, the community id of the node should be obtained according to the community ids of other nodes in the layer to which the node belongs that can form the motif with it.

Experiment
In this section, the benchmark model is constructed for more general multilayer networks with community and we verify the algorithm on the multilayer networks.Besides, the evaluation index NMI and R_Inter are used to measure the accuracy of the community detection results.

Synthetic networks
Based on the relationship between the community structure and the degree of density between nodes, this paper constructs a synthetic heterogeneous two-layer network model with a community structure.The edge density www.nature.com/scientificreports/inside and outside the community within the layer as well as the effect of the specificity of fewer inter-edges on the multilayer network structure are also considered.The generation algorithm for the artificial two-layer network is shown in algorithm 2, and the network generation model is controlled by the following parameters: c,n 1 ,n 2 ,z,z 1 ,p in ,p layer , where c is the number of communities in the two-layer network, n 1 and n 2 indicates the number of nodes at different layers in the two-layer network, z represents the average degree of nodes in the whole network, z 1 represents the average interlayer degree of nodes in the network, p in represents the probability that two nodes belong to the same community, 1 − p in represents the probability that two nodes are in different communities, and p layer represents the probability that two nodes belong to the same layer.
Algorithm 2. Building a benchmark model of heterogeneous multilayer networks with community structure.
D ur ing t he exp er iment, we generate d random b enchmark net works w it h t he number of communities of 3, 4, 5 and 6, the parameter settings are as follows: a n d c = 6,n 1 = 90,n 2 = 120,p layer = 0.8 .The community to which each node belongs is fixed, and the layer to which each node belongs is determined.Once the parameter c,n 1 ,n 2 ,p layer is determined, the structure of the two-layer network only depends on the p in ,z,z 1 .
The average degree in the network includes two parts: intra-community degree (z in ) and inter-community degree (z out ) , where, z in = p in * ((n 1 + n 2 )/c − 1)/2,z out = (1 − p in ) * ((n 1 + n 2 )/c * 2)/2 , the average degree z of the network is the sum of z in and z out .The degree of interlayer includes two parts: the degree of interlayer within the community and the degree between the communities of interlayer.Among them, the degree of intralayer within the community is z in layer = p layer * ((n 1 + n 2 )/c)/2 , and the degree of interlayer within the same community is z in − z in layer ; the degree of interlayer between the communities is z out * (1 − p layer ) ; the average degree of the interlayer network (z 1 ) is the sum of the degree of interlayer within the community and the degree between the communities of interlayer.During the experiment, we also considered the different numbers of communities in different layers, and the parameters were set as c 1 = 3,c 2 = 4,n 1 = 60,n 2 = 80,p layer = 0.8 , where c 1 and c 2 represent the number of communities in different layers.
The advantage of the constructed network in this way is that we can know the community id of each node in the network, which can be compared with the partition result obtained by the algorithm, so as to www.nature.com/scientificreports/determine the effectiveness of the algorithm and the correctness of the partition result.According to the model of network construction, Fig. 2a is one of the network structure diagrams constructed when the parameters were c 1 = 3,c 2 = 3,n 1 = 60,n 2 = 90,p layer = 0.8,p in = 0.9, Fig. 2b is one of the network structure diagrams constructed when the parameters were c 1 = 3,c 2 = 4,n 1 = 60,n 2 = 80,p layer = 0.8,p in = 0.9.
To access the code and supplementary data used in this research, please contact the corresponding author.

Algorithm performance
To evaluate the accuracy of the community detection results on the synthetic networks, NMI (Normalized Mutual Information) was used to measure the results.This metric is one of the commonly used measures of partition similarity 50 , and it can measure the accuracy of community detection as a whole.NMI is calculated as follows: where, X refers to the real category.Y refers to the category obtained by clustering algorithm, and H(.) refers to the cross entropy, which is calculated as follows: . NMI is obtained by normalizing mutual infor- mation, so the range of NMI is [0,1].The more similar the two vectors are, the closer the similarity is to 1.If NMI = 1 , the result of community detection obtained by the algorithm is exactly the same as the real community IDs.
In addition, to measure the accuracy of community correspondence between individuals of different layers, we designed an evaluation index R_Inter .By comparing the community ids of individuals in different layers, an interlayer correspondence matrix C is obtained to determine whether two nodes belong to the same community.If two nodes belong to the same community, C ij = 1 , otherwise C ij = 0 .R_Inter is calculated as follows: where C ij real represents the real interlayer correspondence matrix of the network, C ij alg represents the correspondence matrix obtained by the detection algorithm, n 1 represents the number of nodes at Layer L 1 , n 2 represents the number of nodes at Layer L 2 , and R_Inter represents the ratio of correct detection in the interlayer relationship.|C ij real − C ij alg | is used to determine whether node i belonging to layer L 1 and node j belonging to layer L 2 belong to the same community is correctly identified.When |C ij real − C ij alg | = 1 , it indicateds detecting errors.There- fore, the value range of R_Inter is [0, 1].When the interlayer community correspondence is completely correct, R_Inter = 1 , when the interlayer community correspondence is completely incorrect, R_Inter = 0.
To verify the effectiveness of the community detection algorithm in multilayer networks based on motifs, we conducted experiments on synthetic networks.At the same time, to confirm the role of heterogeneity in community detection, the two-layer network was compressed into a single-layer network, in other words, all nodes (nodes in different layers) and edges (intralayer edges and interlayer edges) were input into a network.The intralayer motif in multilayer networks is regarded as the motif of a single-layer network, which is then divided based on the motif of a single-layer network.The community detection algorithm that considers heterogeneity is compared with the algorithm that does not consider heterogeneity.To avoid the specificity of the results, we Q_motif denotes the result obtained based on algorithm 1, and single denotes the result of partitioning the two- layer network by compressing it into a single-layer network without considering heterogeneity.QM_GN 36 and QM_louvain 36 denote the results obtained by other algorithms.Figure 3a,b provide a comparison of the overall network partition obtained with different probabilities of edges within the community, and Fig. 3c,d compare the community correspondence between nodes of different layers of the network under different edge connectivity probabilities within the community.As seen from the figure, the more obvious the community structure is, the more accurate the detected community structure is, and the nodes of different layers can be effectively unified when considering heterogeneity.In Fig. 3, we evaluated the accuracy of the community detection results for members of a heterogeneous multilayer network, but did not account for the accuracy of the number of communities detected by the network as a whole.Therefore, in Fig. 4, the number of communities obtained by community detection algorithms with the real number of communities are compared.The graph shows the number of communities for different probabilities of edges within a community and for different numbers of communities.In the figure, num_real represents the number of real communities in the network, Q_motif represents the number of communities detected based on Algorithm 1, num_single represents the number of communities obtained when the network is compressed to a single layer, and QM_GN and QM_louvain represent the number of communities obtained by other algorithms.As seen from the figure, with the increase in the probability of edges within a community, that is, the more obvious the community structure is, the closer the number of detected communities is to the real number of communities, and the number of communities obtained based on the algorithm is closer to the real number of communities than that obtained without considering the heterogeneity.

Relationship between the intralayer motif and community
In order to prove the validity of community detection using intra-motifs, we identify whether each fixed node in the layer belongs to the same community as the nodes that can form the maximum number of intralayer motifs The first number in the abscissa is c 1 (the number of communities at layer L 1 ), and the second number is c 2 (the number of communities at layer L 2 ).
Vol:.( 1234567890 www.nature.com/scientificreports/with it and calculate the probability that the fixed node belongs to the same community as these nodes that can form the intralayer motif with it.We randomly selected one of the networks constructed based on the following parameters: p in = 0.9,c 1 = 3,c 2 = 3,n 1 = 60,n 2 = 90,andp layer = 0.8 .The results are shown in Fig. 5a,b.The brown line shows the proportion of fixed nodes that belong to the same community as other nodes in the same network that can form more than one intralayer motif, and the red line indicates the proportion of fixed nodes that belong to the same community as the other nodes in the same network that can form the largest number intralayer motifs.As seen from the figure, in this network, the fixed node must be in the same community as the nodes that can form the intralayer motif with it, and the node that has the largest number of intra-motifs must be in the same community. In addition, we calculated the number of motifs that can be formed by nodes that belong to the same community as the fixed node and the number that are not in the same community.Taking Fig. 1a as an example, for  show the ratio in which motifs can be formed in layers L 1 and L 2 , respectively, and (c) and (d) show the number of motifs that can be formed in the same community in the same layer L 1 and L 2 , respectively, compared with the number of motifs that can be formed between the communities in the same layer.layer L 2 , the nodes that can compose the motif structure with the fixed node 11 are: 12, 14, 13, and 15.Node 11 and nodes 12, 13, and 14 are in the same community, and node 15 is not in the same community.The number of the intralayer motifs that nodes 12, 13, 14, and 15 can form is 1, 1, 3, and 1, respectively.Thus, the number of motifs that belong to the same community is 5, and the number of motifs that do not belong to the same community is 1.The statistical results are shown in Fig. 5c,d.The abscissa represents nodes, and the ordinate represents the number of motifs.The orange line is the number of motifs that can be formed within a community, and the blue line is the number of motifs that can be formed between communities.The number of motifs belonging to the same community is far greater than the number of motifs formed between nodes that are not in the same community.

Relationship between the interlayer motif and community
In order to prove the validity of community detection using inter-motifs, we calculated the formation of regular triplets.We used layer L 1 and layer L 2 as the base layer, assumed that each node in the layer was a fixed node, and then calculated the probability that the fixed node belongs to the same community as the nodes that can form the motif with it, and the probability that the nodes that have interlayer edges with the fixed node belonging to the same community.As shown in Fig. 1a, with layer L 2 as the base layer and node 9 as the fixed node, there are two nodes (2 and 5) belonging to layer L 1 and connected to fixed node 9, one of which (node 2) is in the same community as node 9. Therefore, among the nodes with which node 9 can form an interlayer edge, the probability that node 9 belongs to the same community is 0.5.Nodes 2 and 5 form the motif with node 9. Nodes 2 and 9 can form two interlayer motifs, and node 5 can form one interlayer motif.Therefore, node 9 tends to be in the same community as node 2.
In a heterogeneous multilayer network, there are few edges between layers.Therefore, we analyze the statistics of the edges between layers in the whole network, and the results are shown in Table 1.The results in the table are based on one of the networks with c 1 = c 2 = 3,n 1 = 60,n 2 = 90,p layer = 0.8,and p in = 0.9 .It can be seen that fixed nodes and nodes that can form interlayer modules with them are essentially in the same cluster, and most of the nodes with which they have interlayer edges belong to the same community.Table 2 shows the mean values of the metric ratio in Table 1, which obtained based on multiple networks, and it can be seen that this phenomenon exists in all networks.

Applications in empirical networks
Finally, the algorithm is applyed to the empirical network.For an example of scientist-research topic two-layer networks, we looked at the network surrounding HQL, an academician with the Chinese Academy of Sciences (CAS).He is mainly engaged in condensed matter theory and related computational physics research, and his main research interests include the following aspects: strongly correlated systems, quantum entanglement and quantum phase transitions, and numerical methods for many-body systems.Based on the journal data (1893-2010) provided by the American Physical Society, we collected the (1984) papers published by Haiqing Lin's collaborators as well as the PACS codes of each paper, where each PACS code corresponds to a specific research topic in physics.
Based on the above data, we constructed a collaborative network of scientists with Haiqing Lin's collaborators as nodes at the scientist level.We also constructed a co-occurrence network between the PACS codes of the papers published by these scientists at the research topic level.In the scientist collaboration network we constructed, there are 844 nodes and 146817 edges, the nodes in the network represent Haiqing Lin's collaborators, and the Table 1.Statistical analysis of interlayer edges and motif based on a network. 1 It refers to the number of objects that can be made up. 2 The number of nodes that make up the motif that belong to the same community as the consent community. 3It refers to the number of edges that exist between layers. 4It refers to the number of nodes in the same community of two nodes with edges between layers. 5  www.nature.com/scientificreports/edges represent the two scientists who have coauthored at least one APS journal paper.In the research topic co-occurrence network, which contains 78 nodes and 241 edges, the nodes in the network represent the PACS codes included in the APS journal papers published by the above scientists, and the edges represent that the two PACS codes have co-occurred at least once in the APS journal papers published by these scientists.At the same time, based on the information that a scientist has published a paper in a particular PACS code, we built an edge between the scientist layer and the research topic layer.Finally, we obtained a scientist-research topic two-layer network with heterogeneous nodes and edges.Based on algorithm 1, we performed community detection on this heterogeneous scientist collaboration network, and the whole network was divided into 4 groups, which allowed us to determine in what research areas scientists mainly collaborate with each other.
If community detection for single-layer networks is performed on the scientist cooperation network and the research topic co-occurrence network, we can determine which scientists cooperate more closely with each other and which research fields are more closely connected, but we cannot integrate the scientist groups and research fields.To fuse information about scientists and research fields on top of the above two single-layer networks, it is also necessary to add information about which papers scientists collaborated on and in which papers research fields co-occur, i.e., to construct a bipartite network between scientists and papers, and a bipartite network between research fields and papers.Our approach is able to directly relate scientists and research fields together to achieve a more rational division of scientists and their research topics.

Conclusion and future work
In this paper, the community detection algorithm of more general multilayer networks in which both nodes and edges contain heterogeneity are proposed.Among, the motif structure are used to calculate the modularity of multilayer networks, which can distinguish the intralayer and interlayer edges of networks well.We used two metrics ( NMI, R_Index ) to measure the accuracy of community detection in terms of the overall distribution of communities and the integration of communities between different layers.The results of proposed algorithm in synthetic networks showed the more accurate community structure (the number of communities and the community to which members belong), comparing with other community detection algorithms.
We applied algorithm 1 on an empirical network, which enables the problem of detecting communities uniformly between different types of individuals.Finally, this paper analyzed the relationship between the intralayer motifs (interlayer motifs) and communities and further explains the feasibility of the algorithm.
This study provides an understanding of the community structure of more general multilayer networks, and our algorithm mainly addresses the problem of community detection in undirected multilayer networks.In the following research, we hope to conduct more in-depth research in more multi-level empirical networks.Moreover, there are many unequal relationships in real networks, such as directed networks.In the future, we will conduct an in-depth study of community detection in multilayer-directed networks.

Figure 1 .
Figure 1.Community structure of heterogeneous multilayer networks.(a) represents the community structure of the multilayer network.Different colors represent different communities, which are divided into three communities ( C 1 , C 2 and C 3 ).(b) shows the structure of the intralayer motif for the network.(c) shows the structure of the interlayer motifs for the network based on layer L 2 . (d) shows the structure of the interlayer motif for the network based on layer L 1 .

Figure 2 .
Figure 2. Structure diagram of a two-layer network with a known community structure.(a) shows a two-layer network with the same numbers of communities at different layers, and (b) shows a two-layer network with different numbers of communities at different layers.

Figure 3 .
Figure 3. Performance of different detection algorithms in identifying community members.(a) and (c) depict the NMI and R_Inter values obtained based on the following parameters: p in = 0.8 and p layer = 0.8. (b) and (d) present the NMI and R_Inter values obtained based on the following parameters: p in = 0.9andp layer = 0.8 .The first number in the abscissa is c 1 (the number of communities at layer L 1 ), and the second number is c 2 (the number of communities at layer L 2 ).

Figure 4 .
Figure 4. Performance of the detection algorithm in terms of identifying the number of communities.The purple triangle represents the real number of communities in the network, the yellow circle represents the number of communities detected in the single-layer network, and the blue star represents the number of communities obtained based on Algorithm 1.The red and orange colors indicate the results obtained by other algorithms.

Figure 5 .
Figure 5. Statistical analysis of intralayer motifs and experimental results of an intralayer motif for a benchmark network with three communities.The horizontal coordinate represents each node in the corresponding network.(a) and (b) show the ratio in which motifs can be formed in layers L 1 and L 2 , respectively,and (c) and (d)show the number of motifs that can be formed in the same community in the same layer L 1 and L 2 , respectively, compared with the number of motifs that can be formed between the communities in the same layer.

Table 2 .
Statistical analysis of interlayer edges and motif of different structural networks. 1c 1