# Heterogeneous Graph Structure Learning for Next Point-of-Interest Recommendation
## 4 Heterogeneous Graph Structure Learning Model
### Heterogeneous Graph Contrastive Learning
#### 4.2.3 Heterogeneous Graph Contrastive Learning  
To further enhance the quality of the representation vectors obtained by the graph encoders, this paper employs graph contrastive learning to align the representation vectors from different subgraphs. The goal of graph representation learning is to align the node representation vectors, with the core idea being that similar samples are brought closer together, while dissimilar samples are pushed further apart. To incorporate information from various aspects, this paper adopts two methods of contrastive learning:  
1. Meta-path-based Contrastive Learning  
The meta-path-based contrastive learning is mainly to align the representation vectors of users and POIs under meta-path subgraphs. The representation vectors used in this part are \(\mathrm{E}_{u1}\), \(\mathrm{E}_{u2}\), \(\mathrm{E}_{p1}\) and \(\mathrm{E}_{p2}\). Take the loss function of users as an example. We use the representations \(\mathrm{E}_{u1}\) and \(\mathrm{E}_{u2}\) from different meta-paths and the InfoNCE loss function to align the two representations and maximize the mutual information between them. The specific calculation method is as follows:  
\[L_{u1}\ =\ \sum_{u\in U}-log\frac{exp\big{(}sim\big{(}e_{u}^{1},e_{u}^{2}\big{)} /\tau\big{)}}{\sum_{u^{\prime}\in U}exp\big{(}sim\big{(}e_{u}^{1},e_{u^{\prime} }^{2}\big{)}/\tau\big{)}} \tag{5}\]  
where e\({}_{u}^{1}\) and e\({}_{u}^{2}\) are the representations of the same user \(u\) under two meta-path subgraphs, e\({}_{u^{\prime}}^{1}\) is the representation for another user \(u^{\prime}\), \(sim\) is the cosine similarity, and \(\tau\) represents the temperature coefficient, which can be used to control the model's ability to distinguish between different negative samples. In this paper, the representations of the same user under different subgraphs are considered positive samples and should be as similar as possible. Conversely, the representations of different users are considered negative samples and should be as dissimilar as possible. The goal of the contrastive learning in the meta-path subgraphs is to align the node representations under different relations. Based on this method, we can obtain the \(L_{p1}\) for E\({}_{p1}\) and E\({}_{p2}\):  
\[L_{p1}=\ \sum_{p\in U}-log\frac{exp\big{(}sim\big{(}e_{p}^{1},e_{p}^{2}\big{)} /\tau\big{)}}{\sum_{p^{\prime}\in P}exp\big{(}sim\big{(}e_{p}^{1},e_{p^{\prime }}^{2}\big{)}/\tau\big{)}} \tag{6}\]  
(2) Interaction-Aware Contrastive Learning  
Based on four meta-path subgraphs and the interaction graph, the interaction-aware contrastive learning takes into account the interaction graph between users and POIs. Take the calculation of user contrastive loss as an example. Before calculating the contrastive loss, we first integrate the representation vectors from the meta-path subgraphs with those from the heterogeneous interaction graph to obtain the user representation vectors. The integration method is as follows:  
\[\text{E}_{u01}=\text{E}_{u1}\bigoplus\text{E}_{u0},\text{E}_{u02}=\text{E}_{u2 }\bigoplus\text{E}_{u0} \tag{7}\]  
where E\({}_{u1}\) and E\({}_{u2}\) are the results of the meta-path subgraph coding, E\({}_{u0}\) is the representations of users obtained from the interaction graph, \(\bigoplus\) is average pooling, E\({}_{u01}\) and E\({}_{u02}\) are the results of the fusion between the representations of meta-path subgraphs and the representations obtained from the heterogeneous graph.