Friend recommendation method based on cross-view contrastive learning in location-based social networks
By generating distance- and time-constrained meta-path instances in location-based social networks and optimizing user node embeddings using a cross-view contrastive learning approach, the sparsity and edge noise issues are addressed, improving the accuracy of friend recommendations and the robustness of the model.
Patent Information
- Application Number
- CN202411624916.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-14
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2044-11-14
Smart Images

Figure CN119557521B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of recommendation technology, and in particular relates to a friend recommendation method based on cross-view comparison learning in location-based social networks. Background Technology
[0002] Traditional friend recommendation systems rely on users' interest tags, social networks, and behavioral patterns. Location-based social networks, however, incorporate spatial and temporal dimensions into their check-in data, making recommendations more personalized and accurate. By analyzing check-in data, users' interests, travel habits, and potential social relationships can be revealed, allowing for the recommendation of potentially interesting new friends.
[0003] The success of neural network-based graph representation learning in graph analysis tasks has advanced the development of heterogeneous graph neural networks for friend recommendation. Traditional heterogeneous graph neural networks follow a semi-supervised learning paradigm; however, in practical applications, acquiring labeled data is always expensive and difficult. Therefore, self-supervised learning, exploring the inherent information hidden within the data itself, has become a promising solution for unlabeled data. Within the self-supervised learning paradigm, contrastive learning has become a highly regarded heterogeneous graph learning approach due to its remarkable achievements in computer vision and natural language processing. Currently, well-known heterogeneous graph contrastive learning methods mainly utilize meta-paths and network patterns to design contrastive views. In "Heterogeneous graph contrastive multi-view learning" (Wang, 2023), various contrastive methods are employed based on meta-paths, including intra-view and inter-view contrastives. A view is constructed for each meta-path, and contrasts are performed between two perturbation views of a meta-path-induced view, between two meta-path-induced views, and between a meta-path-induced view and its summary representation, considering only the consistency of the structural and semantic information carried by different meta-paths. The paper "Heterogeneous graph contrastive learning with metapath contexts and weighted negative samples" (Yu & Li, 2023) employs two contrastive methods: one compares a coarse-grained view constructed by aggregating metapath neighbors with a fine-grained view constructed by fusing metapath node embeddings; the other compares the coarse-grained view with clustering representations generated by clustering algorithms, considering only the complementarity of information. The paper "Self-supervised heterogeneous graph neural network with co-contrastive learning" (Wang, 2021) proposes a network pattern view in addition to the metapath view, and compares these two views. The metapath view is constructed by fusing node embeddings from metapaths, while the network pattern view is constructed by aggregating first-order neighbors from different types, considering only the consistency of information carried by different perspectives in a heterogeneous graph.
[0004] The heterogeneous graph contrastive learning methods recommended by friends currently have two main shortcomings: 1) These methods do not make good use of spatiotemporal information to handle the sparsity and edge noise of heterogeneous networks; 2) These methods only consider the consistency or complementarity of heterogeneous information, resulting in poor recommendation performance. Summary of the Invention
[0005] The purpose of this invention is to provide a friend recommendation method based on cross-view comparison learning in location social networks. This method utilizes temporal and spatial constraints to alleviate the sparsity and edge noise of location social networks, while capturing the consistency and complementarity of heterogeneous information to improve the accuracy of recommendations.
[0006] The technical solution adopted in this invention is a friend recommendation method based on cross-view comparison learning in location-based social networks, comprising the following steps:
[0007] S1. Obtain users' social media platform data and construct a location-based social network based on the social media platform data;
[0008] S2. Generate distance-constrained meta-path instances and time-constrained meta-path instances;
[0009] S3. Perform cross-view comparison on fine-grained views;
[0010] S4. Perform cross-view comparison on coarse-grained views;
[0011] S5. Calculate the final contrastive loss and train the contrastive learning model based on the final contrastive loss to optimize the user node embedding.
[0012] S6. Calculate user similarity and make friend recommendations based on user similarity.
[0013] Furthermore, in step S1, the social platform data includes user check-in data and user friend relationship data. The user check-in data includes the user, check-in time, and check-in location. The check-in location includes the location's latitude and longitude information. The friend relationship data includes the user and user-user edges that express the friend relationships between users. In the location social network, when a user checks in at a check-in location, a user-check-in location edge containing the check-in time is generated and complements the user friend relationship data.
[0014] Furthermore, in step S2, the generated distance-constrained meta-path instance is:
[0015] Calculate the distance between check-in locations:
[0016] D = distance(L) x ,L y )
[0017] In the formula, D is the distance between check-in locations, distance(·) is the distance function, and L x For location x, L y Let y be the location;
[0018] Set a distance threshold τ, where τ>0. If D≤τ, then generate a distance-constrained metapath instance; if D>τ, then do not generate one.
[0019] The time-constrained metapath example is:
[0020] Divide a 24-hour day into n time periods, denoted as {T1, T2, ..., T...}. n}, 0 <n≤24,T n For the nth time period, if the check-in time falls within a time period, the distance constraint metapath instance is retained and denoted as the time constraint metapath instance; otherwise, it is deleted.
[0021] Furthermore, in step S3, the fine-grained view includes a meta-path view, a meta-path enhanced view, a node type view, and a node type enhanced view, and also includes:
[0022] The metapath view generates user-defined node embeddings based on each metapath, as follows:
[0023] {X mp |mp∈{UUU,ULU,ULLU}}
[0024] In the formula, X mp This is the node embedding of a user based on the metapath mp in the metapath view, where mp is any metapath in the metapath set, {UUU,ULU,ULLU} is the metapath set, U is the user, and L is the location;
[0025] The meta-path enhanced view generates user-defined node embeddings based on each meta-path, as follows:
[0026] {Y mp |mp∈{UUU,ULU,ULLU}};
[0027] In the formula, Y mp Enhance the embedding of user-defined nodes based on metapath mp in the metapath-based view;
[0028] The node type view generates the node embeddings of the user based on the first-order neighbors of each meta-path, as follows:
[0029] {X nt |nt∈{U UUU ,L ULU ,L ULLU}}
[0030] In the formula, X nt For node embeddings of user-defined first-order nt type neighbors based on metapaths in the node type view, where nt is any type of the first-order neighbor in the metapath, {U UUU ,L ULU ,L ULLU} represents the set of types of first-order neighbors of the metapath;
[0031] The node type-enhanced view generates user-defined node embeddings based on first-order neighbors for each meta-path, as follows:
[0032] {Y nt |nt∈{U UUU ,L ULU ,L ULLU}}
[0033] In the formula, Y nt Enhance the node embedding of user-defined first-order nt type neighbors based on metapaths in the node type view.
[0034] Furthermore, in step S3, the cross-view comparison of the fine-grained view includes:
[0035] S31. A comparison between meta-path views, and a comparison between meta-path views and meta-path enhanced views, specifically:
[0036]
[0037] In the formula, Let log(·) be the contrast loss between the metapath view and the metapath augmentation view, and let log(·) be the logarithmic function. Intermediate parameters have no practical significance. For positive sample comparison between different meta-path views For negative sample comparison between different meta-path views For negative sample comparison within the same metapath view For positive sample comparisons between different meta-path views and enhanced views, For negative sample comparison between different meta-path views and augmented views, For negative sample comparison between the same meta-path view and the enhanced view, X i Let X be the embedding matrix of user nodes in the metapath view corresponding to the i-th metapath. j Y is the embedding matrix of user nodes in the metapath view corresponding to the j-th metapath. i The user node embedding matrix in the metapath augmented view corresponding to the i-th metapath, Y j Let u be the embedding matrix of user nodes in the enhanced view corresponding to the j-th meta-path, i be the i-th meta-path in the meta-path set, j be the j-th meta-path in the meta-path set, i ≠ j, cos(·) be the cosine similarity function, and s be the embedding matrix of user nodes in the enhanced view corresponding to the j-th meta-path. + (u) is the set of positive samples for user u, s - (u) is the set of negative samples of user u, and v is any user in the set of positive or negative samples of user u.
[0038] S32. Comparison between node type views and between node type views and node type enhanced views, specifically:
[0039]
[0040] In the formula, Contrast loss for node type views and node type augmented views. Intermediate parameters have no practical significance. For positive sample comparison between views of different node types. For negative sample comparison between views of different node types. For negative sample comparison within the same node type view. For positive sample comparisons between views of different node types and enhanced views, For negative sample comparison between views of different node types and enhanced views, For negative sample comparison between views and augmented views of the same node type, X m X is the user node embedding matrix in the node type view corresponding to the m-th type. n Y is the user node embedding matrix in the node type view corresponding to the nth type. m Y is the embedding matrix of user nodes in the enhanced view corresponding to the m-th type of node. n Let m be the embedding matrix of user nodes in the enhanced view corresponding to the nth type of node, m be the mth type in the set of first-order neighbors of the metapath, n be the nth type in the set of first-order neighbors of the metapath, and m ≠ n.
[0041] Furthermore, in step S4, the coarse-grained view includes a meta-path summary view and a node type summary view, and also includes:
[0042] In the meta-path summary view, for {X mp The node embedding representation H of the user's meta-path summary view is generated by performing a weighted summation on |mp∈{UUU,ULU,ULLU}}. smp X mp This refers to the node embedding of the user based on the metapath mp in the metapath view, where mp is any metapath in the metapath set, and {UUU,ULU,ULLU} is the metapath set.
[0043] In the node type summary view, {X nt |nt∈{U UUU ,L ULU ,L ULLU The weighted summation is performed to generate the node embedding representation H of the user's summary view based on node type. snt X ntFor node embeddings of user-defined first-order nt type neighbors based on metapaths in the node type view, where nt is any type in the set of first-order neighbor types in the metapath, {U UUU ,L ULU ,L ULLU} represents the set of types of first-order neighbors of the metapath.
[0044] Furthermore, in step S4, the cross-view comparison of the coarse-grained view includes a comparison between the meta-path summary view and the node type summary view, specifically:
[0045]
[0046] Where, L SP_ST (u) represents the comparison loss between the meta-path summary view and the node type summary view. This provides a positive sample comparison between the meta-path summary view and the node type summary view. For negative sample comparison between the meta-path summary view and the node type summary view, s + (u) is the set of positive samples for user u, s - (u) is the set of negative samples for user u, H smp H is a node embedding representation of a user's meta-path-based summary view. snt Let be the node embedding representation of the user-based node type summary view, where cos(·) is the cosine similarity function, u is the user, and v is any user in the positive and negative sample sets of user u.
[0047] Furthermore, in step S5, the final comparison loss is calculated as follows:
[0048]
[0049] In the formula, L represents the final contrastive loss, u represents a user, and User represents the set of users. The contrast loss for the metapath view and the metapath augmented view. LSP is the contrast loss for node-type views and node-type augmented views. _ST (u) represents the comparison loss between the meta-path summary view and the node type summary view.
[0050] Furthermore, in step S6, the calculation of user similarity is as follows:
[0051] Calculate the similarity between non-friend user node pairs (u, w) in the original user relationship data, where u is a user and w is any user that is not a friend of user u.
[0052] The beneficial effects of this invention are:
[0053] (1) This invention proposes a friend recommendation method based on cross-view comparison learning in location social networks. According to the first law of geography, "everything is related to everything else, but things that are nearby are more related than things that are far away." Enhanced edges between two locations (L) with a distance threshold of less than a certain distance are generated, and then meta-path instances based on ULLU (user-location-location-user) are obtained. Then, in order to capture users (U) with the same travel habits and eliminate a certain degree of edge noise, this invention uses time information to constrain the generation process of ULU (user-location-user) and ULLU meta-path instances. The generated ULU and ULLU instances capture the edge relationship between two users visiting the same and nearby locations in the same time period. The edge enhancement technology based on distance and time constraints is used to alleviate the sparsity problem of networks with spatiotemporal information and reduce noise in the network, thereby overcoming the problem of poor node embedding representation caused by the network being too sparse and complex noise.
[0054] (2) This invention considers both the consistency and complementarity of information. It designs two levels of comparison views: fine-grained views (meta-path view, meta-path augmented view, node type view, and node type augmented view) and coarse-grained views (meta-path summary view and node type summary view). When designing the comparison task, this invention uses the comparison between different fine-grained views to learn the consistent representation of nodes under different views, which is used to capture the consistency of information. It uses the comparison between two coarse-grained views to capture the complementarity of information. The two levels of comparison tasks cooperate with each other and complement each other to learn the embedded representation of nodes, thereby helping the model to better learn the representation of nodes and improve the performance and robustness of the model. Attached Figure Description
[0055] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0056] Figure 1 This is a flowchart illustrating the distance and time constraints in this invention;
[0057] Figure 2 This is a schematic diagram of the process of cross-view comparison in this invention. Detailed Implementation
[0058] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0059] This invention provides a friend recommendation method based on cross-view comparison learning in location-based social networks, comprising the following steps:
[0060] S1. Obtain social platform data of users on social platforms. The social platform data includes user check-in data and user friend relationship data. The user check-in data includes user (U), check-in time, and check-in location (L). The check-in location includes latitude and longitude information. The friend relationship data includes user (U) and user-user edges (UU) that express the friend relationship between users. Construct a location social network based on the social platform data. In the location social network, when a user checks in at a check-in location, generate an edge containing the check-in time and user-check-in location (UL), which complements the user friend relationship data.
[0061] S2. Generate distance-constrained meta-path instances and time-constrained meta-path instances;
[0062] To compensate for data sparsity, this invention utilizes the latitude and longitude information of check-in locations to calculate the distance between check-in locations. When user U1 is at check-in location L... x User U2 checked in at check-in location L. y The distance between check-in locations is as follows:
[0063] D = distance(L) x ,L y )
[0064] In the formula, D is the distance between check-in locations, and distance(·) is the distance function;
[0065] Set a distance threshold τ, where τ > 0. If D ≤ τ, then generate an enhanced distance constraint edge between user U1 and user U2, resulting in a distance constraint metapath instance U1L. x L y U2; if L x =L y Then the distance constraint metapath instance is obtained as U1L x U2, if D>τ, then do not process;
[0066] The time-constrained metapath example is:
[0067] To reduce the noise of spatio-temporal information in the location social network, the present invention further constrains the distance-constrained meta-path instances according to the user check-in time, that is, divides 24 hours of a day into n time periods, denoted as {T1, T2,..., Tn}, 0 < n ≤ 24, Tn is the nth time period. If the check-in times of user U1 and user U2 are within one time period, then retain this meta-path instance to obtain the time-constrained meta-path instance; if not, then delete it.
[0068] As Figure 1 shown, it is a schematic diagram of the process of distance and time constraints.
[0069] S3. Conduct cross-view comparison on the fine-grained views;
[0070] The fine-grained views include the meta-path view, the meta-path enhanced view, the node type view, and the node type enhanced view, and also include:
[0071] The meta-path view generates node embeddings of users based on each meta-path, that is, generates a one-hot code feature matrix for users. According to the time-constrained meta-path instances, a user adjacency matrix is generated. For each meta-path mp in the meta-path set {UUU, ULU, ULLU}, input the one-hot code feature matrix of the user and the user adjacency matrix of the time-constrained meta-path instance generated based on the meta-path mp into the graph convolutional network (GCN) encoder, and obtain the node embedding Xmp of the user based on each meta-path mp as:
[0072] {Xmp|mp∈{UUU,ULU,ULLU}}
[0073] In the formula, X mp is the node embedding of the user based on the meta-path mp in the meta-path view, mp is any meta-path in the meta-path set, {UUU, ULU, ULLU} is the meta-path set, U is the user, L is the location, UUU is the user-user-user meta-path, ULU is the user-location-user meta-path, and ULLU is the user-location-location-user meta-path.
[0074] The meta-path enhanced view generates node embeddings of users based on each meta-path, that is, performs feature masking and edge masking on the one-hot code feature matrix of the user input into the GCN encoder and the user adjacency matrix of the time-constrained meta-path instance generated based on each meta-path mp. The feature masking means randomly setting some elements in the feature matrix to zero, and the edge masking means randomly setting some elements in the adjacency matrix to zero, constructing the meta-path enhanced view, and obtaining the node embedding Ymp of the user based on each meta-path mp as:
[0075] {Ymp|mp∈{UUU,ULU,ULLU}};
[0076] In the formula, Ymp represents the user-defined node embedding based on the metapath mp in the metapath-enhanced view.
[0077] The node type view generates node embeddings of the user's first-order neighbors based on each meta-path. Specifically, it uses an attention mechanism to aggregate the user's first-order neighbors for each meta-path, constructs the node type view, and generates the node embedding Xnt for each user's first-order neighbors based on each meta-path.
[0078] {Xnt|nt∈{U UUU ,L ULU ,L ULLU}}
[0079] In the formula, Xnt is the node embedding of the user's first-order nt type neighbor based on the metapath in the node type view, and nt is any type in the type set of first-order neighbors of the metapath, {U UUU ,L ULU ,L ULLU} represents the set of types of first-order neighbors of the metapath; U UUU For the type of first-order neighbor of a user under the constraint of metapath instance UUU, L ULU For the type of first-order neighbor of a user under the metapath instance ULU constraint, L ULLU The type of the first-order neighbor of the user under the ULLU constraint of the metapath instance.
[0080] The node type augmented view generates the node embeddings of the user based on the first-order neighbors of each meta-path. This involves performing feature masking on Xnt, randomly setting some elements of Xnt to zero, and generating the node type augmented view to obtain the node embedding Ynt of the user based on the first-order neighbors of each meta-path.
[0081] {Ynt|nt∈{U UUU ,L ULU ,L ULLU}}
[0082] In the formula, Ynt is the node embedding of the user's first-order nt-type neighbor based on the metapath in the node-type enhanced view.
[0083] Fine-grained views allow for cross-view comparisons, including:
[0084] S31. Comparison between meta-path views and between meta-path enhanced views, specifically:
[0085]
[0086]
[0087] In the formula, Let log(·) be the contrast loss between the metapath view and the metapath augmentation view, and let log(·) be the logarithmic function. Intermediate parameters have no practical significance. For positive sample comparison between different meta-path views For negative sample comparison between different meta-path views For negative sample comparison within the same metapath view For positive sample comparisons between different meta-path views and enhanced views, For negative sample comparison between different meta-path views and augmented views, For negative sample comparison between the same meta-path view and the enhanced view, let Xi be the user node embedding matrix in the meta-path view corresponding to the i-th meta-path, Xj be the user node embedding matrix in the meta-path view corresponding to the j-th meta-path, Yi be the user node embedding matrix in the enhanced view corresponding to the i-th meta-path, Yj be the user node embedding matrix in the enhanced view corresponding to the j-th meta-path, u be the user, i be the i-th meta-path in the meta-path set, j be the j-th meta-path in the meta-path set, i≠j, cos(·) be the cosine similarity function, and s be the user node embedding matrix in the enhanced view corresponding to the j-th meta-path. + (u) is the set of positive samples for user u, s - (u) is the set of negative samples of user u, and v is any user in the set of positive or negative samples of user u.
[0088] S32. Comparison between node type views and between node type views and node type enhanced views, specifically:
[0089]
[0090] In the formula, Contrast loss for node type views and node type augmented views. Intermediate parameters have no practical significance. For positive sample comparison between views of different node types. For negative sample comparison between views of different node types. For negative sample comparison within the same node type view. For positive sample comparisons between views of different node types and enhanced views, For negative sample comparison between views of different node types and enhanced views, For negative sample comparison between views and augmented views of the same node type, Xm is the user node embedding matrix in the node type view corresponding to the m-th type, Xn is the user node embedding matrix in the node type view corresponding to the n-th type, Ym is the user node embedding matrix in the node type augmented view corresponding to the m-th type, Yn is the user node embedding matrix in the node type augmented view corresponding to the n-th type, m is the m-th type in the set of first-order neighbors of the meta-path, n is the n-th type in the set of first-order neighbors of the meta-path, and m≠n.
[0091] S4. Perform cross-view comparison on coarse-grained views;
[0092] Coarse-grained views include meta-path summary views and node type summary views, and also include:
[0093] In the meta-path summary view, a weighted summation of {Xmp|mp∈{UUU,ULU,ULLU}} is performed to generate the user's node embedding representation Hsmp based on the meta-path summary view. mp This refers to the node embedding based on the metapath mp in the metapath view, where mp is any metapath in the metapath set, and {UUU,ULU,ULLU} is the metapath set.
[0094] In the node type summary view, {Xnt|nt∈{U UUU ,L ULU ,L ULLU}} Perform weighted summation to generate the node embedding representation Hsnt of the user's node type summary view, where Xnt is the node embedding of the user's first-order nt type neighbors based on the metapath in the node type view, and nt is any type in the set of first-order neighbors of the metapath, {U UUU ,L ULU ,L ULLU} represents the set of types of first-order neighbors of the metapath.
[0095] Cross-view comparison of coarse-grained views includes a comparison between meta-path summary views and node type summary views, specifically:
[0096]
[0097] In the formula, LSP _ST (u) represents the comparison loss between the meta-path summary view and the node type summary view. This provides a positive sample comparison between the meta-path summary view and the node type summary view. For negative sample comparison between the meta-path summary view and the node type summary view, s + (u) is the set of positive samples for user u, s -(u) is the set of negative samples of user u, Hsmp is the node embedding representation of user based on metapath summary view, Hsnt is the node embedding representation of user based on node type summary view, cos(·) is the cosine similarity function, u is user, and v is any user in the positive and negative sample sets of user u.
[0098] like Figure 2 The diagram shown is a flowchart illustrating cross-view comparison.
[0099] S5. Calculate the final contrastive loss, train the contrastive learning model based on the final contrastive loss, and obtain the user node embedding under the optimized meta-path summary view.
[0100] The final comparative loss is:
[0101]
[0102] In the formula, L represents the final contrastive loss, u represents a user, and User represents the set of users. The contrast loss for the metapath view and the metapath augmented view. LSP is the contrast loss for node-type views and node-type augmented views. _ST (u) represents the comparison loss between the meta-path summary view and the node type summary view.
[0103] S6. Calculate user similarity and make friend recommendations based on user similarity;
[0104] This invention uses the importance λmp of each meta-path mp to measure the contribution of a meta-path. Based on the meta-path importance learned during training and the number of meta-paths traversed between user nodes, the correlation between user nodes is calculated, and sorted sampling is performed to obtain the candidate positive sample set for users, as follows:
[0105] cand + (u)={(v,t)|t=∑mpλmpInd(v∈Neimp(u))>0}
[0106] In the formula, cand + (u) is the candidate positive sample set of user u, mp is any metapath in the metapath set {UUU,ULU,ULLU}, λmp is the importance of metapath mp learned during training, Neimp(u) is the set of neighboring user nodes connected by user node u through instances of metapath mp, Ind(·) is an indicator function, which is 1 if any user node v∈Neimp(u), otherwise it is 0, and t is the degree of association between user node u and v.
[0107] Based on the degree of association t between user nodes, for cand +(u) sorts and starts from cand + (u) selects the first k user nodes v to form the positive sample set s of user u. + (u), negative sample set s - (u) = User-s + (u), where User is the set of all users.
[0108] Based on the user node embeddings under the optimized meta-path summary view, the similarity of non-friend relationship user node pairs (u, w) in the original user relationship data is calculated, where u is a user and w is any user that is not a friend of user u, and friend recommendations are made based on user similarity.
[0109] Example 1
[0110] According to the present invention, a friend recommendation method based on cross-view contrastive learning in a location-based social network includes:
[0111] S1. Obtain user's social media data. Table 1 shows user check-in data, and Table 2 shows user friend relationship data.
[0112] Table 1. User check-in data (partial)
[0113]
[0114]
[0115] Table 2. Friend Relationship Data (Partial)
[0116] user user 0 2 0 5 0 12 0 33 0 41 1 36 ... ... 2 12 ... ...
[0117] S2. Based on the latitude and longitude information of the user's check-in location, calculate the distance between the check-in locations, set the distance threshold τ = 50, and generate the distance constraint enhancement edge between the check-in locations as shown in Table 3. Then, obtain the distance constraint instances of the metapaths ULU and ULLU, as shown in Tables 4 and 5.
[0118] Table 3. Partial list of reinforced edges with distance constraints between locations.
[0119] Place Place 0 21 0 52 0 167 ... ... 1 44 ... ... 21 52 ... ...
[0120] Table 4 shows some examples of distance constraints for meta-path ULUs.
[0121]
[0122]
[0123] Table 5 shows some examples of distance constraints for ULLU (Ultra-Low Path) meta-paths.
[0124] user Sign-in time Check-in location 1 Check-in location 2 Sign-in time user 0 20:12 0 21 20:20 8 0 21:45 0 52 01:35 78 0 18:34 0 167 18:54 125 0 14:12 11 65 14:41 7 ... ... ... ... ... ... 1 11:05 50 34 15:25 86 ... ... ... ... ... ...
[0125] The distance constraint instances of metapaths ULL and ULLU are further constrained based on the user's check-in time. Specifically, a 24-hour day is divided into 12 time periods {0:00-2:00, 2:00-4:00, ..., 22:00-24:00}. Instances with check-in times within the same time period are retained, while instances with check-in times outside the same time period are deleted. This yields the time constraint instances of metapaths ULL and ULLU, as shown in Tables 6 and 7. Furthermore, an example of metapath UUU obtained from Table 2 is shown in Table 8.
[0126] Table 6. Examples of time constraints for meta-path ULUs (partial list)
[0127] user Sign-in time Place Sign-in time user 0 12:22 16 13:09 53 0 08:54 81 09:04 109 ... ... ... ... ... 1 17:01 8 16:31 29 ... ... ... ... ...
[0128] Table 7. Examples of time constraints for meta-path ULLUs (partial list)
[0129] user Sign-in time Check-in location 1 Check-in location 2 Sign-in time user 0 20:12 0 21 20:20 8 0 18:34 0 167 18:54 125 0 14:12 11 65 14:41 7 ... ... ... ... ... ...
[0130] Table 8 lists some examples of the metapath UUU.
[0131]
[0132]
[0133] S3. Perform cross-view comparison on fine-grained views.
[0134] The initial feature matrix of the user, consisting of one-hot codes, is generated, as shown in Table 9. Based on the temporal constraint instances of metapaths ULU and ULLU, and instances of metapath UUU, user adjacency matrices based on metapaths ULU, ULLU, and UUU are constructed, where the user adjacency matrix based on metapath ULLU is shown in Table 10. The initial feature matrix of the user and the user adjacency matrix based on each metapath are input into the graph convolutional network (GCN) encoder to obtain the user node embeddings {XULU, XULLU, XUUU} based on metapaths ULU, ULLU, and UUU in the metapath view.
[0135] Table 9. Initial Feature Matrix of Users (Partial)
[0136] user 0 1 0 0 0 ... 0 0 1 0 1 0 0 ... 0 0 2 0 0 1 0 ... 0 0 3 0 0 0 1 ... 0 0 … ... ... ... ... … … … 0 0 0 0 ... 1 0 0 0 0 0 ... 0 1
[0137] Table 10. User Adjacency Matrix Based on Meta-Path ULLU (Partial)
[0138] user 0 ... 7 8 ... 125 ... 0 1 ... 1 1 ... 1 ... ... ... 1 ... ... ... ... ... 7 1 ... 1 0 ... 0 ... 8 1 ... 0 1 ... 0 ... ... ... ... ... ... 1 ... ... 125 1 ... 0 0 ... 1 ... ... ... ... ... ... ... ... …
[0139] The user's initial feature matrix and some elements in the user's adjacency matrix based on each metapath are randomly set to zero and input into the graph convolutional network (GCN) encoder to obtain the node embeddings {YULU, YULLU, YUUU} of the user based on the metapaths ULU, ULLU, and UUU in the metapath-enhanced view.
[0140] An initial feature matrix consisting of latitude and longitude coordinates is generated for each check-in location, as shown in Table 11. Based on the time-constrained instances of metapaths ULU and ULLU, instances of metapath UUU, and the feature matrices of users and check-in locations, an attention mechanism is used to aggregate the features of the user's first-order neighbors based on each metapath, resulting in the node embeddings of the user in the node type view based on the first-order neighbors of metapaths ULU, ULLU, and UUU.
[0141] Table 11 Initial Feature Matrix of Check-in Locations (Partial)
[0142] Check-in location latitude longitude 0 40.09821789 116.56959598 1 40.00721934 116.31959567 2 40.76067265 116.31452362 ... ... ... 8 40.00705733 116.31778956 ... ... ... 21 40.09827235 116.56974657 ... ... ...
[0143] By randomly setting some elements in the user node embedding based on the first-order neighbors of each metapath to zero, the user node embedding based on the first-order neighbors of the metapaths ULU, ULLU, and UUU in the node type enhanced view is obtained.
[0144] The comparison is performed between the meta-path view and the meta-path enhancement view, specifically between the embeddings of user nodes based on meta-paths ULU, ULLU, and UUU (XULU, XULLU, XUUU) and the enhanced embeddings of user nodes based on meta-paths ULU, ULLU, and UUU (YULU, YULLU, YUUU), and the comparison loss is calculated. Comparing node type views and node type enhanced views, specifically embedding user nodes based on metapath ULU, ULLU, and UUU first-order neighbors. And enhanced user node embedding based on metapath ULU, ULLU, and UUU first-order neighbors. Compare between them and calculate the contrast loss.
[0145] S4. Perform cross-view comparison on coarse-grained views;
[0146] The user node embeddings {XULU, XULLU, XUUU} based on metapaths ULU, ULLU, and UUU are weighted and summed to generate user node embeddings Hsmp in the metapath summary view.
[0147] An attention mechanism is used to embed user nodes based on metapath ULU, ULLU, and UUU first-order neighbors. Perform a weighted summation to generate the user node embedding Hsnt under the node type summary view.
[0148] The comparison loss LSP is calculated by comparing the coarse-grained views, specifically the user node embeddings Hsmp under the meta-path summary view and the user node embeddings Hsnt under the node type summary view. _ST (u).
[0149] S5, compare the loss of all users LSP _ST (u) Summation yields the final contrastive loss L. Based on L, backpropagation is performed to optimize model parameters and update user embeddings in each view. This process is repeated iteratively to train the model until convergence. After model training, the optimized user node embeddings under the meta-path summary view are obtained, as shown in Table 12.
[0150] Table 12 shows the embedded user nodes (partial) in the optimized meta-path summary view.
[0151]
[0152] S6. Generate positive and negative sample sets for training the model. Based on the user adjacency matrix of meta-paths ULU, ULLU, and UUU, as well as the importance and number of instances of the meta-paths, calculate the degree of association between users, select the 5 users with the highest degree of association, generate the positive sample set of users, and randomly select 100 users from the remaining users to generate the negative sample set of users, as shown in Table 13.
[0153] Table 13: Partial Set of Positive and Negative Samples of Users
[0154]
[0155] After model training, cosine similarity between users is calculated based on the user node embeddings in the optimized metapath summary view, as shown in Table 14. Finally, the top 5 users with the highest similarity who are not friends are recommended as new friends for each user, and a partial list of recommended friends is shown in Table 15.
[0156] Table 14 Cosine Similarity Among Users (Partial)
[0157] user 0 ... 7 8 ... 30 ... 77 ... 125 ... 0 1 ... 0.8023 0.9012 ... 0.8812 ... 0.7856 ... 0.7964 ... ... ... ... ... ... ... ... ... ... ... 7 1 0.6044 ... 0.5023 ... 0.5123 ... 0.6284 ... 8 1 ... 0.7845 ... 0.5049 ... 0.6612 ... ... ... ... ... ... ... ... 30 1 ... 0.5623 ... 0.6678 ... ... ... ... ... ... 77 1 ... 0.7142 ... ... ... ... 125 1 ... ... …
[0158] Table 15: Partial List of Friend Recommendations
[0159]
[0160] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0161] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. A friend recommendation method based on cross-view comparison learning in location-based social networks, characterized in that, Includes the following steps: S1. Obtain users' social media platform data and construct a location-based social network based on the social media platform data; S2. Generate distance-constrained meta-path instances and time-constrained meta-path instances; The example of the generated distance-constrained metapath is: Calculate the distance between check-in locations: D = distance(L) x ,L y In the formula, D is the distance between check-in locations. Let L be the distance function. x For location x, L y Let y be the location; Set distance threshold Then a distance-constrained metapath instance is generated, if Then it will not be generated; The time-constrained metapath example is: Divide a 24-hour day into n time periods, represented as: If the check-in time falls within a time period, the distance constraint metapath instance is retained and recorded as a time constraint metapath instance; otherwise, it is deleted. S3. Perform cross-view comparison on fine-grained views; The fine-grained view includes a meta-path view, a meta-path enhanced view, a node type view, and a node type enhanced view; The cross-view comparison of fine-grained views includes: comparison between meta-path views, and comparison between meta-path views and meta-path enhanced views; comparison between node type views, and comparison between node type views and node type enhanced views; S4. Perform cross-view comparison on the coarse-grained view; the coarse-grained view includes the meta-path summary view and the node type summary view, and the cross-view comparison on the coarse-grained view includes the comparison of the meta-path summary view and the node type summary view. S5. Calculate the final contrastive loss and train the contrastive learning model based on the final contrastive loss to optimize the user node embedding. S6. Calculate user similarity and make friend recommendations based on user similarity.
2. The friend recommendation method based on cross-view comparison learning in a location-based social network according to claim 1, characterized in that, In step S1, the social platform data includes user check-in data and user friend relationship data. The user check-in data includes user, check-in time, and check-in location. The check-in location includes location latitude and longitude information. The friend relationship data includes users and user-user edges that express the friend relationship between users. In the location social network, when a user checks in at a check-in location, a user-check-in location edge containing the check-in time is generated and complements the user friend relationship data.
3. The friend recommendation method based on cross-view comparison learning in a location-based social network according to claim 1, characterized in that, Step S3 also includes: The metapath view generates user-defined node embeddings based on each metapath, as follows: In the formula, For users in the metapath view based on metapath Node embedding, For any metapath in the metapath set, Let U be the set of metapaths, where U represents users and L represents locations; The meta-path enhanced view generates user-defined node embeddings based on each meta-path, as follows: In the formula, Enhance the user's meta-path-based view. Node embedding; The node type view generates the node embeddings of the user based on the first-order neighbors of each meta-path, as follows: In the formula, For the first-order user-based metapath in the node type view Node embedding of type neighbors, It can be any type of the first-order neighbor of the metapath. The set of types of first-order neighbors of the metapath; The node type-enhanced view generates user-defined node embeddings based on first-order neighbors for each meta-path, as follows: Where, Enhance the user's first-order meta-path based view for node types. Node embedding of type neighbors.
4. The friend recommendation method based on cross-view comparison learning in a location-based social network according to claim 1, characterized in that, In step S3, the cross-view comparison of the fine-grained view includes: S31. A comparison between meta-path views, and a comparison between meta-path views and meta-path enhanced views, specifically: In the formula, The contrast loss for the metapath view and the metapath augmented view. It is a logarithmic function. Intermediate parameters have no practical significance. For positive sample comparison between different meta-path views For negative sample comparison between different meta-path views For negative sample comparison within the same metapath view For positive sample comparisons between different meta-path views and enhanced views, For negative sample comparison between different meta-path views and augmented views, For negative sample comparison between the same meta-path view and the enhanced view, The embedding matrix of user nodes in the metapath view corresponding to each metapath. The user node embedding matrix in the metapath view corresponding to the metapath. The embedding matrix of user nodes in the meta-path augmented view corresponding to each meta-path. The embedding matrix of user nodes in the meta-path augmented view corresponding to each meta-path. For users, The first in the metapath set Path of a single element The first in the metapath set Path of a single element It is the cosine similarity function. For users The set of positive samples For users The negative sample set, For users Any user in either the positive or negative sample set; S32. Comparison between node type views and between node type views and node type enhanced views, specifically: Where, Contrast loss for node type views and node type augmented views. Intermediate parameters have no practical significance. For positive sample comparison between views of different node types. For negative sample comparison between views of different node types. For negative sample comparison within the same node type view. For positive sample comparisons between views of different node types and enhanced views, For negative sample comparison between views of different node types and enhanced views, For negative sample comparison between views and enhanced views of the same node type, User node embedding matrix in the node type view corresponding to each type. For the User node embedding matrix in the node type view corresponding to each type. The user node embedding matrix in the enhanced view corresponding to the node type. For the The user node embedding matrix in the enhanced view corresponding to the node type. The first-order neighbor of the metapath is the type set of the first-order neighbors. Types, The first-order neighbor of the metapath is the type set of the first-order neighbors. Types, .
5. The friend recommendation method based on cross-view comparison learning in a location-based social network according to claim 1, characterized in that, Step S4 also includes: In the meta path summary view Perform weighted summation to generate a node embedding representation of the user's meta-path summary view. For users in the metapath view based on metapath Node embedding, For any metapath in the metapath set, For the set of metapaths; In the node type summary view Perform weighted summation to generate a node embedding representation of the user's summary view based on node type. For the first-order user-based metapath in the node type view Node embedding of type neighbors, For any type in the set of types of first-order neighbors of the metapath It is the set of types of first-order neighbors of the metapath.
6. The friend recommendation method based on cross-view comparison learning in a location-based social network according to claim 1, characterized in that, In step S4, the cross-view comparison of the coarse-grained view includes a comparison between the meta-path summary view and the node type summary view, specifically: In the formula, The loss is compared between the meta-path summary view and the node type summary view. This provides a positive sample comparison between the meta-path summary view and the node type summary view. This provides a negative sample comparison between the meta-path summary view and the node type summary view. For users The set of positive samples For users The negative sample set, For users, a node embedding representation based on the meta-path summary view. For users, a node embedding representation of a summary view based on node type is provided. It is the cosine similarity function. For users, For users Any user in the set of positive and negative samples.
7. The friend recommendation method based on cross-view comparison learning in a location-based social network according to claim 1, characterized in that, In step S5, the final comparison loss is calculated as follows: Where, For the final comparison of losses, For users, For a collection of users, The contrast loss for the metapath view and the metapath augmented view. Contrast loss for node type views and node type augmented views. Comparison loss between metapath summary view and node type summary view.
8. The friend recommendation method based on cross-view comparison learning in a location-based social network according to claim 1, characterized in that, In step S6, the calculation of user similarity is as follows: Calculate the pairs of user nodes that are not friends in the original user relationship data. similarity, For users, In order to connect with users Any user who is not a friend.
Citation Information
Patent Citations
Friend recommendation method and device, equipment and storage medium
CN114579879A
Graph neural network recommendation method and system based on social preference
CN118171738A