## 3 Establishment of the Flow Prediction Model
### Neural Network Flow Prediction Methods  
BP neural networks are multi-layer feed-forward neural network algorithms, which have been widely used in various subject areas [17]. The BP neural network structure includes input, hidden, and output layers. Training is performed by passing sample information forward and propagating sample errors backward, and the thresholds and weights are continuously optimized and adjusted based on the feedback error data. Training stops when the total error of the training samples is lower than the set error value or when the specified number of training times is reached. The trained BP neural network model has a nonlinear relationship from input factors to output results. The output results can be calculated directly by importing the parameter values of the impact factors. In this paper, three influencing factors, namely gate opening, upstream water level, and downstream water level, are used as input factors. The number of neurons in the input layer is 3. The flow is used as the output layer, and the number of neurons in the output layer is 1.  
The initial weight and threshold are important factors that affect the calculation accuracy and stability of BP neural networks. Since the initial weights and thresholds are randomly generated in the BP neural network, unreasonable initial weights and thresholds will reduce the generalization ability of the BP neural network. The prediction results will exhibit a phenomenon of \"overfitting\", where the training result will have a small error while the prediction result will have a large error. Existing studies have shown that the genetic algorithm (GA) [18] and particle swarm optimization (PSO) [19] are two commonly used efficient optimization methods for BP neural networks. The GA method solves the optimal initial weights and thresholds by simulating the genetic process of organisms in nature. After that, the BP neural network is trained with samples based on the optimal initial weights and thresholds. This combination is called the GA-BP neural network model. Similarly, the PSO method solves the optimal initial weights and thresholds by simulating the predatory behavior of bird populations in nature. Then, the optimal solutions are substituted into the BP neural network for network training. This combination is called the PSO-BP neural network model. The specific implementation steps of the GA-BP neural network model and the PSO-BP neural network model are shown in Figure 4. The constraint condition for discharge flow is 110-2500 m\({}^{3}\)/h, and the constraint condition for gate opening is 100-590 mm. The number of nodes in the hidden layer of the BP neural network is 5, the network training accuracy is set to 0.0001, the upper limit of network training is set to 5000 times, the error threshold is \(10^{-6}\), and the learning rate is 0.01. The genetic algebra of the GA-BP neural network model is set to 50, the population size is 5, the evolution algebra is 100, the crossover probability is 0.4, and the mutation probability is 0.01. The learning factor of the PSO-BP neural network model is 4.494, the number of population updates is 30, the population size is 5, the inertia weight is 0.6, and the maximum iteration number is 2000. The maximum and minimum boundaries are 1 and \(-1\), respectively. The training of the BP neural network is carried out using the built-in neural network toolbox of MATLAB2019b software. The optimization of initial weights and thresholds of the BP neural network by the GA algorithm and the PSO algorithm is implemented through programming in MATLAB.