# Neighborhood Aggregation Collaborative Filtering Based on Knowledge Graph
## 3 NACF Framework
### Aggregation Process  
The aggregation of user-item pairs (\(e_{u}\),\(e_{i}\)) includes the sub-aggregation of all entities in the current neighborhood \(N_{e_{u}}^{n}\). Sub-aggregation is a single process of aggregating information from directly connected neighbors to entity. As shown in Algorithm 1, given user id \(u\) and item id \(i\), we define the \(h\)-\(th\) sub-aggregation process \(Agg\) of \(e_{j}\) as following:  
\[e_{j}^{[h]}=Agg_{(u,i)}\left(N_{e_{j}},e_{j}^{[h-1]}\right) \tag{3}\]  
where \(e_{j}\in N_{e_{u}}^{n-h}\) and \(e_{j}^{[0]}\) is initial \(e_{j}\).  
As shown in Figure 3, we use the neighboring sub-aggregation process of the \(e_{j}\) as an example to illustrate the \(Agg\) in NACF. We use \(N_{e_{j}}\) to represent the collection of entities that are directly connected to \(e_{j}\) and assume that \(N_{e_{j}}=(e_{k},e_{m},e_{l})\). \(r_{(j,k)}\) represents the relation between \(e_{j}\) and \(e_{k}\). The corresponding link relations are \(r_{(j,k)},r_{(j,m)},r_{(j,l)}\).  
First we design a attention module to assign different weights to entities in the neighbor collection, since we believe that aggregation without distinction can introduce too much noise and is unreasonable. In NACF, we consider the degrees of users' interest in different relations and the similarity between neighboring entities and recommended entity. In this way, the weights of different entities in the aggregation have been confirmed.  
The attention module for calculating the weight is shown on the right sub-picture of Figure 3. For the weight calculation of the entity \(e_{k}\), two parts of weight (\(w_{(u,r)}\) and \(w_{(e_{i},e_{k})}\)) are calculated separately in the attention module. \(w_{(u,r)}\) represents the user's attention to \(r_{(jk)}\). For example, one user may be more inclined to choose a particular singer when listening to music; another may care more about the style of the music. \(w_{(e_{i},e_{k})}\) is the similarity between the current neighbor \(e_{k}\) and the recommended item \(e_{i}\). We believe that entities with high similarity to recommended entity have a greater impact on user's choice. Finally, the weight of neighboring entities \(W_{e_{k}}^{(u,i)}\) is two-part (\(w_{(u,r)}\) and \(w_{(e_{i},e_{k})}\)) multiplication result. The process is as follows:  
\[w_{(u,r)}=Softmax\left(w_{1}\cdot\left(\text{concat}\left(e_{u},r_{(jk)}\right) \right)+b_{1}\right) \tag{4}\]  
\[w_{(e_{i},e_{k})}=Softmax\left(w_{2}\cdot\left(\text{concat}\left(e_{i},e_{k} \right)\right)+b_{2}\right) \tag{5}\]  
\[W_{k}^{(u,i)}=w_{(u,r)}\cdot w_{(e_{i},e_{k})} \tag{6}\]  
where \(w1\) and \(w2\) are trainable vectors with \((2\times d)\)-dimensions. \(b_{1}\) and \(b_{2}\) are one-dimensional trainable vectors.  
In order to integrate the neighborhood information of \(e_{j}\), we perform an cumulative operation on the weighted neighbors to generate an aggregated vector \(V_{j}\). The final step of the sub-aggregation is to calculate the mean of the original entity representation \(e_{j}^{[h-1]}\) and neighborhood representation \(V_{j}\), and update the entity representation of \(e_{j}\) to \(e_{j}^{[h]}\). The update process of \(e_{j}^{[h]}\) is as follows:  
\[V_{j}=\sum_{e_{k}\in N_{e_{j}}}W_{k}^{(u,i)}\cdot e_{k} \tag{7}\]  
\[e_{j}^{[h]}=\left(V_{j}+e_{j}^{[h-1]}\right)/2 \tag{8}\]  
In the actual knowledge graph, there may be significant differences in the number of neighbors for each entity. To facilitate more efficient batch operation of the model, we extract a fixed-size neighbor set as a sample for each entity instead of its complete neighbor set. Specifically, the real neighborhood of the entity \(e_{j}\) in the knowledge graph is \(N(e_{j})\). We set its calculation neighbor set to \(S(e_{j})\). \(S(e_{j})\) samples \(K\) neighbors from \(N(e_{j})\), and \(K\) is a hyper-parameter.  
Figure 3: Neighborhood sub-aggregation process.