# Local Contrast Learning for One-Shot Learning
## 3 Methodology
### Local Contrast Learning
#### 3.1.1 Contrasting Cognitive Context Constructor  
The contrasting cognitive context constructor is responsible for constructing the Local Cognitive Context (LCC) from the labeled support set (training data), denoted as \(S=\{S_{1},\dots,S_{c},\dots,S_{SC}\}\) and \(S_{c}=\{(x_{ci},y_{c})\}_{i=1}^{K}\), where \(K\) is the number of training images in each category (in order to simplify the analysis, in this paper, it is supposed there is the same number of training images in every category; however, LCL allows different numbers). Here, \(x_{ci}\in\mathbb{R}^{W\times H}\) is the \(i\)th training image (or sample) in the \(c\)th category, \(W\) is the width of an image, and \(H\) is the height of an image. Here, \(y_{c}\in\mathbb{C}_{S}=\{c_{1},\dots,c_{c},\dots,c_{SC}\}\) is the corresponding label and \(SC\) is the number of the categories. The Local Cognitive Context \(LCC=\left((x_{c},y_{c}),\{(x_{i},y_{i},z_{i})\}_{i=1}^{L}\right)\) is defined by a recognized object \((x_{c},y_{c})\), and a set of contrastive objects \(\{(x_{i},y_{i},z_{i})\}_{i=1}^{L}\). Here, \(L\) is the number of contrastive objects in an LCC. In the set of contrastive objects, there is one and only one sample whose category is equal to \(y_{c}\) and that is called a contrastive positive object (the \(z_{i}\) is set to 0), but there is not a sample that is equal to \(x_{c}\). The contrastive objects, except for this contrastive positive object, are called contrastive negative objects (the \(z_{i}\) is set to 1). There are not two samples with the same category in the contrastive objects. The Local Cognitive Context (LCC) is constructed from a labeled support set (training set) and is crucial for ensuring the effective training of the LCL method, especially when dealing with small datasets. By creating a diverse LCC, the LCL method enhances the robustness of the model, thereby improving its recognition and classification capabilities and overall performance in one-shot learning tasks. Algorithm 1 can construct a large amount of different Local Cognitive Contexts by two random selections and one shuffle. The amount of Local Cognitive Contexts is extremely crucial for LCL. The number of contrastive categories combinations in Step 1 is  
\[C_{L}^{SC}=\left({}_{L}^{SC}\right)=\frac{SC!}{L!(SC-L)!} \tag{1}\]  
```
Data: A labeled support set \(S=\{(x_{i},y_{i})\}_{i=1}^{K}\), and the number of contrastive objects \(L\). 1. Randomly sample \(L\) categories from \(\mathbb{C}_{S}\) as contrastive categories. 2. Select the first category as a contrastive positive category from the contrastive categories, and the other as contrastive negative categories. 3. Iteratively sample one image from each contrastive negative categories as a contrastive negative object. 4. Sample two images from the contrastive positive category; one is a recognized object \((x_{c},y_{c})\) and another is a contrastive positive object. 5. Concatenate the contrastive positive objects and the contrastive negative objects as contrastive objects \(\{(x_{i},y_{i},z_{i})\}_{i=1}^{L}\). 6. Randomly shuffle \(\{(x_{i},y_{i},z_{i})\}_{i=1}^{L}\)
```  
**Algorithm 1**Build procedure for Local Cognitive Context  
The number of contrastive negative object combinations for each contrastive negative category is \(K\). The number of contrastive positive object combinations for each contrastive positive category is Equation (2). So, the number of contrastive object combinations is Equation (3). \[C_{2}^{K}=\left({}_{2}^{K}\right)=\frac{K!}{2!(K-2)!}=\frac{1}{2}K\times(K-1) \tag{2}\]  
\[N_{co}=\frac{SC!}{L!(SC-L)!}\times\left((L-1)\times K+\frac{1}{2}K(K-1)\right) \tag{3}\]In Step 6, the contrastive objects are randomly permutated, so the number of each contrastive object permutations is \(L!\).