Method for predicting hydrological flow based on psa algorithm mlp neural network model
Patent Information
- Application Number
- CN202510269394.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-07
- Publication Date
- 2026-09-29
- Estimated Expiration
- 2045-03-07
AI Technical Summary
传统的统计方法在水文流预测方面存在一定的局限性
[0016]1)采用PSO算法对MLP神经网络模型进行优化,可以解决MLP神经网络模型收敛速度慢以及容易陷入局部优化的问题;
Smart Images

Figure CN120234558B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of hydrological prediction technology, and in particular to a method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm. Background Technology
[0002] Predicting the dynamic changes in hydrological flow has always been a crucial issue in water resources management, flood control, and disaster reduction, and is also a research hotspot in the field of water resources. With the increasing complexity of climate change, hydrological flow variations are becoming increasingly unstable. Accurate prediction of the dynamic changes in hydrological flow plays a vital guiding role in decision-making and engineering design. Traditional statistical methods have certain limitations in hydrological flow prediction. Summary of the Invention
[0003] Purpose of the invention: In order to overcome the shortcomings of the existing technology, the present invention provides a method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm. The MLP model is optimized based on the PSO optimization algorithm and applied to the field of dynamic prediction of hydrological flow.
[0004] Technical Solution: To achieve the above objectives, the present invention provides a method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm, comprising the following steps: Step S1: Collecting hydrological flow data and preprocessing the hydrological flow data; Step S2: Constructing an MLP neural network model and inputting the hydrological flow data into the MLP neural network model for iterative training; Step S3: Optimizing the weights and biases of the MLP neural network model using the PSO algorithm; Step S3 specifically includes the following steps: Step S3.1: Initializing the particle swarm; using the particle positions to represent the weights and biases of the MLP network, and initializing the particle velocities and positions; Step S3.2: Updating the particle velocities and positions, and updating the weights and biases of the MLP network according to the new particle positions; Step S3.3: Fitness evaluation; defining a fitness function to evaluate the prediction accuracy of the neural network, and updating the individual optimal position and global optimal position of each particle according to the fitness value; Step S3.4: Repeating the velocity update, position update, and fitness evaluation until the stopping condition is met; In Step S3.2, the formula for calculating the particle update velocity is: ; where v i t+1 v represents the velocity of the i-th particle at time t+1. i t Let represent the velocity of the i-th particle at time t, w be the inertia weight, c1 and c2 be learning factors, r1 and r2 be random numbers, pi be the historical best position of the i-th particle, pg be the global best position, and x be the velocity of the i-th particle at time t. i t Let represent the position of the i-th particle at time t; the formula for calculating the updated position of a particle is: ;where x i t+1 This represents the position of the i-th particle at time t+1. During the iteration process, the value of the inertia weight w decreases with the increase of the iteration number, and the rate of decrease of the inertia weight w is negatively correlated with the rate of change of the recent river flow. The formula for the value of the inertia weight w is as follows:
[0005] ;
[0006] ;
[0007] ;
[0008] Where wmin is the lower bound of the inertia weight, wmax is the upper bound of the inertia weight, ΔQ(t) is the flow rate change rate, λ(ΔQ) is the decay rate coefficient, λbase is the base decay rate, ΔQmax is the historical maximum flow rate change, and N is the sliding window length. It is the average flow rate within the window.
[0009] Furthermore, in step S1, outliers in the hydrological flow data are detected and processed using the quartile method, missing values in the hydrological flow data are filled using linear interpolation or mean filling methods, and the hydrological flow data are smoothed using the moving average method.
[0010] Further, step S2 specifically includes the following steps: Step S2.1: Determine the grid structure of the MLP neural network model; for the input layer, determine the number of nodes in the input layer based on the number of input features; for the hidden layer, select an appropriate number of hidden layer neurons and activation function; for the output layer, determine the number of nodes in the output layer based on the prediction target; Step S2.2: Perform forward propagation; input the preprocessed hydrological data into the MLP model, calculate the weighted input, convert the weighted input into the output through the activation function, and finally the output value of the output layer is the predicted hydrological flow value; Step S2.3: Adjust the network weights by minimizing the loss function; Step S2.4: Perform backpropagation; calculate the error of the output layer, calculate the error of each layer layer by layer according to the error magnitude, and finally update the weights based on the error and the learning rate.
[0011] Furthermore, in step S2.1, the features input by the input layer include one or more of water level, flow rate, flow rate, precipitation, and evaporation.
[0012] Furthermore, in step S2.1, for river areas with upstream hydropower stations, the features input by the input layer include water level, flow velocity, flow rate, precipitation, evaporation, electricity consumption of the hydropower station in the application area, and the water level difference between the upstream and downstream of the hydropower station. The output layer outputs the flow rate of the river area.
[0013] Furthermore, in step S2.2, the activation function is the Sigmoid function.
[0014] Furthermore, in step S2.3, the mean squared error is used as the loss function.
[0015] Beneficial Effects: The method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm of this invention has the following beneficial effects:
[0016] 1) Using the PSO algorithm to optimize the MLP neural network model can solve the problems of slow convergence speed and easy getting trapped in local optimization in the MLP neural network model;
[0017] 2) For river areas with upstream hydropower stations, the input characteristics also include the electricity consumption of the hydropower station in the application area and the water level difference between the upstream and downstream of the hydropower station, which can improve the prediction effect of hydrological flow.
[0018] 3) When the output layer outputs the flow rate of the river region, the value of the inertial weight w decreases with the increase of the number of iterations, and the decay rate of the inertial weight w is negatively correlated with the recent rate of change of river flow. During the period of high flow change, the decay rate of the inertial weight w can be slowed down to maintain the exploration capability to cope with sudden changes and more accurately predict the flood peak. During the period of low flow change, convergence can be accelerated and the number of iterations can be shortened. Attached Figure Description
[0019] Appendix Figure 1 A line graph showing hydrological data for a certain area;
[0020] Appendix Figure 2 A chart of hydrological data for a certain area;
[0021] Appendix Figure 3 To create a graph of the characteristic values of the MLP after converting the hydrological data;
[0022] Appendix Figure 4 A chart for setting parameters for the PSO algorithm;
[0023] Appendix Figure 5 A schematic diagram illustrating the changes in fitness;
[0024] Appendix Figure 6 A comparison chart showing the MLP model optimized using the PSO algorithm and the unoptimized MLP model;
[0025] Appendix Figure 7 A comparison chart of the MLP model optimized using the PSO algorithm and the BP model;
[0026] Appendix Figure 8 A schematic diagram illustrating the performance of the MLP model optimized using the PSO algorithm in predicting flow error values;
[0027] Appendix Figure 9 A schematic diagram illustrating the error values in predicting flow rates using an unoptimized MLP model;
[0028] Appendix Figure 10 A schematic diagram illustrating the performance of the flow prediction error value using the BP model;
[0029] Appendix Figure 11 A comparison chart of MAE values for the three algorithm models;
[0030] Appendix Figure 12 A comparison chart of MAPE values for the three algorithm models;
[0031] Appendix Figure 13 A comparison chart of the RMSE values of the three algorithm models;
[0032] Appendix Figure 14 This is a comparison chart of the iteration times of the three algorithm models. Detailed Implementation
[0033] The invention will now be further described with reference to the accompanying drawings.
[0034] As attached Figures 1 to 14 The method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm includes the following steps:
[0035] Step S1: Collect hydrological flow data and preprocess the hydrological flow data;
[0036] Step S2: Construct an MLP neural network model and input hydrological flow data into the MLP neural network model for iterative training;
[0037] Step S3: Optimize the weights and biases of the MLP neural network model using the PSO algorithm.
[0038] To address the issues of slow convergence and susceptibility to local optimization in MLP algorithms when dealing with weights and biases in neural network models, this paper optimizes the MLP model based on the PSO optimization algorithm and applies it to the field of hydrological flow dynamic prediction, thus combining the PSO and MLP algorithms.
[0039] Hydrological flow data is crucial for studying hydrological processes and water resource management, and has significant application value in flood forecasting, water resource assessment, and hydraulic engineering design. Accurate and precise collection and preprocessing of hydrological flow-related data are of great importance to hydrological research. The main sources of hydrological flow-related data include hydrological stations, remote sensing data, and simulation models. Hydrological stations are the most common data source, collecting data such as water level and flow velocity using equipment such as level gauges and current meters. Remote sensing data, obtained through satellite remote sensing technology, can acquire large-scale hydrological data, such as rainfall and evaporation data.
[0040] Commonly used hydrological flow data acquisition equipment includes water level gauges, current meters, and rain gauges. Water level gauges acquire water level data by measuring water level differences. Current meters acquire flow velocity data by measuring flow velocity, and rain gauges acquire rainfall data by measuring precipitation. In addition, there are advanced devices such as remote sensing satellites and radars that can acquire a wider range of hydrological data. To improve the objectivity of forecast results, satellite observations can be used to improve data collection, and relevant hydrological flow data from hydrological stations can be used as research data to further analyze corresponding uncertainties. The main data include water level, flow velocity, discharge rate, and water quality parameters.
[0041] To improve the quality of hydrological flow data and facilitate subsequent analysis, data preprocessing is necessary. Common data preprocessing methods include outlier removal, missing value imputation, and data smoothing. Outlier removal refers to eliminating or correcting outliers in the data; missing value imputation refers to interpolating or estimating missing values in the data; and data smoothing refers to reducing data fluctuations and extracting trends and periodicity from the data.
[0042] Specifically, in step S1, outliers in the hydrological flow data are detected and processed using the quartile method, missing values in the hydrological flow data are filled using linear interpolation or mean filling methods, and the hydrological flow data is smoothed using the moving average method.
[0043] The quartile method is commonly used to handle outliers in hydrological flow data. The formula for the quartile method is as follows:
[0044] ;
[0045] ;
[0046] In the above formula, Q1 and Q3 represent the first and third quartiles of the data, respectively, and IQR represents the interquartile range (Q3-Q1). According to this formula, values less than Q1-1.5 * IQR or greater than Q3+1.5 * IQR are considered outliers.
[0047] Common methods for handling missing values in hydrological flow data include linear interpolation and mean imputation. Linear interpolation is suitable when the preceding and following data points are known; it can be used to fill in the missing value. Assuming the missing value is x, the preceding data point is x1, and the following data point is x2, corresponding to times t1 and t2 respectively, the formula for the interpolation result of x is as follows:
[0048] .
[0049] If there are no known data points before or after the missing data point, the mean imputation method can be used. The missing value is filled using the average of other known data. In data processing, while ensuring the continuity of the data sequence, the appropriate missing value imputation method should be selected based on the actual application requirements.
[0050] Hydrological flow data is smoothed using the moving average method. In practice, the average value of the data within a window is first calculated, and this average is used to reduce data fluctuations and extract the long-term trend of the time series data. The formula for the moving average method is:
[0051] ;
[0052] In the above formula, n is the size of the moving average window, p1, p2, ..., pn represent the hydrological flow observations within the sliding window, and δ is the average value of the observations within the window. An appropriate window size can be selected based on actual needs. Collecting and preprocessing hydrological flow-related data is an important part of hydrological research. It can improve data quality and accuracy and provide reliable data support for establishing hydrological models and water resource management.
[0053] Figure 1 It displays preprocessed hydrological flow data for a certain area, which has been converted into a visual chart format.
[0054] Step S2 specifically includes the following steps:
[0055] Step S2.1: Determine the mesh structure of the MLP neural network model. The MLP neural network is a neural network composed of three layers: the input layer, the hidden layer, and the output layer. For the input layer, the number of nodes is determined based on the number of input features. For the hidden layer, an appropriate number of hidden layer neurons and activation functions are selected. For the output layer, the number of output layer nodes is determined based on the prediction target.
[0056] Step S2.2: Perform forward propagation; input the preprocessed hydrological data into the MLP model, calculate the weighted input, convert the weighted input into the output through the activation function, and finally the output value of the output layer is the predicted hydrological flow value;
[0057] Step S2.3: Adjust network weights by minimizing the loss function;
[0058] Step S2.4: Backpropagation; Calculate the error of the output layer, calculate the error of each layer according to the error magnitude, and finally update the weights based on the error and the learning rate.
[0059] For the input layer, the MLP neural network receives raw data as input. The number of nodes in the input layer is the same as the number of features in the data, with each node corresponding to one feature. The data can be represented as a vector, where each element corresponds to the value of a feature. The input layer receives preprocessed hydrological feature data as input.
[0060] Hidden layers are intermediate layers in a neural network where neurons perform non-linear transformations on the input layer data. Each neuron receives the output of the neurons in the previous layer and activates it through an activation function to obtain that neuron's output.
[0061] The expression formula for the hidden layer is:
[0062] ;
[0063] In the above formula, hj represents the output value of the j-th hidden layer neuron. g represents the activation function. xi represents the value of the i-th input neuron in the input layer. wij represents the connection weight between the i-th input neuron and the j-th hidden layer neuron. bj represents the bias value of the j-th hidden layer neuron. n represents the number of input neurons.
[0064] In MLP neural networks, the output layer maps the results of the hidden layers to the final output. For hydrological flow prediction models, the output layer design needs to consider how to convert the features from the hidden layers into predicted hydrological flow values. The input to the output layer is the output of the hidden layers, which can be represented as:
[0065] ;
[0066] In the above formula, Ok represents the output value of the k-th neuron in the output layer. Vkj represents the weight between the j-th neuron in the hidden layer and the k-th neuron in the output layer. ck represents the bias value of the k-th neuron in the output layer. m represents the number of neurons in the hidden layer.
[0067] In one embodiment, in step S2.1, the features input to the input layer include one or more of water level, flow rate, flow rate, precipitation, and evaporation, while the features output to the output layer can also be one or more of water level, flow rate, flow rate, precipitation, and evaporation.
[0068] In another embodiment, in step S2.1, for a river area with a hydropower station upstream, the features input by the input layer include water level, flow velocity, flow rate, precipitation, evaporation, electricity consumption of the hydropower station in the application area, and the water level difference between the upstream and downstream of the hydropower station, and the flow rate of the river area is output by the output layer.
[0069] Generally, the flow rate of a river region is mainly affected by natural factors. However, for river regions with hydropower stations upstream, the operation of these stations also impacts the flow rate. Therefore, human factors can interfere with the flow rate prediction. Consequently, the features input into the input layer cannot only consider natural factors. Therefore, in this invention, when predicting river flow, relevant features of the hydropower station are additionally input into the MLP neural network model, enabling the MLP neural network model to comprehensively consider the influence of both natural and human factors.
[0070] Specifically, during the power generation process of a hydropower station, the power generation is positively correlated with the water flow passing through the station. Furthermore, the power generation of a hydropower station is positively correlated with the electricity consumption of the region it serves. Therefore, by collecting data on the electricity consumption of the region by the hydropower station, the water flow passing through the station can be determined. In addition, some special cases need to be considered. For example, different drought and flood conditions upstream of the hydropower station will lead to different water storage and release strategies, which will also affect the downstream flow. Taking this factor into account, the water level difference between the upstream and downstream of the hydropower station can be used as one of the features input to the input layer.
[0071] Therefore, the two additional input features—the electricity consumption of the hydropower station in the application area and the water level difference between the upstream and downstream of the hydropower station—take into account the impact of the hydropower station's operation and the impact of the hydropower station's water storage and release strategies. Under the combined effect of these two additional features, the MLP neural network model can make the prediction results of river flow more accurate.
[0072] In step S2.2, forward propagation refers to the process of signal transmission from the input layer to the output layer. In each layer, each neuron multiplies the output of the previous layer with its corresponding weight, sums the results using an activation function, and then activates the neuron to obtain its output. In this invention, the sigmoid function is used as the activation function. This output can be used as the input to the next layer of neurons. In this invention, the loss function used in model training can be the mean squared error, and its formula is:
[0073] ;
[0074] In the above formula, yi represents the actual observed value. This represents the model's predicted value. E represents the value of the loss function. N represents the number of samples.
[0075] In step S2.3, the goal of model training is to adjust the network parameters by minimizing the value of the loss function. During forward propagation, the neural network propagates the input sample data sequentially along the network layers until the output layer produces the prediction result. The specific steps are as follows: The input values of the input layer are initialized with the sample data. Then, for each neuron in the hidden and output layers, a weighted input is calculated and converted into an output value through an activation function. The output value is used as the input value for the next layer, and the above steps are repeated until the output layer is reached. The output value of the output layer is the prediction result. For the l-th layer (l=1 is the input layer), the weighted input of the i-th neuron is:
[0076] ;
[0077] In the above formula, Z(l, i) represents the weighted input value of the i-th neuron in the l-th layer. W(l, i, j) represents the weight connecting the j-th neuron in the previous layer and the i-th neuron in the current layer in the l-th layer. A(1-1, j) represents the output value of the j-th neuron in the (l-1)-th layer. B(l, i) represents the bias value of the i-th neuron in the l-th layer.
[0078] The weighted input is converted into an output value using the sigmoid activation function, as shown in the following formula:
[0079] .
[0080] In step S2.4, backpropagation refers to adjusting the connection weights of each neuron in the network based on the error between the predicted result and the true label, and propagating the updated weights layer by layer from the output layer to the input layer. This can be achieved using the gradient descent algorithm. The weights of each neuron are updated according to the gradient of the loss function. During backpropagation, the gradient of the loss function needs to be calculated to update the weights.
[0081] First, calculate the error of the output layer:
[0082] ;
[0083] In the above formula, delta(L) represents the error of the Lth layer; then, based on the magnitude of the error, the error of each layer is calculated layer by layer:
[0084] ;
[0085] The above steps require multiple iterations of training, with continuous adjustment of weights, until predetermined stopping conditions are met, including reaching the maximum number of iterations or the loss function converging. Based on this, an optimal algorithm is used to dynamically adjust the weights of each neuron in the neural network to reduce errors and improve prediction accuracy.
[0086] Based on the characteristics of hydrological data and the basic theory of MLP neural networks, the size of the input layer is determined. If we use hydrological data from the past n days to predict the flow rate for the next day, then the input dimension is n. A sigmoid activation function is used to enhance the model's nonlinear fitting ability. The final output layer is determined based on the intended purpose of the task. If predicting the flow rate for the next day, the output layer dimension is 1. During the training and learning phases, appropriate optimization algorithms need to be selected and relevant parameters updated.
[0087] In this invention, the PSO algorithm is selected to optimize the MLP neural network model. The PSO algorithm, also known as Particle Swarm Optimization, is a swarm intelligence optimization algorithm that simulates the search behavior of birds and fish. Particles are used as the solution objects in the MLP neural network, and their weights and biases are represented by their positions. Based on this, a fitness function is defined to evaluate the prediction accuracy of the neural network. Step S3 specifically includes the following steps:
[0088] Step S3.1: Initialize the particle swarm; use the particle positions to represent the weights and biases of the MLP network, and initialize the particle velocities and positions; typically, the initial positions of the particles can be randomly generated, and the initial velocities of the particles can be set empirically.
[0089] Step S3.2: Update the particle velocity and position, and update the weights and biases of the MLP network based on the new particle positions; specifically, the formula for calculating the particle update velocity is:
[0090] ;
[0091] Among them, v i t+1 v represents the velocity of the i-th particle at time t+1. i t Let represent the velocity of the i-th particle at time t, w be the inertia weight, c1 and c2 be learning factors, r1 and r2 be random numbers, pi be the historical best position of the i-th particle, pg be the global best position, and x be the velocity of the i-th particle at time t. i t This represents the position of the i-th particle at time t;
[0092] The formula for calculating the updated position of a particle is:
[0093] ;
[0094] Where, x i t+1 This represents the position of the i-th particle at time t+1;
[0095] Step S3.3: Fitness Evaluation; Define a fitness function to evaluate the prediction accuracy of the neural network, update the individual optimal position and global optimal position of each particle based on the fitness value; select the minimum mean square error as the optimal fitness function;
[0096] Step S3.4: Repeat the speed update, position update, and fitness evaluation until the stopping conditions are met, including reaching the maximum number of iterations or the fitness reaching a certain threshold.
[0097] The PSO algorithm can gradually optimize the weights and biases of an MLP neural network, thereby continuously improving the fitness of the MLP neural network on the training set and achieving better model performance.
[0098] In the PSO algorithm, the value of the inertia weight w directly affects its convergence speed. A larger inertia weight w results in a stronger global search capability but a slower convergence speed. Conversely, a smaller inertia weight w leads to higher convergence accuracy but makes the algorithm more prone to getting trapped in local optima.
[0099] Therefore, in order to ensure that the PSO algorithm has both strong global search capabilities and high convergence accuracy in the end, the inertia weight w is usually dynamically valued during the iteration process. That is, the inertia weight w is set to a higher value in the early stage to enable strong global search capabilities in the early stage. Then, as the number of iterations increases, the inertia weight w gradually decays to enable higher convergence accuracy in the later stage.
[0100] In this invention, the PSO-optimized MLP model is used to predict hydrological flow data. For river regions, the rate of change of river flow differs significantly between the rainy and dry seasons. During the rainy season, the river flow is more likely to change abruptly, while during the dry season, the rate of change of river flow is smaller.
[0101] To address this, the present invention optimizes the value selection strategy for the inertia weight w. During the iteration process, the value of the inertia weight w decreases with the increase of the number of iterations, and the rate of decrease of the inertia weight w is negatively correlated with the recent rate of change in river flow. Thus, during the rainy season, when the river is in a period of high flow variation, the rate of decrease of the inertia weight w can be slowed down, maintaining the exploration capability to cope with sudden changes; during the dry season, when the river is in a period of low flow variation, convergence can be accelerated, the number of iterations shortened, and the local convergence accuracy improved.
[0102] In one embodiment, the formula for determining the inertia weight w is as follows:
[0103] ;
[0104] ;
[0105] ;
[0106] Where wmin is the lower limit of the inertia weight, for example, 0.4; wmax is the upper limit of the inertia weight, for example, 0.9; ΔQ(t) is the flow rate change rate; λ(ΔQ) is the decay rate coefficient; λbase is the base decay rate; ΔQmax is the historical maximum flow rate change rate; N is the sliding window length; It is the average flow rate within the window.
[0107] For seasonal rivers, the flow fluctuates dramatically during the rainy season, resulting in a high ΔQ(t). Therefore, the decay rate of the inertial weight w decreases, allowing w to remain at a higher level, leading to stronger global search capabilities and easier detection of flood peaks. During the dry season, the flow is stable, ΔQ(t) is lower, w decays rapidly, resulting in faster convergence and higher local convergence accuracy. Through this method, the present invention can dynamically adjust the value strategy of the inertial weight w according to the differences between the rainy and dry seasons of a river, demonstrating stronger flood peak prediction capabilities during the rainy season and shorter convergence iterations during the dry season.
[0108] To evaluate the optimization effect of the PSO algorithm on the MLP neural network model, this invention compares the PSO-optimized MLP model, the unoptimized MLP model, and the BP model.
[0109] Appendix Figure 2 The charts in the table show water level, flow velocity, discharge, precipitation, and evaporation data for a specific inland river region during different time periods from January 1, 2021 to December 30, 2021. Data collection covered hydrological flow data from January 1, 2021 to December 30, 2021. Data was collected hourly, and Table 1 shows only a portion of the hydrological data. This data was used as samples for prediction by an MLP neural network model, and a portion of the dataset was categorized into training, validation, and test sets. Hydrological flow prediction relies on the use of an MLP neural network to obtain feature values from the data; these feature values are analyzed to obtain certain patterns for predicting hydrological flows. (Appendix) Figure 3 The charts in the image show the characteristic values of the MLP after the hydrological data has been transformed. (See attached...) Figure 3 The data shows that after the model processes hydrological flow features, the data characteristics become relatively uniform. Feature extraction and transformation of the input hydrological data can improve the model's performance and generalization ability.
[0110] After acquiring and preprocessing hydrological data, a PSO model was used to optimize the parameters of the MLP neural network model, initializing the position and velocity of each particle in the particle swarm, as well as the individual optimal solution and the global optimal solution for each particle. A portion of the training set was selected to train the MLP neural network, and the model parameters were updated by adjusting the position and velocity of each particle in the particle swarm until a stopping condition was reached. Figure 4 The charts in the diagrams show some of the parameters used to evaluate the experimental setup.
[0111] Based on the experimental structure, during training, after optimizing the neural network model using the PSO algorithm, the model's fitness also changes with the number of iterations. (Appendix) Figure 5 This demonstrates the changes in fitness during the experiment. (From the appendix...) Figure 5 It can be seen that the fitness of the PSO-optimized MLP model changes continuously with the number of iterations. When the number of iterations is greater than 10, the fitness value gradually stabilizes, remaining relatively stable between 40 and 50 iterations. Therefore, choosing 50 iterations for the experiment is reasonable. After using the PSO-optimized MLP neural network model, the predicted results of hydrological flow changes in the region were obtained, such as... Figure 6 and Figure 7 As shown.
[0112] Figure 6 and Figure 7 The hydrological flow prediction performance of different algorithms was tested. Figure 6 This demonstrates a comparison of prediction results between an MLP model optimized using the PSO algorithm and an unoptimized MLP model. Figure 7 The comparison of prediction results between the MLP model optimized using the PSO algorithm and the BP model is presented, along with actual hydrological flow data for the region over 12 months in 2021.
[0113] Since there is a lack of significant comparisons of the predicted hydrological flows for 12 months in the figure, the hydrological flows for July and December were selected for comparison with the predicted values. Figure 6 and Figure 7Overall data shows that the hydrological flow predicted by the MLP model optimized by PSO is closer to the actual hydrological flow value. From the predicted data for July and December, it can be seen that the hydrological flow in this region in July is 2238 cubic meters per second. The MLP model optimized by PSO predicts 2238.48 cubic meters per second, while the unoptimized MLP model predicts 2229.87 cubic meters per second. The BP neural network predicts 2237 cubic meters per second. The hydrological flow in this region in December is 978 cubic meters per second. The MLP model optimized by PSO predicts 977.24 cubic meters per second, while the unoptimized MLP model predicts 950.49 cubic meters per second. The BP neural network predicts 979 cubic meters per second. It can be concluded that the MLP model optimized by PSO has more accurate predictions and smaller prediction errors, followed by the BP neural network.
[0114] Appendix Figure 8 , 9 In Section 10, the performance of three algorithms in predicting flow error values across 30 hydrological flow data samples was tested. The comparison revealed that the MLP model optimized by PSO exhibited the best hydrological flow prediction performance, with relatively smaller fluctuations in flow prediction error values and a smaller overall error range. Furthermore, compared to the BP model, the MLP model had a larger error.
[0115] In addition, in algorithm performance evaluation, MAE (mean absolute error), MAPE (mean absolute percentage error), RMSE (root mean square error), and algorithm iteration time are used as indicators to measure and compare the actual application effect of the algorithm.
[0116] MAE (Modular Value Exceeded) measures the accuracy of a model's predictions. Unlike other metrics, MAE is unaffected by outliers because it focuses only on the absolute value of the difference between the predicted and actual values. When comparing the performance of different models, MAE can be used as an evaluation metric to select the best model.
[0117] MAPE is a metric used to evaluate the accuracy of predictive models. MAPE measures the relative error between predicted and actual values, making it particularly suitable for predictive tasks involving percentages or proportions. The formula for calculating MAPE is as follows:
[0118] ;
[0119] In the above formula, MAPE represents the mean absolute percentage error, n represents the total number of data points, pv represents the actual value, and tv represents the predicted value.
[0120] RMSE is a mean error metric used to measure the difference between predicted and actual values from a regression model. It is a commonly used indicator to evaluate the accuracy of regression models; a lower RMSE value indicates better model performance. Based on predicted hydrological flow values for the region over 12 months in 2021, their MAE, MAPE, RMSE, and algorithm iteration time were calculated. Statistical analysis was performed on the 12 sets of data, and their mean-variance plots are presented.
[0121] The MAE values of the three algorithm models are compared in the appendix. Figure 11 As shown, attached Figure 11 The results show that the average MAE error of the PSO-optimized MLP model is approximately 0.245; the average MAE error of the unoptimized MLP model is approximately 0.398; and the average MAE error of the BP model is approximately 0.349.
[0122] A comparison of the MAPE values of the three algorithm models is attached. Figure 12 As shown, attached Figure 12 The results show that the average MAPE error of the PSO-optimized MLP model is approximately 0.015; the average MAPE error of the unoptimized MLP model is approximately 0.032; and the average MAPE error of the BP model is approximately 0.022.
[0123] The RMSE values of the three algorithm models are compared below. Figure 13 As shown, attached Figure 13 The results show that the RMSE error of the PSO-optimized MLP model is relatively small, averaging about 0.128. The unoptimized MLP model has the highest RMSE error, averaging 0.184, while the average RMSE error of the BP model is about 0.180.
[0124] The algorithm iteration times of the three algorithm models are compared in the appendix. Figure 14 As shown, attached Figure 14 The results show that the PSO-optimized MLP model requires a shorter iteration time to predict hydrological flows, with an average iteration time of 149 milliseconds. The average iteration time of the unoptimized MLP is approximately 185 milliseconds, while the average iteration time of the BP model is 167 milliseconds.
[0125] Based on the specific comparison results above, the PSO-optimized MLP model achieves more ideal results compared to the unoptimized MLP model and the BP model.
[0126] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm, characterized in that: Includes the following steps: Step S1: Collect hydrological flow data and preprocess the hydrological flow data; Step S2: Construct an MLP neural network model and input hydrological flow data into the MLP neural network model for iterative training; Step S3: Optimize the weights and biases of the MLP neural network model using the PSO algorithm; Step S3 specifically includes the following steps: Step S3.1: Initialize the particle swarm; use the particle positions to represent the weights and biases of the MLP network, and initialize the particle velocities and positions; Step S3.2: Update the particle velocity and position, and update the weights and biases of the MLP network according to the new particle position; Step S3.3: Fitness evaluation; Define a fitness function to evaluate the prediction accuracy of the neural network, and update the individual optimal position and global optimal position of each particle based on the fitness value; Step S3.4: Repeat the velocity update, position update, and fitness evaluation until the stopping condition is met; In step S3.2, the formula for calculating the particle renewal rate is: ; Among them, v i t+1 v represents the velocity of the i-th particle at time t+1. i t Let represent the velocity of the i-th particle at time t, w be the inertia weight, c1 and c2 be learning factors, r1 and r2 be random numbers, pi be the historical best position of the i-th particle, pg be the global best position, and x be the velocity of the i-th particle at time t. i t This represents the position of the i-th particle at time t; The formula for calculating the updated position of a particle is: ; Where, x i t+1 This represents the position of the i-th particle at time t+1; During the iteration process, the value of the inertia weight w decreases with the increase of the number of iterations, and the rate of decrease of the inertia weight w is negatively correlated with the rate of change of the recent river flow; the formula for the value of the inertia weight w is as follows: ; ; ; Where wmin is the lower bound of the inertia weight, wmax is the upper bound of the inertia weight, ΔQ(t) is the flow rate change rate, λ(ΔQ) is the decay rate coefficient, λbase is the base decay rate, ΔQmax is the historical maximum flow rate change, and N is the sliding window length. It is the average flow rate within the window.
2. The method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm according to claim 1, characterized in that: In step S1, outliers in the hydrological flow data are detected and processed using the quartile method, missing values in the hydrological flow data are filled using linear interpolation or mean filling methods, and the hydrological flow data are smoothed using the moving average method.
3. The method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm according to claim 1, characterized in that: Step S2 specifically includes the following steps: Step S2.1: Determine the grid structure of the MLP neural network model; for the input layer, determine the number of nodes in the input layer based on the number of input features; for the hidden layer, select an appropriate number of hidden layer neurons and activation function; for the output layer, determine the number of nodes in the output layer based on the prediction target. Step S2.2: Perform forward propagation; input the preprocessed hydrological data into the MLP model, calculate the weighted input, convert the weighted input into the output through the activation function, and finally the output value of the output layer is the predicted hydrological flow value; Step S2.3: Adjust network weights by minimizing the loss function; Step S2.4: Backpropagation; Calculate the error of the output layer, calculate the error of each layer according to the error magnitude, and finally update the weights based on the error and the learning rate.
4. The method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm according to claim 3, characterized in that: In step S2.1, the features input by the input layer include one or more of water level, flow rate, flow rate, precipitation, and evaporation.
5. The method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm according to claim 3, characterized in that: In step S2.1, for river areas with upstream hydropower stations, the features input by the input layer include water level, flow velocity, flow rate, precipitation, evaporation, electricity consumption of the hydropower station in the application area, and the water level difference between the upstream and downstream of the hydropower station. The output layer outputs the flow rate of the river area.
6. The method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm according to claim 3, characterized in that: In step S2.2, the activation function is the Sigmoid function.
7. The method for predicting hydrological flow using an MLP neural network model based on the PSO algorithm according to claim 3, characterized in that: In step S2.3, the mean squared error is used as the loss function.