# Resource Allocation for Network Slicing in RAN Using Case-Based Reasoning
## 3 Problem Formulation  
O-KNN is used to predict the slice ratio. The similarity between the query case and the library cases is first calculated, and then a search is made of the nearest \(k\) neighbors. The \(k\) value is determined by the reconstruct process between the test sample and training sample. We use the training sample to reconstruct each test sample by least squares, spare learning, and locality preserving projections. Finally, the solutions are predicted by weighting the distance of the \(k\)-nearest neighbors. The flowchart of the O-KNN method is shown in Figure 3.  
To test the CBR approach, we used query cases from the test data where we had already used an exhaustive search to determine the optimum slice ratios. We compared the test case with the attributes in the case library using Euclidean distance. To speed up the retrieval, brute force [16] was applied. Investigating a faster search structure would form part of future work using the approach here as a benchmark. \begin{table}
\begin{tabular}{c c c} \hline
**Cases** & **Attributes** & **Solution** \\ \hline Case 1 & \(\{A_{11}\),\(A_{12}\),\(\ldots A_{1d}\}\) & \(\omega_{1}\) \\ \hline Case 2 & \(\{A_{21}\),\(A_{22}\),\(\ldots A_{2d}\}\) & \(\omega_{2}\) \\ \hline ⋮ & ⋮ & ⋮ \\ \hline Case n & \(\{A_{n1}\),\(A_{n2}\),\(\ldots A_{nd}\}\) & \(\omega_{n}\) \\ \hline \end{tabular}
\end{table} 
Table 1: Case library. Figure 3: Flowchart of the O-KNN method. Each case in the library is an d-dimensional space and the Euclidean distance between the query case (\(q\)) and each library case (\(c_{i}\)) represents the similarity and can be expressed as:  
\[d_{i}=\sqrt{\sum_{j=1}^{d}\left(q_{j}-c_{i,j}\right)^{2}} \tag{3}\]  
By calculating this, we can find the set of \(k\) nearest neighbors, i.e., those with the smallest value of \(d_{i}\). Each of those \(k\) neighbors has a value for the slice ratio and the KNN approach [17] takes these \(k\) values of distance and output (slice ratio) to predict the value of \(w\) for the query case, which we denote as \(w_{q}\). This prediction is generally conducted by using a weighted combination [18] of the outputs with the weighting depending on distance. The \(\alpha(\bullet)\) is the weight function and is shown in Table 2.  
\[\omega_{q}=\frac{\sum_{i=1}^{k}\alpha(d_{i})\times\omega_{i}}{\sum_{i=1}^{k} \alpha(d_{i})} \tag{4}\]  
The \(k\) value metrics and distance metrics used in KNN algorithms have an impact on their performance. Using a set \(k\) value for all query cases is not feasible [19] as is using the time-consuming cross-validation approach [13] to obtain the \(k\) value for each query case. The \(k\) value should be different and should be learned from the data. The selection of an optimal \(k\) value for each query case as the nearest neighbor to conduct KNN by sparse learning, and locality preserving projections have shown to be highly effective [20; 21]. The case library is denoted as a matrix \(\mathbf{X}\in\mathbb{R}^{n\times d}\), where \(n\) and \(d\), respectively, denote the quantity of practice samples and attributes. \(\mathbf{X}=[x_{ij}]\), its \(i\)-th row and \(j\)- th column are denoted as \(x_{i}\) and \(x^{j}\), respectively. \(\mathbf{Y}\in\mathbb{R}^{d\times m}\) denotes the transpose matrix of the query cases, where \(m\) denotes the number of query case. In this paper, we propose to reconstructed query case \(\mathbf{Y}\) using case library \(\mathbf{X}\), with the purpose of minimizing the distance between \(\mathbf{X}^{\mathrm{T}}\mathbf{w}_{i}\) and \(y_{i}\). The reconstruction coefficient or correlation between the case library and query cases is denoted by \(\mathbf{W}\in\mathbb{R}^{n\times m}\).