# AFGN: Adaptive Filtering Graph Neural Network for Few-Shot Learning
## 2 Materials and Methods
### The Proposed Method
#### 2.2.3 The Construction of Graph  
In general, the features extracted by the backbone are regarded as node features to construct graphs in graph-based few-shot learning. However, this representation of node features only focuses on the global features of the image, neglecting the local relationships hidden within the image. In our model, the Brownian Distance Metric (BDM) module is utilized to explore the hidden dependency information within features. This dependency relationship serves as node feature representations, while the measured results of these inter-node dependencies function as edges to construct graphs and participate in information propagation within the graph. Firstly, we introduce the principle of the BD for exploring hidden dependency information within features. In probability and statistics, for discrete random vectors \(X\in\mathbb{R}^{m}\) and \(Y\in\mathbb{R}^{m}\), there exist m pairs of random variables \((X,Y)=\{(X_{1},Y_{1}),(X_{2},Y_{2}),\ldots,(X_{m},Y_{m})\}\), which are independent and identically distributed. The Euclidean distance between any two random variables, \(X_{i}\) and \(X_{j}\), within \(X\) is defined as \(b_{ij}=\|X_{i}-X_{j}\|\). Then, the Brownian covariance \(B_{ij}\) between \(X_{i}\) and \(X_{j}\) has the following form [17]:  
\[B_{ij}=b_{ij}-b_{i*}-b_{*j}+b_{**}, \tag{1}\]  
where \(b_{i*}=\frac{1}{m}\sum_{j=1}^{m}b_{ij}\) representing the mean of the total Euclidean distances between \(X_{i}\) and all other rand variables in \(X\), \(b_{sj}=\frac{1}{m}\sum_{i=1}^{m}b_{ij}\) representing the mean of the total Euclidean distances between \(X_{j}\) and all remaining rand variables in \(X\), and \(b_{**}=\frac{1}{m^{2}}\sum_{i=1}^{m}\sum_{j=1}^{m}b_{ij}\) representing the mean of all Euclidean distances among every rand variables in \(X\). Similarly, for \(Y\), we can calculate the Brownian covariance \(C_{ij}\) of random variables \(Y_{i}\) and \(Y_{j}\). Assuming there is an RGB image \(s\), after the backbone processing, we get its embedding in the feature space \(s\in\mathbb{R}^{d\times h\times w}\), where \(d\) is the number of channels, \(h\) and \(w\) represent the height and width in the embedded space, then we transform the feature tensor into a matrix \(X\in\mathbb{R}^{d\times hw}\). Specially, we can consider \(X\) as a discrete random vector, and \(x_{j}\in\mathbb{R}^{hw}\) as a random variable. According to Formula (1), we can get the Brownian covariance matrix \(B\in\mathbb{R}^{d\times d}\) of \(X\):  
\[B=\tilde{B}-\frac{1}{d}(\mathbb{J}\tilde{B})-\frac{1}{d}(\mathbb{J}\tilde{B})^ {T}+\frac{1}{d^{2}}(\mathbb{J}\tilde{B}\mathbb{J}), \tag{2}\]  
where \(\mathbb{J}\in\mathbb{R}^{d\times d}\) denotes a matrix in which all elements are equal to 1, the Euclidean distance matrix is represented as \(\tilde{B}\), and  
\[\tilde{B}=\sqrt{\mathbb{J}(XX^{T}\mathbb{I})+\mathbb{I}(XX^{T})\mathbb{J}-2 XX ^{T}}, \tag{3}\]  
where \(\mathbb{I}\in\mathbb{R}^{d\times d}\) denotes a identity matrix. Correspondingly, for the image \(q\), after converting it to \(Y\in\mathbb{R}^{d\times hw}\), according to Formulas (2) and (3), we can obtain its Brownian covariance matrix \(C\in\mathbb{R}^{d\times d}\):  
\[C=\tilde{C}-\frac{1}{d}(\mathbb{J}\tilde{C})-\frac{1}{d}(\mathbb{J}\tilde{C })^{T}+\frac{1}{d^{2}}(\mathbb{J}\tilde{C}\mathbb{J}), \tag{4}\]  
where the Euclidean distance matrix \(\tilde{C}\):  
\[\tilde{C}=\sqrt{\mathbb{J}(YY^{T}\mathbb{I})+\mathbb{I}(YY^{T})\mathbb{J}-2 YY^{T}}. \tag{5}\]  
Because matrices \(B\) and \(C\) are symmetric, we can extract the upper triangular matrices of \(B\) and \(C\), and vectorize them to obtain the corresponding Brownian covariance vectors\(\mathbf{b}\in\mathbb{R}^{\frac{d\times(d+1)}{2}}\) and \(\mathbf{c}\in\mathbb{R}^{\frac{d\times(d+1)}{2}}\).