# Learnable Nonlocal Contrastive Network for Single Image Super-Resolution
## 3 Method
### Network Structure
#### 3.2.2 Learnable Nonlocal Contrastive Attention  
As shown in Figure 2, the proposed LNLCA module combines the advantages of self-similar exploration and sparse aggregation strategies and can achieve global correlation information aggregation of important information at the cost of linear complexity, avoiding overfitting while improving the computational efficiency of the model combination and information redundancy problem. Specifically, the self-similar exploration strategy can find feature information highly related to the current location in the local area and aggregate it with the current location. The sparse aggregation strategy can effectively reduce the computational complexity while maintaining the integrity of global information. Formally, the process by which the LNLCA module applies attention to feature vectors is defined as shown:  
\[y_{i}=\sum_{j=1}^{n}\frac{exp\big{(}s\big{(}Q_{i},K_{j}\big{)}\big{)}}{\sum_{j= 1}^{n}f\big{(}s\big{(}Q_{i},K_{j}\big{)}\big{)}}v_{j} \tag{12}\]  
where \(Q_{i}\), \(K_{j}\), and \(K_{j}\) represent the pixel features corresponding to positions \(i\), \(j\), and \(\hat{j}\), respectively, of feature map \(X\); \(y_{i}\) represents the output for position \(i\); \(f(*)\) represents the similarity measurement between feature map \(Q\) and feature map \(K\); \(v_{j}\) represents the feature transformation function; and \(n\) represents the input size. Among them, to explore more valuable nonlocal textures, we proposed to incorporate the learnable similarity score function (LSS) [22] and the dot product similarity score function (DPSS) [22] into the LNLCA module, thereby forming the \(s(*,*)\) function. Furthermore, different from traditional nonlocal attention mechanisms, our LNLCA module achieves better performance by approximating Gaussian random features and changing the multiplication order. Formally, the \(s(*,*)\) function can be defined as below:  
\[s\big{(}Q_{i},K_{j}\big{)}=s_{l}^{j}(Q_{i})+s_{f}\big{(}Q_{i},K_{j}\big{)} \tag{13}\]  
where \(s_{l}^{j}(*)\) represents the score of position \(j\) in the learnable similarity scoring function (LSS) and \(s_{f}(*)\) represents the dot product similarity scoring function (DPSS). \(s_{l}(*)\) can adaptively modify the scores of different positions in the nonlocal texture, thereby helping the network correct some inaccurate textures, which is formally defined as follows:  
\[s_{l}(Q_{i})=W_{2}\sigma(W_{1}\theta(Q_{i})+b_{1})+b_{2} \tag{14}\]  
where \(\sigma(*)\) represents the ReLU function and \(W_{1}\in X^{n\times c}\), \(W_{2}\in X^{n\times n}\), \(b_{1}\in X^{n}\), and \(b_{2}\in X^{n}\). The dot product similarity score \(s_{f}(*)\) is formally defined as shown:  
\[s_{f}\big{(}Q_{i},K_{j}\big{)}=\theta(Q_{i})^{T}\delta\big{(}K_{j}\big{)} \tag{15}\]  
For an input feature map \(X\), we first multiplied by a scaling factor \(k\) to increase the weight of the relevant information:  
\[Q=\sqrt{k}\frac{\theta(X)}{\parallel\theta(X)\parallel},K=\sqrt{k}\frac{ \delta(X)}{\parallel\theta(X)\parallel},V=g(X) \tag{16}\]  
\[\text{K}\big{(}Q_{i},K_{j}\big{)}=\text{exp}\left(Q_{i}^{\top}K_{j}\right)= \phi(Q_{i})^{T}\phi\big{(}K_{j}\big{)} \tag{17}\]  
where \(X\) and \(k\) represent the module input feature map and the magnification factor, respectively; \(\theta(*)\), \(\delta(*)\), and \(g(*)\) represent feature transformation functions; and \(Q_{i}\) and \(K_{j}\) represent the pixel information at positions \(i\) and \(j\) in the feature maps \(Q\) and \(K\), respectively. By setting \(r\) Gaussian random samples and concatenating these samples into a Gaussian random matrix \(F\), the Gaussian random feature map was further approximatedas \(\phi(Q_{i})^{T}\phi(K_{j})\), where \(\phi(u)=\frac{1}{\sqrt{t}}\exp\left(-\parallel u\parallel^{2}/2\right)\exp(Fu)\).