# MLW-gcForest: A Multi-Weighted gcForest Model for Cancer Subtype Classification by Methylation Data
## 2 Materials and Methods
### Multi-Weighted gcForest (MLW-gcForest)
#### 2.3.2 Sorting Optimization Algorithm (Calculation of Weight \(\beta\))  
As the different feature vectors of the sliding window have different effects on the classification results, we considered assigning corresponding weights to different sliding windows. We call the weight setting process the sorting optimization algorithm, as shown in the right part of Figure 4.  
Sorting Optimization Algorithm  
(1) The input is \(N_{s}\) and \(N_{w}\). \(N_{s}\) is the number of samples, and \(N_{w}\) is the number of sliding windows. \(M_{o}\) represents the dimension of the original features, and \(N_{c}\) represents the number of sample classes. For sample \(i\), the sliding window \(w\) (\(1\leq w\leq N_{w}\)). The size of the sliding window \(w\), \(S\), (\(S=100,200\ldots\)), is used to cut the original high-dimension data into multi-instance feature vectors. The step size of the scan is \(S_{0}\) (default \(S_{0}=1\)). The number of feature vectors after scanning is \(N_{v}\), as shown in Formula (5). \[N_{v}=\frac{M_{o}-S}{S_{0}}+1 \tag{5}\]  
(2) \(M_{o}\)-dim original features are cut by the sliding window to generate \(S\)-dim feature vectors. The number of feature vectors generated is \(N_{v}\). Each \(S\)-dim feature vector is input into one random forest and one completely random forest. The random forest and completely random forest each output \(N_{c}\)-dim class vectors. The class vectors output from the random forest are concatenated into an \(N_{v}*N_{c}\)-dim class vector (called \(\mathbf{RF}_{v}\)); the class vectors output from the completely random forest are concatenated into an \(N_{v}*N_{c}\)-dim class vector (called \(\mathbf{CRF}_{v}\)). (3) \(\mathbf{RF}_{v}\) and \(\mathbf{CRF}_{v}\) are multiplied by the weights \(\alpha_{1}\) and \(\alpha_{2}\) and are concatenated as \(2*N_{v}*N_{c}\)-dim class vectors. The length of the vectors is \(L\) and \(L=2*N_{v}*N_{c}\). (4) The outputs of the random forest and completely random forest classification models are the confidence probabilities that the samples belong to the \(N_{c}\) class. The closer the maximum confidence probability is to 1, the stronger the ability of the forest is in distinguishing the sample categories. Figure 3: Illustration of feature re-representation using sliding window scanning [28]. We took the first \(1/N_{c}\) class vectors to measure the prediction ability of the current sliding window. The \(L\)-dim class vectors obtained in the previous step are sorted in descending order. The top \(1/N_{c}\) of the sorted class vectors are averaged. This calculation can approximate the strength of the prediction ability of the current window for the current sample \(i\). We called this value the \(\textit{Pre\_ability}_{i}\), as shown in Formula (6). \[\textit{Pre\_ability}_{i}=\frac{\sum\limits_{j=1}^{\frac{L}{N_{c}}}\textit{Des} (\textit{con}(\textit{RF}_{\textbf{p}}*\alpha_{1},\textit{CRF}_{\textbf{p}}* \alpha_{2}))}{\frac{L}{N_{c}}} \tag{6}\]  
where _Des_ represents the descending order and _con_ represents the concatenation operation. (5) For each of the \(N_{s}\) samples, we repeated steps (1)-(4) and obtained the prediction abilities of the \(N_{s}\) samples, \(\textit{Pre\_ability}_{1},\ \ldots,\textit{Pre\_ability}_{i},\ \ldots,\ \textit{Pre\_ability}_{N_{s}}\). (6) The prediction ability \(\textit{W\_ability}_{w}\) of the sliding window, \(w\) was obtained by averaging the prediction ability of the \(N_{s}\) samples, as shown in Formula (7). \[\textit{W\_ability}_{w}=\frac{\sum_{k=1}^{N_{s}}\textit{Pre\_ability}_{k}}{N_{s}} \tag{7}\]  
(7) For each window, we repeated steps (1)-(6) to obtain the prediction ability of each window, \(\textit{W\_ability}_{1}\ \ldots\textit{W\_ability}_{w}\ldots\textit{W\_ability}_{N_{s}}\). (8) We normalized \(\textit{W\_ability}\) to obtain the predictive weight \(\beta_{w}\) for each sliding window, as shown in Equation (8). We obtained the weights for each window, \(\beta_{1},\ \beta_{2}\ \ldots\ \beta_{w}\ \ldots\beta_{N_{w}}\).