# State-of-Charge Prediction Model for Ni-Cd Batteries Considering Temperature and Noise
## 3 APSO-GRNN Algorithm
### Optimization Process of APSO Algorithm  
According to the model's prediction error, APSO automatically adjusts the velocity weight of the particles to control the convergence speed and improve the model's prediction accuracy. Assuming that the number of particles is n, the particle search space dimension is \(M\) and the basic particle swarm algorithm formula is  
\[v_{i}^{k+1}=wv_{i}^{k}+c_{1}r_{1}(p_{i}^{k}-x_{i}^{k})+c_{2}r_{2}(g_{M}^{k}-x_{ i}^{k}) \tag{6}\]  
\[x_{i}^{k+1}=x_{i}^{k}+v_{i}^{k+1} \tag{7}\]  
Figure 2: GRNN structure diagram. \[\left\{ \begin{array}{ll}-v_{max}&v_{i}^{k+1}<-v_{max}\\ v_{max}&v_{i}^{k+1}<-v_{max}\end{array} \right. \tag{8}\]  
where \(k\) is the number of iterations, \(x_{i}\) is the position vector of the particle, the corresponding velocity vector is \(v_{i}\), \(p_{i}\) is the historical optimal value of the particle, \(g_{M}\) is the group optimal value in the current particle population, \(c_{1}\) and \(c_{2}\) are the learning factors, \(c_{1}>0\), \(c_{1}>0\), \(r_{1}\), \(r_{2}\) are random numbers in the range of [0,1], and \(v_{max}\) is the maximum velocity limit for the particle. The weight parameter, denoted as \(w\), is a critical component in particle swarm optimization. When the speed weight increases, the global optimization ability of the particle swarm improves while the local optimization ability decreases, and vice versa. Static weight parameters are insufficient to meet the requirements for convergence speed and global optimization simultaneously. Additionally, the number of neurons in the output layer of the GRNN is determined by the number of samples in the prediction set. However, due to the long discharge time of Ni-Cd batteries, the voltage drop gradient changes significantly at different times, resulting in decreased prediction accuracy. Moreover, the historical data of input samples exert various influences on the current SOC prediction results, and using a uniform weight in the summation layer further increases the error. To address these issues, the speed weight of particles requires adjustment. Specifically, we define the prediction model as \(f(x)\) and the loss function as  
\[E_{k}=|f(x,\sigma)-y_{k}| \tag{9}\]  
where \(y_{k}\) is the true value of the training set. To measure the magnitude of the error in the output of individual pattern layer neurons relative to the global one, a conditioning scoring function is introduced:  
\[h_{k}=\frac{E_{k}-min(E_{k})}{max(E_{k})-min(E_{k})} \tag{10}\]  
The matrix \(E_{k}\) represents the errors of the \(k\)th iteration output. The scoring function measures the magnitude of the prediction error relative to the overall prediction error. To obtain the score matrix \(h\), the scores of \(n\) neurons are calculated and organized as \(h_{k}=[h_{k1},h_{k2},\ldots,h_{kn}]^{T}\). Although the scoring function indicates the size of the prediction error relative to the overall prediction error, larger values of \(h_{k}\) correspond to worse prediction performance of the particle and thus require a higher weight. However, when the overall prediction error of the particle swarm is large, some particles may account for only a small fraction of it, which diminishes the global search ability of the swarm. Therefore, the bias vector \(B\) needs to be added to ensure the strong global optimization ability of the particle swarm in the early stages of iteration:  
\[B=\frac{2}{T}\ln\frac{E_{k}}{E_{target}} \tag{11}\]  
\(T\) represents the number of iterations and \(E_{target}\) is the error threshold the particle swarm should reach to stop the iteration. The bias vector decreases as the error decreases, enhancing the particle swarm's global search ability in the early stages. Although the scoring function can adjust the weight based on the error, it cannot evaluate the convergence of the particle swarm optimization algorithm. There may be a large prediction error but the algorithm has converged. Therefore, the polymerization degree is introduced to further optimize particle performance.