*3.2. Algorithm Optimization Based on Sparrow Search Algorithm* 3.2.1. Sparrow Search Algorithm

Introducing the SSA with stronger search ability and faster convergence speed to update the BP neural network to improve the accuracy of the model. The SSA is a swarm intelligence optimization algorithm that is based on the foraging and anti-predation behavior of the sparrow. The sparrow with the highest fitness is prioritized in the SSA. They are separated into discoverers and joiners during the foraging process of sparrows. Discoverers are responsible for discovering food in the population and offering foraging places and instructions for the entire sparrow population, whereas joiners rely on discoverers for food. Sparrows can usually forage as discoverers and joiners to obtain food. Individuals in the population monitor the behavior of others in the community, and attackers in this population will fight for food supplies with high-intake peers to raise their predation rate. Furthermore, when the sparrow population detects a threat, it will engage in anti-predatory behavior. During each iteration, the description of the discoverer's location update is shown in the following equation [43]:

$$X\_{i,j}^{\;\;q+1} = \begin{cases} X\_{i,j} \, ^q \exp\left(\frac{-i}{a \times \text{iter}\_{\text{max}}}\right) , if \; R\_2 \le ST\\\ X\_{i,j} \, ^q + \mathcal{Q} \times L, if \; R\_2 > ST \end{cases} \tag{6}$$

where *q* is the current number of iterations, *iter*max is the largest iteration algebra, *Xij* is the position information of the *i*-th sparrow in the *j*-th dimension, *α* is the random number(*α* ∈ (0, 1]), *R*<sup>2</sup> is the warning value (*R*<sup>2</sup> ∈ [0, 1]), *ST* is the safety value (*ST* ∈ [0.5, 1]), *Q* is the random number subject to normal distribution, and *L* is a matrix of 1 × d, where each element within the matrix is all 1.

When *R*<sup>2</sup> < *ST*, it indicates that there are no predators in the foraging environment, allowing for the discoverers to conduct lengthy search activities. If *R*<sup>2</sup> ≥ *ST*, it means that some sparrows in the population have detected predators and alerted other sparrows. At this time, the sparrows must fly immediately to other safe areas for feeding. The description of the joiner's location update is shown in the following equation:

$$X\_{i,j}^{\;\;q+1} = \begin{cases} X\_{\text{best}}{}^q + \beta \times |X\_{i,j}{}^q - X\_{\text{best}}{}^q|, \text{if } f\_i > f\_{\text{\"\;g}}\\ X\_{i,j}{}^{q+1} + K \times \left(\frac{X\_{i,j}{}^q - X\_{\text{worst}}{}^q}{(f\_i - f\_{\text{\"\;w}}) + \varepsilon}\right), \text{if } f\_i = f\_{\text{\"\;g}} \end{cases} \tag{7}$$

where *Xbest* is the optimal position occupied by the discoverer; *Xworst* is the current global position; *β* is the control parameter of step size, which follows the normal distribution random number with the mean of 0 and variance of 1; *K* ∈ [−1, 1] represents the random number; *fi* is the fitness value of current sparrow individuals; *fg* is the fitness value of the sparrow in the current global optimal position; *fw* is the fitness value of the sparrow in the current global worst position; and *ε* is a constant.

Among these, *fi* > *fg* indicates that sparrows are on the periphery of the population and highly vulnerable to predators. When *fi* = *f*, it demonstrates that sparrows in the middle of the population know the danger and should approach other sparrows to reduce the predation risk. *K* controls the direction of the sparrow's movement and step size.
