## 2 Improved Sparrow Search Algorithm and PSO Optimization Algorithm
### Optimization of the Sparrow Search Algorithm  
#### 2.2.1 Sparrow Search Algorithm  
Inspired by sparrow populations' foraging and antipredatory behaviors, a novel population intelligence optimization algorithm with a bionic principle of the detector-follower-alarm model, called the sparrow algorithm, was proposed in 2020. Each sparrow in the population has a matching solution in the SSA. The detector is responsible for finding areas with high food reserves and adaptability and for directing the population to food-producing regions and directions. To get more fitness, the followers choose to forage using the detector with the highest fitness value. Some followers watch the detectors, search for food around them, and even compete for food. In addition, they alert and move quickly to a safe area when danger is recognized, while the sparrows in the middle area move freely and approach other sparrows. At the same time, when the alarm value is greater than the safety threshold, the detector will take other sparrows to other areas to find food [42; 43].  
The sparrow collection matrix is as follows:  
\[X=[x_{1},x_{2},\cdots,x_{n}]^{T},x_{i}=[x_{i1},x_{i2},\cdots,x_{i,d}] \tag{9}\]a sparrow's fitness can be represented by the following mixture:  
\[F_{x}=[f(x_{1}),f(x_{2}),\cdots,f(x_{N})]^{T} \tag{10}\]  
\[f(x_{i})=[f(x_{i,1}),f(x_{i,2}),\cdots,f(x_{i,d})] \tag{11}\]  
where (10) \(F_{x}\) represents the fitness matrix of individuals, while the individuals with high fitness values become detectors and search for food.  
The updated formula for the detector is as follows:  
\[X_{i,j}^{t+1}=\left\{\begin{aligned} X_{i,j}^{t}\cdot\exp\left( \frac{-i}{\alpha\cdot\alpha t\sigma_{\max}}\right),R_{2}<ST\\ X_{i,j}^{t}+Q\cdot L,R_{2}\geqslant ST\end{aligned}\right. \tag{12}\]  
where (12) \(t\) is the number of iterations; \(j=(1,2,\cdots,d)\), and \(X_{i,j}^{t}\) is the i-th individual's location in the j-th dimension; \(\alpha\) is a random number distributed between (0 and 1); \(iter_{\max}\) is the number of iterations that can be performed; \(R_{2}\) is a number chosen at random between (0 and 1); ST denotes a warning threshold taking the value interval (0.5 and 1).  
When \(R_{2}<ST\), the alarm value is less than the safe value, indicating that the population is in a safe position, and the detector conducts an extensive search and approaches the best position. When \(R_{2}>ST\), the alert value exceeds the safe value, the detector issues an alarm, stops foraging, and then, moves to the current best position.  
The formula for updating the location of the followers is as follows:  
\[X_{i,j}^{t+1}=\left\{\begin{aligned} Q\cdot\exp\left( \frac{X_{\text{worst}}-X_{i,j}^{t}}{i^{2}}\right),i>\frac{\pi}{2}\\ X_{p}^{t+1}+\left|X_{i,j}^{t}-X_{p}^{t+1}\right|\cdot A^{+}\cdot \text{ L,otherwise}\end{aligned}\right. \tag{13}\]  
where (13) \(X_{p}\) represents the sparrow's best position in the current population, and \(X_{\text{t}orwise}\) represents its worst position.  
Finally, during foraging, some sparrows in the population will be responsible for vigilance, comprising 10-20% of the entire population. When danger is sensed, all sparrows will stop foraging and relocate to a different place. The formula for updating these sparrows' positions is as follows:  
\[X_{i,j}^{t+1}=\left\{\begin{aligned} X_{\text{best}}^{t}+\beta \cdot\left|X_{i,j}^{t}-X_{\text{best}}^{t}\right|,f_{i}>f_{g}\\ X_{i,j}^{t}+k\cdot\left(\frac{\left|X_{i,j}^{t}-X_{\text{worst }}^{t}\right|}{(f_{i}-f_{w})+\epsilon}\right),f_{i}=f_{g}\end{aligned}\right. \tag{14}\]  
where (14) \(\beta\) is the step adjustment factor, and it follows the standard normal distribution; \(f_{g}\) and \(f_{w}\) denote the global ideal fitness value and global worst fitness value of the sparrow, respectively, and \(k\) is the sparrow's movement direction.