# A Lightweight Multi-Source Fast Android Malware Detection Model
## 3 A Lightweight Multi-Source Fast Android Malware Detection Model
### Adaptive Soft Voting Ensemble Method  
An ensemble learning method combines the results of two or more separate machine learning algorithms and attempts to produce results that are more accurate than any single algorithm.  
Voting is a combination strategy for classification problems within ensemble learning. The basic idea is to select the class with the most output among all machine learning algorithms. There are two types of machine learning algorithm outputs for classification: one is the direct output of class labels, and the other is the output of class probabilities, using the former for voting is called Hard voting, and using the latter for classification is called Soft voting.  
Soft voting obtains the weighted average of each class probability by inputting weights, and selects the class with the more significant value; soft voting returns the class labels as Argmax of the sum of predicted probabilities, which is achieved by outputting class probabilities. We propose the soft voting method using the above base models for ensemble learning. The weights of traditional static weighted average probability soft voting are determined manually. Generally, they use multiple homogeneous base models, but we extract different features using different models. Since different features and models have different training curves and fitting abilities, the voting weights need to be dynamically adjusted during the training process. So we propose a dynamic weighted soft voting method, where the gradient descent principle automatically determines the voting weights, and a new loss function is designed for this model.  
Let \(N\) be the number of samples, \(p_{i}\) be the probability that the \(i\)th sample is a positive case, and \(y_{i}\) be the label of the \(i\)th sample, then the binary cross-entropy formula is as Equation (7).  
\[L_{\text{BCE}}(p,y)=\frac{1}{N}\sum_{i=1}^{N}-[y_{i}\cdot log(p_{i})+(1-y_{i}) \cdot log(i-p_{i})] \tag{7}\]  
where the probabilities \([p_{1},p_{2},\cdots,p_{j}]\) of the positive cases derived from \(M\) models and the weights \(W\) are calculated by the Hadamard product of Softmax operations to derive the probability of positive cases \(p_{vote}\) after soft voting, and the Softmax function \(\sigma(W)\) and \(p_{vote}\) is calculated as Equations (8) and (9).  
\[\sigma(W)_{j}=\frac{e^{W_{j}}}{\sum_{m=1}^{M}e^{W_{m}}}\qquad j=1,2,\cdots,M \tag{8}\]  
\[p_{vote}=\sum_{j=1}^{M}([p_{1},p_{2},\cdots,p_{j}]\circ\sigma(W)) \tag{9}\]  
The binary cross-entropy loss \([l_{1},l_{2},\cdots,l_{j}]\) derived from \(M\) models for Softmax operation and the absolute value of the difference between the value of the weights after Softmax operation are calculated as the average and multiplied by the value obtained from the weight parameter \(\mu\). Finally, the sum of this value and the binary cross-entropy of the soft voting results is calculated as the loss _Loss_ of adaptive soft voting, which is calculated as Equation (10).  
\[Loss=L_{BCE}(p_{vote},y)+\mu\times\frac{\sum_{j=1}^{M}|\sigma(-[l_{1},l_{2}, \cdots,l_{j}])-\sigma(W)|}{M} \tag{10}\]  
This loss function can effectively suppress the problem that the adaptive soft voting method assigns too small weights to the base model with slow gradient decline during the training process so that the output of the base model is not considered even if the base model achieves good results at the later stage of training, leading to the problem of falling into a local optimum.