# Adaptive Leakage Protection for Low-Voltage Distribution Systems Based on SSA-BP Neural Network
## 3 Normal Leakage Current Prediction Model
### Prediction Model Training  
The sparrow algorithm is used to iteratively update the weight and threshold of the BP neural network, and the minimum error value of the neural network is the fitness function of the sparrow algorithm. The sparrow algorithm obtains the ideal weight and threshold, and it assigns the weight and threshold to the BP neural network. The specific training steps are as follows:  
Step 1: Initialize the weights and biases of each layer and set the basic parameters of the BP neural network.  
Step 2: Initialize the parameters of the sparrow search algorithm, including the number of sparrow populations, the maximum number of iterations, the upper and lower limit of the independent variable, the dimension, and the sample data.  
Step 3: According to the input parameters, calculate the output of node \(p\) (\(p=1,2,\ldots,j\)) in the input layer.  
\[hid_{p}^{n}=\sum\limits_{i=1}^{j}w_{ip}x_{i}^{n}+a_{p}. \tag{10}\]  
Step 4: Calculate the output of hidden layer node \(p\) as  
\[out_{p}^{n}=f\big{(}hid_{p}\big{)}=\frac{1}{1+exp\Bigg{(}-\sum\limits_{i=1}^{ j}w_{ip}x_{i}^{n}-a_{p}\Bigg{)}}. \tag{11}\]  
Step 5: Similarly, the output of the output layer is  
\[y^{n}=f\Big{(}out_{p}^{n}\Big{)}=\frac{1}{1+exp\Bigg{(}-\sum\limits_{p=1}^{z} w_{p}out_{p}^{n}-b\Bigg{)}}. \tag{12}\]  
In (11) and (12), \(a_{p}\) and \(b\) are the thresholds.  
Step 6: The error of the predicted value can be expressed by the following Equation:  
\[e^{n}=y^{n}-m^{n}. \tag{13}\]  
Step 7: The error in the training result is taken as the fitness value, and the current position of the sparrow is obtained according to the fitness value.  
Step 8: The SSA fitness value is updated according to the better position obtained above. Update the values of \(w_{ip}\) and \(w_{p}\) using Equations (14) and (15).  
\[w_{ip}=w_{ip}+\eta x_{i}^{n}out_{p}^{n}\Big{(}1-out_{p}^{n}\Big{)}\sum\limits _{p=1}^{z}w_{p}e^{n}. \tag{14}\]  
\[w_{p}=w_{p}+\eta out_{p}^{n}e^{n}. \tag{15}\]  
In (14), \(\eta\) is the learning rate.  
Step 9: The thresholds of the hidden and the output layers will also be updated as  
\[a_{p}=a_{p}+e^{n}. \tag{16}\]\[b=b+\eta out_{p}^{n}\Big{(}1-out_{p}^{n}\Big{)}\sum_{p=1}^{z}w_{p}e^{n}. \tag{17}\]  
Step 10: If the newly obtained fitness value is less than the original value, it means the new position is better, and the value is updated; otherwise, the current value is kept unchanged.  
Step 11: If the fitness value is less than the set threshold, the termination condition is satisfied. At the same time, the optimal fitness value satisfying the condition is output, as well as the corresponding weight and threshold, in this case. Otherwise, the number of iterations is increased by 1, and the execution jumps to Step 7.  
Step 12: According to the optimal weight and threshold, the network model parameters are obtained, and the BP network architecture is determined by using the parameters.  
Step 13: The data that needs to be predicted are input to the optimized model for normal leakage current prediction.  
Step 14: Output the prediction results in the form of curves.  
The overall fitness showed a downward trend, and reached the minimum value of 0.0168 at 18 times after 50 iterations of evolution, which demonstrated that the SSA algorithm can optimize the initial value of the weight and threshold of the BP neural network algorithm with low overhead.  
Table 1 shows the minimum relative error value, maximum relative error value, and mean squared error value between the SSA-BP algorithm and the traditional BP neural network algorithm. 'MIRE' represents the minimum relative error, 'MARE' represents the maximum relative error, 'MSE' represents the mean squared error. The MSE of the SSA-BP algorithm is 0.0095, the MIRE is 0.0017, and the MARE is 0.1852. According to the error theory principle of the evaluation algorithm in econometrics, controlling the error within the range of 20% is a better prediction algorithm. Through the comparison, it can be seen that the prediction algorithm in this paper has a better effect.