# Prototypical Graph Contrastive Learning for Recommendation
## 3 Methodology
### Prototype Generation and Feature Augmentation  
As shown in the \"K-means\" module of Figure 1, to select representative preference prototypes from the dataset, ProtoRec runs the K-means clustering algorithm at each epoch to extract \(k\) cluster centers as prototypes for each category in the initialized user and item embedding spaces [19]. Although prototypes may be less accurate in the early stages of training, as the model gradually converges, the extracted prototypes progressively align with the correct clusters, ensuring feature distinctiveness while avoiding unnecessary model complexity. Unlike other methods [20; 21] that extract prototypes separately for users and items, ProtoRec aims to classify all nodes with potential preferences into one category. Therefore, when implementing the K-means algorithm, users and items are considered as a whole, effectively controlling the number of prototypes. Thus, the preference prototypes proposed at each epoch are as follows:  
\[\mathbf{P}=kmeans(\mathbf{E}^{(\mathbf{0})}) \tag{6}\]  
where \(\mathbf{P}\in\mathbb{R}^{k\times d}\) represents the preference prototypes, and \(kmeans(\cdot)\) denotes the deployed K-means algorithm. The number of clustering centers \(k\), serving as the basis for prototype information, is controlled through parameter tuning. In the embedding space, the clustering centers evenly partition the dataset into different categories, thereby meeting the requirements of the subsequent feature refinement module. Although the K-means algorithm effectively extracts representative prototypes, learning the same prototype for nodes of the same class can lead to over-smoothing. As shown in Figure 2, using preference levels to measure the relationship between nodes and existing prototypes and exploring refined preferences for each user and item is an alternative method. Inspired by the self-attention mechanism, the dot product similarity \(\mathbf{E}\cdot\mathbf{P}^{T}\) between the GNN embeddings \(\mathbf{E}\) and the prototypes \(\mathbf{P}\) extracted by K-means is calculated as the preference scores, and a sigmoid function is deployed to normalize the preference scores. The preference scores predict the probability of the association between embeddings and prototypes, with values ranging from 0 to 1. To eliminate the influence of irrelevant prototypes, interactions with a probability below 0.5 are masked. The threshold should be set to evenly divide the probability range. Finally, the refined prototype embedding is computed by preference scores:  
\[\mathbf{P}_{r}=sigmoid(\mathbf{E}\cdot\mathbf{P}^{T})\cdot\mathbf{P} \tag{7}\]  
where \(\mathbf{P}_{r}\in\mathbb{R}^{(M+N)\times d}\) represents the refined preference prototype matrix for each user and item. Equation (7) corresponds to the \"Refinement\" module in Figure 1.  
Due to the complexity and time-consuming nature of generating more-uniform embeddings through graph structure perturbations, ProtoRec migrates the augmentation scheme to the embedding space. In formal terms, the augmentation strategy can be represented as \(\mathbf{G}=\mathbf{E}+\mathbf{P}_{r}\). As shown in Figure 3, taking any user \(u\) as an example, the embedding learned through the GNN is denoted as \(\epsilon_{u}^{(u)}\), which is added to the corresponding prototype \(p_{r,u}^{(u)}\), making the learned embedding closer to the preferred prototype and obtaining augmented embedding \(g_{u}^{(u)}\). This can be understood as users consciously selecting their preferred categories. Since directly adding prototype information to embeddings may lead to uneven embeddings and misguide representation learning, ProtoRec employs a prototype filtering network (PFN) to balance feature augmentation. Structurally, the PFN consists of linear transformation functions \(f_{t}(\cdot)\) and \(f_{s}(\cdot)\) for enhancing model fitting, and a self-gating module \(f_{gate}(x)=x\cdot sigmoid(f_{s}(x))\) for controlling feature augmentation.