# Improving Deep Learning-Based Recommendation Attack Detection Using Harris Hawks Optimization
## 3 Proposed Approach
### Detection Algorithms
Generally, it is not necessary to let the optimization algorithm continue to run after the learning performance is stable. Driven by this idea, the early stop conditions have been successfully applied in many learning models to speed up training and optimization [37, 38]. However, the original HHO algorithm has no early stop condition yet. Therefore, the number of iterations performed by the HHO algorithm must be the maximum. Based on this analysis, in this paper, to improve the original HHO algorithm we use the detection stability as an early stop condition, as shown in lines 7 to 9 of Algorithm 2, to reduce the optimization iterations of the HHO algorithm. From our experiments, it can be found that this is a useful improvement. Benefit from this improvement the detection approach can maintain good detection performance while the number of iterations is reduced greatly. ```
0: training set \(Set_{train}\), validation set \(Set_{validation}\), deep learning-based detection method \(DLDM\), key hyperparameters and their candidate values \(Set_{KH}\), the population size \(N\), and the maximum number of iterations \(T\). 0: The location of rabbit \(X_{rabbit}\) which denotes the optimal solution. 1:\(Set_{KH}\leftarrow\) Call Algorithm 1 to convert the discrete key hyperparameters to continuous key hyperparameters in \(Set_{KH}\). 2:\(X_{i}(i=1,2,\dots,N)\leftarrow\) Initialize the population \(X_{i}(i=1,2,\dots,N)\), randomly. Each \(X\) is a D-dimensional vector which element is randomly set by using \(Set_{KH}\). Each \(X\) is a hawk. 3:\(X_{rabbit}\gets X_{1}\). 4:while the number of iterations is less than \(T\)do
5:\(fitness_{i}(i=1,2,\dots,N)\leftarrow\) Train \(DLDM\) to generate classifiers by using \(Set_{train}\) and each \(X\). Use these classifiers to detect the \(Set_{validation}\), respectively. Calculate f-measures according the detection results for each classifier. Take the f-measure as fitness of each classifier. 6:\(X_{rabbit}\leftarrow\) Set \(X_{rabbit}\) as the location of rabbit. The classifier corresponding to \(X_{rabbit}\) has the maximum fitness. 7:if the maximum fitness has not changed for \(m\) consecutive iterations then
8:return\(X_{rabbit}\). 9:endif
10:for each hawk \(X_{i}\)do
11: Update the initial energy \(E_{0}\) and jump strength \(J\). 12: Update \(E\) using Equation (3). 13:if\(|E|\geq 1\)then
14: Update the location vector using Equation (1). //Exploration. 15:endif
16:if\(|E|<1\)then
17:// Exploitation. 18:if\(r\geq 0.5\) and \(|E|\geq 0.5\)then
19: Update the location vector using Equation (4). 20:else if\(r\geq 0.5\) and \(|E|<0.5\)then
21: Update the location vector using Equation (6). 22:else if\(r<0.5\) and \(|E|\geq 0.5\)then
23: Update the location vector using Equation (10). 24:else if\(r<0.5\) and \(|E|<0.5\)then
25: Update the location vector using Equation (11). 26:endif
27:endif
28:endfor
29:endwhile
30:return\(X_{rabbit}\). ```  
**Algorithm 2** Hyperparameter automatic optimization algorithm based on the improved HHO algorithm. Let \(U_{u}=[rating_{1},rating_{2},\dots,rating_{IT}]\) denote a rating vector of user \(u\) where \(IT\) denotes the number of items in a recommender system. Let \(Set_{train}=\{U_{1},U_{2},\dots,U_{TR}\}\) denote the training set where \(TR\) denotes the number of users in the training set. Let\(Set_{validation}=\{U_{1},U_{2},\ldots,U_{VA}\}\) denote the validation set where \(VA\) denotes the number of users in the validation set. Let \(DLDM\) denote a deep learning-based detection method which has a certain number of key hyperparameters. Let \(K_{d}\) denote the \(d\)th key hyperparameter with its candidate values derived from \(DLDM\). Therefore, a solution \(X\) for a \(DLDM\) can be denoted as \([k_{1},k_{2},\ldots,k_{d},\ldots,k_{D}]\) where \(D\) denotes the number of key hyperparameters and \(k_{d}\) is a candidate value of \(K_{d}\).