# Attention-Based Hypergraph Neural Network: A Personalized Recommendation
## 3 Proposed Method
### Heterogeneous Hypergraph and Attention Fusion
#### 3.4.2 Calculation of Attention Weights  
In heterogeneous hypergraphs, each vertex is connected to multiple hyperedges, and each hyperedge, in turn, connects multiple vertices. To capture the differences in importance between different hyperedges and vertices, attention mechanisms based on hyperedge aggregation and vertex aggregation are designed, respectively. The embedding matrices of the five different types of sub-hypergraphs and hyperedges mentioned above will be input into the attention network.  
In the algorithm framework, the attention mechanism based on hyperedge aggregation aggregates the embeddings of all hyperedges connected to a particular vertex. The weight matrix P trained in Equation (6) is used to transform the features of vertices and hyperedges. The coefficient matrix between hyperedges and vertices can be calculated using the following formula:  
\[\sigma\big{(}Z_{ij}\big{)}=\frac{e^{p^{T}(e_{j},e_{i})}}{\sum\limits_{v_{k}\in V _{i}}e^{p^{T}(e_{j},v_{k})}} \tag{12}\]  
In the above Equation (2), the terms \"\(e_{j}\)\" and \"\(v_{i}\)\" represent the connection feature vectors between the \"hyperedge and vertex\" nodes. \(P^{T}\) is the weight matrix for linear transformation, \(V_{i}\) is the set of all vertices connected to the hyperedge, \(e_{j}\) is the feature vector of hyperedge \(j\), and the feature vector of the hyperedge is \(e_{j}=\sum_{j\in V_{i}}\sigma\big{(}Z_{ij}\big{)}v_{j}\), which is the weighted sum of the feature vectors of the nodes connected to the hyperedge.  
The attention mechanism based on vertex aggregation is similar to the above hyperedge-based attention aggregation mechanism, as they share the same coefficient matrix. The feature representations of hyperedges and vertices in the other four types of hypergraphs are obtained using the same method.  
To reveal the similarity in the course lists that online learners focus on, i.e., the similarity between hyperedges with courses as vertices, if the courses that two online learners focus on have a high degree of similarity, then the list of courses they both focus on is relatively long, indicating a high-attention score between them. Otherwise, the attention score would be low. The attention scores between hyperedges are calculated using Equations (13) and (14), as follows:  
\[sim\big{(}e_{i},e_{j}\big{)}=\frac{e_{i}\cdot e_{j}}{\|e_{i}\|\|e_{j}\|} \tag{13}\]  
Equation (13) calculates the cosine similarity between hyperedge \(e_{i}\) and hyperedge \(e_{j}\). The numerator is the dot product of vector \(e_{i}\) and vector \(e_{j}\), and \(\|e_{i}\|\) and \(\|e_{i}\|\) represent the L2 norms of vectors \(e_{i}\) and \(e_{j}\), respectively. The formula for calculating the attention coefficients between hyperedges is shown in Equation (14), and the calculation method is as follows:  
\[Atten_{e_{i},e_{j}}=\frac{sim\big{(}e_{i},e_{j}\big{)}}{\max(|e_{i}|,|e_{j}|)} \tag{14}\]  
In Equation (14), \(|e_{i}|\) and \(\big{|}e_{j}|\) represent the number of vertices in hyperedge i and hyperedge j, respectively. Since two hyperedges may have different numbers of vertices, the calculation process uses the maximum number of vertices between the two to determine the attention coefficient. If there is no common list of learning courses between the two, the attention coefficient is 0, otherwise, the attention coefficient is high.