River short-term flow prediction method based on time sequence

The ROA algorithm optimizes the gating mechanism and adaptive activation function of the LSTM model, and introduces an attention mechanism to build the ROA-LSTM model, which solves the problem of difficulty in parameter optimization and insufficient prediction accuracy in river flow prediction, achieving higher prediction accuracy and robustness.

CN120069149APending Publication Date: 2025-05-30NANJING UNIV OF INFORMATION SCI & TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411900292.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-23
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

The existing LSTM model has difficulty in optimizing parameters, easy to fall into local optimal solutions, inflexible adjustment of learning rate and neuron count, and neglecting time dependence, resulting in insufficient prediction accuracy.

Method used

The ROA algorithm is used to optimize the gating mechanism and adaptive activation function of the LSTM model, and combined with the attention mechanism, the ROA-LSTM model is built, the learning rate and number of neurons are optimized, and the long-term dependence modeling ability and nonlinear relationship capture ability of the model on time series data.

Benefits of technology

The accuracy of river short-term flow prediction is improved, the robustness and generalization ability of the model are enhanced, the prediction error rate is significantly reduced, and the accuracy rate is increased by more than three times.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120069149A_ABST
    Figure CN120069149A_ABST
Patent Text Reader

Abstract

The invention discloses a river short-term flow prediction method based on a time sequence, and the method employs an attention mechanism to improve the attention of different time steps based on a conventional LSTM time sequence prediction model, enables the resources in the model to be efficiently applied, and improves the flow prediction performance of the model. An ROA algorithm is adopted to optimize the gating mechanism of the LSTM model, so that the long-term dependence modeling capability of the model on time sequence data is enhanced, and the gradient disappearance problem can be effectively avoided; the ROA algorithm is adopted to carry out parameter adjustment on the adaptive activation function in the LSTM model, and the ability of the model to capture a nonlinear relationship is improved, so that the generalization ability and robustness of the LSTM in a prediction task are enhanced. According to the method, the ROA-LSTM joint model is constructed, so that the flow change of the river in a short period can be accurately predicted, the fluctuation trend of the flow change is more sensitively reflected, and the prediction of the peak value is more accurate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical fields of river flow prediction and deep learning, and particularly relates to a short-term river flow prediction method based on time series. Background Art

[0002] Accurate river flow prediction plays a key role in water resources management, providing important support for decision-making on water resources allocation, reservoir operation, flood control measures, and drought mitigation strategies. Reservoir operation relies on water flow prediction to make decisions on water release and storage, in order to balance downstream demands, flood control, and ecological protection. During drought periods, accurate inflow prediction helps to actively manage water resources supply, implement water conservation measures, restrict water use, and explore alternative water sources. Accurate river flow prediction can also ensure sustainable water supply for communities and ecosystems, helping to reduce risks, optimize water resources reserves, and promote efficient water resources management practices.

[0003] Traditional river flow prediction methods are divided into two types: physical models and mathematical models. Physical models are usually based on physical laws and require a large amount of measurement data for calibration and verification. A comprehensive and detailed understanding of the river basin is needed. The complexity of the model and the large amount of required data lead to high prediction costs. Mathematical models rely on historical flow data and other relevant variables and require high-precision time series data. When the data presents linear characteristics, the model has good effects, but it has weak processing ability for non-linear data and is difficult to cope with complex flow changes.

[0004] With the introduction of data-driven models, significant progress has been made in river flow prediction. These models evaluate historical flow data and use computational methods such as machine learning (ML) and artificial intelligence (AI) to reveal patterns and correlations. In the field of hydrological flow prediction, models such as Recurrent Neural Network (RNN), Gated Recurrent Unit (GRU), and Convolutional Neural Networks (CNN) are used to predict flow. In response to the problems existing in hydrological flow prediction, many experts and scholars have conducted research and proposed some feasible models.Widia sari et al. (Widia sari I R, Nugoho L E, Efendi R. Context-based hydrology time series data for a flood prediction model using LSTM[C]. 2018 5th International Conference on Information Technology, Computer, and Electrical Engineering (ICITACEE). IEEE, 2018: 385-390.) applied the traditional Long Short-Term Memory (LSTM) model to small watersheds to achieve flow prediction. However, the general LSTM model showed problems of insufficient accuracy in predicting the river flow of large watersheds such as the Yangtze River; Liwei Zhou (Zhou L, Kang L. A comparative analysis of multiple machine learning methods for flood routing in the Yangtze River[J]. Water, 2023, 15(8): 1556.) applied six models including support vector regression, Gaussian process regression, and long short-term memory to predict the Yangtze River flow. Although the reliability of the LSTM model was verified, due to the nonlinear characteristics of the flow data, the prediction performance of this model decreased severely, lacking effective optimization means to cope with complex nonlinear flow changes; Yuanyuan Man (Man Y, Yang Q, Shao J, et al. Enhanced LSTM model for daily runoff prediction in the upper Huai River Basin, China[J]. Engineering, 2023, 24: 229-238.) proposed an enhanced LSTM model, which improved the impact caused by data nonlinearity in the flow prediction of the Huai River Basin and alleviated the problem of the decline in measurement prediction performance. However, this method ignored the impact of parameters such as the learning rate and the number of neurons in the LSTM model on the model performance.)

[0005] The above research demonstrated the feasibility of the LSTM model in river basin prediction. However, the general LSTM model mostly relies on heuristic methods for parameter optimization, which is prone to falling into local optimal solutions and fails to fully explore the parameter space, resulting in the model performance not reaching the best. At the same time, the learning rate and the number of neurons in the model cannot be flexibly adjusted, which may lead to insufficient model training or overfitting, affecting the prediction accuracy. When dealing with time series data, the time dependence between data is ignored, reducing the prediction accuracy. Summary of the Invention

[0006] In view of the above problems, the present invention proposes a short-term river flow prediction method based on time series, which is used to realize the short-term prediction of river flow and improve the accuracy of flow prediction.

[0007] The present invention adopts the following technical solutions: A short-term river flow prediction method based on time series, including:

[0008] Step S1: Obtain the original data, including river flow data and water level height data, and perform preprocessing, normalization, and division of the corresponding data on the original data.

[0009] Step S2: Initialize the LSTM model, initialize the ROA algorithm, learning rate, and the number of neurons, use the ROA algorithm to improve the gating mechanism and adaptive activation function of the LSTM model, and at the same time optimize the learning rate, the number of neurons, and the individual parameters of a single neuron;

[0010] Step S3: Construct the overall ROA-LSTM model, introduce the attention mechanism, improve the attention degree of different time steps of the LSTM model, optimize the minimum loss function through model training, and gradually adjust the parameters of the ROA-LSTM model;

[0011] Step S4: After meeting the maximum number of iterations, output the optimal ROA-LSTM model parameter solution, combine the attention improvement mechanism, input the test set into the trained ROA-LSTM model, and output the prediction result to complete the prediction of the short-term river flow.

[0012] Preferably, in step S1, the water flow velocity of the river cross-section is obtained by using the transceiver integrated acoustic tomography flow measurement system arranged on both banks of the river, and the river flow data can be calculated from the cross-sectional area, and the real-time water level height data of the river is measured by a water level gauge. After preprocessing and normalizing the river flow and water level height as the original data, the time period is divided into a training set and a test set from front to back.

[0013] Preferably, in step S2, LSTM (Long Short-Term Memory model) is a special RNN (Recurrent Neural Network). The internal neurons of LSTM are composed of four parts: forget gate (f r )), input gate (it )、Cell state (C t ) and output gate (O t ). The adaptive activation functions include the Sigmoid function layer and the tanh hyperbolic tangent curve function layer, and the LSTM neural network is used as the main part of the model.

[0014] Among them, the ROA (Manta Ray Foraging Optimization Algorithm) is based on the core symbiotic strategy and the WOA (Whale Optimization Algorithm), SFO (Sailfish Optimization Algorithm) to perform position update and foraging (converging to the target). The position update is based on the SFO algorithm, and the switching of positions requires empirical accumulation judgment. The foraging stage is based on the WOA algorithm, aiming to find individuals with successful foraging, and comparing fitness to obtain the required optimal solution.

[0015] The ROA algorithm is used to optimize the gating mechanism and the adaptive activation function tanh of the LSTM model respectively.

[0016] In terms of the gating mechanism, the weight matrices W and the bias vectors b of the forget gate (f r ), input gate (i t ), and cell state (C t ) in the LSTM model are respectively initialized to form a population, and at the same time, the individual position information (the initial values of W and b) is initialized; the number of neurons in the input layer and the hidden layer is set; the fitness of each move is calculated, and according to judge whether it is necessary to continue the iterative calculation to update the position information, where X i is the position of individual i, X att is the tentative move, f(X att ) are respectively and the fitness values of X att ; after reaching the maximum number of iterations, it ends, and the optimal parameter solution is obtained, which is used as the optimization result of the gating mechanism in the LSTM model, and the weights and biases of the LSTM are adjusted to better adapt to the changing rules of time series data.

[0017] In terms of the activation function, ROA realizes the parameter adjustment of the adaptive activation function by continuously iterating the parameter combination of the activation function tanh, and improves the model's ability to capture nonlinear relationships.

[0018] Optimize and improve the ROA algorithm, use the learning rate and the number of neurons in the LSTM neural network as the joint search space, and adopt the joint search method in parallel to optimize the learning rate and the number of neurons. Iterate multiple times to find the optimal solution, and use the optimal solution as the optimal number of neurons and the optimal learning rate to optimize the convergence speed of the model and ensure the stability of the model.

[0019] Preferably, in step S3, an attention mechanism is used to improve the attention of the ROA-LSTM model at different time steps, and the steps are as follows:

[0020] S3.1. Process the input data based on the LSTM model to obtain the state h of the hidden layer t , h t is the feature representation at each time step;

[0021] S3.2. Introduce an attention mechanism into the hidden state, and initialize a learnable context vector s, which is used to focus on the importance of different time steps;

[0022] S3.3. Use the core Score function in the attention mechanism to operate each hidden state with the learnable context vector s to obtain an unnormalized score, which is normalized by the Softmax function.

[0023] S3.4. Weightedly sum the attention weights α t of the time stamps with h t , replace the output of the original LSTM, and perform loop training. By optimizing the minimum loss function, gradually adjust the model parameters, which helps the model filter out interference, focus on key areas, and improve the robustness of the ROA-LSTM model.

[0024] Preferably, in step S4, the preprocessed traffic data is input into the constructed ROA-LSTM model. After meeting the maximum number of iterations, the optimal parameter solution is output. Use the mean absolute error (MAE), root mean square error (RSME), and error rate between the predicted value and the true value as evaluation indicators to evaluate the improved ROA-LSTM model. And verify its effectiveness by comparing with LSTM and GRU. Finally, input the test set into the model that has been verified to be effective to obtain the predicted water flow result, and complete the prediction of the short-term river flow.

[0025] The technical solution of the present invention also provides: an electronic device, including:

[0026] One or more processors;

[0027] A storage device, on which one or more programs are stored;

[0028] When the one or more programs are executed by the one or more processors, the one or more processors implement the above-mentioned time-series-based short-term river flow prediction method.

[0029] The technical solution of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it implements the steps in any of the above-mentioned time-series-based short-term river flow prediction methods.

[0030] Compared with the prior art, the present invention adopts the above technical solutions and has the following technical effects:

[0031] 1. The short-term river flow prediction method of the present invention makes improvements and innovations for river flow prediction on the traditional LSTM time series prediction model. The attention mechanism is adopted to improve the attention of the model at different time steps, so that the resources in the model are efficiently utilized, and the flow prediction performance of the model is improved; the ROA algorithm is adopted to optimize the gating mechanism of the LSTM model, which enhances the long-term dependence modeling ability of the model for time series data and can effectively avoid the problem of gradient disappearance; the ROA algorithm adjusts the parameters of the adaptive activation function tanh in the LSTM model, which improves the ability of the model to capture non-linear relationships, thereby enhancing the generalization ability and robustness of the LSTM in the prediction task; by constructing a ROA-LSTM joint model, the short-term flow changes of the river can be accurately predicted, the flow change fluctuation trend can be more sensitively reflected, and the prediction of the peak value is more accurate.

[0032] 2. After comparing the errors of the short-term river flow prediction method based on the ROA-LSTM model of the present invention with those of the traditional LSTM model and GRU model, it is found that: the prediction error rate of the improved ROA-LSTM model is only 5.20%, compared with 15.21% of the traditional LSTM model, the prediction accuracy is tripled, and compared with 8.85% of the GRU model, it is increased by more than 1.5 times, having higher prediction accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 It is a flowchart for constructing the ROA-LSTM algorithm model of the present invention;

[0034] Figure 2 It is a schematic diagram of the hydroacoustic flow measurement device for obtaining the original data of the embodiment of the present invention;

[0035] Figure 3 It is a structural diagram of the basic LSTM model of the present invention;

[0036] Figure 4 It is a flowchart for optimizing the parameters by the ROA algorithm of the present invention;

[0037] Figure 5 It is an LSTM model improved by the attention mechanism of the present invention;

[0038] Figure 6 It is a comparison diagram of the predicted value and the true value output by the present invention;

[0039] Figure 7 It is a comparison diagram of the predicted values and the true values of the ROA-SLTM model, LSTM model and GRU model of the present invention;

[0040] Figure 8 This is a comparison chart of the MAE, RMSE, and error rate of the ROA-SLTM model of the present invention with LSTM and GRU. Detailed implementation manner

[0041] In order to make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions of the application will be further elaborated in detail below with reference to the accompanying drawings. The described embodiments are only a part of the embodiments involved in the present invention. All non-innovative embodiments of other researchers in the field based on this embodiment fall within the protection scope of the present invention. At the same time, for the step numbers in the embodiments of the present invention, they are only set for the convenience of elaboration and explanation, and no limitation is imposed on the order between the steps. The execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.

[0042] Aiming at the problem of short-term prediction of river water flow, the present invention proposes a short-term river flow prediction method based on time series, which overcomes the problems of difficult parameter selection and easy to fall into local optimal solutions in time series prediction by traditional LSTM models. By combining the ROA optimization algorithm improved by the WOA algorithm and the SFO algorithm with the attention mechanism, a time series prediction combined model ROA-LSTM based on the ROA optimization algorithm and the LSTM model is constructed.

[0043] In an embodiment of the present invention, in combination with Figure 1 , the steps of the river short-term flow prediction method are as follows:

[0044] First step, obtain the original data, perform preprocessing, normalization, and divide the corresponding data.

[0045] Preferably, the acquisition of the original data adopts a remotely controllable transceiver-integrated acoustic tomography flow measurement system as Figure 2 shown. This flow measurement system combines acoustic imaging technology and utilizes the propagation characteristics of sound waves in water to achieve high-resolution reconstruction of flow velocity information. By arranging the flow measurement devices on both sides of the river bank at a certain angle respectively, the acoustic reciprocity time is obtained by the underwater transducers emitting sound waves to each other, and the cross-sectional flow velocity of the river is calculated by combining ray acoustics and the Doppler effect, so as to accurately obtain the distribution of the flow velocity inside the water body.

[0046] Furthermore, multiplying the cross-sectional area of the river by the cross-sectional flow velocity can calculate and obtain the flow rate data. In addition, a synchronous water level gauge is equipped to collect the river water level data in real time to obtain the water level change of the river.

[0047] During the data acquisition process, in order to ensure the accuracy of the measurement results, the collected original data is subjected to multiple steps of cleaning and preprocessing, including filtering background noise, removing abnormal data points, and using waveform smoothing technology to eliminate environmental interference.

[0048] Record the river flow and water level data within several days, and map the data to the interval of [0, 1] through the normalization formula. The normalization formula is:

[0049]

[0050] In formula (1), represents the normalized data value, x(i) represents the original data of the variable, and x max represents the maximum value in the original data; x min represents the minimum value in the original data. Divide the original data into a training set and a test set at a ratio of 7:3. The data used as the training set is used to train and adjust the model weight values and coefficients, and the test set is used to obtain the predicted output quantity as the input after the model is trained.

[0051] In this embodiment, the data of the first 3 days is used to predict the data of the next 1 - 3 days, and the error calculation and comparative analysis are performed between the prediction result and the true value, including the absolute error, root mean square error, and error rate between the prediction result and the true value.

[0052] Second step, initialize the LSTM model, and initialize the ROA algorithm, learning rate, and number of neurons; improve the gating mechanism and adaptive activation function tanh of the LSTM model through the ROA algorithm; use the ROA algorithm to optimize the learning rate, number of neurons, and individual neuron parameters.

[0053] Combined with Figure 3 , the LSTM model in this embodiment is a special recurrent neural network (RNN). Compared with the traditional RNN, the LSTM can effectively capture the relationship between long - term sequences and alleviate the problems of gradient vanishing and explosion.

[0054] The internal neurons of the LSTM are composed of four parts: forget gate (f r ), input gate (i t ), cell state (C t ), and output gate (O t ); tanh is the hyperbolic tangent activation function, and the forget gate f r is calculated as:

[0055] f r = σ(W f (h t-1 , x t ) + b y ) (2)

[0056] In formula (2), W f is the forget gate weight, b y is the bias; σ is the Sigmoid activation function, x t is the input, ht-1 is the output of the previous moment. After being operated by the activation function, the value of the formula is constrained within (0, 1).

[0057] Input X t and h t-1 Through the forget gate operation, the result is a vector of 0 or 1. 0 represents the part to be forgotten, and 1 represents the part of the memory to be retained. Input gate i t is:

[0058] i t = σ[W fi (h t-1 , x t ) + b i (3)

[0059] In formula (3), W fi is the input gate weight, and b i is the offset of the input gate.

[0060] Different from other neural networks, σ is the Sigmoid activation function. Cell state C t is:

[0061] C t = tanh[W c (h t-1 , x t + b c )] (4)

[0062] In formula (4), b c is the offset of C t , and W C is the cell state gate weight.

[0063] The data passes through the output gate to obtain the hidden layer state variable O t , and the calculation is:

[0064] O t = σ[W 0 (h t-1 , x t ) + b 0 (5)

[0065] h t = O t * tanh(C t ) (6)

[0066] In formulas (5) and (6), W 0 is the output gate weight, b 0 is the output gate offset, h t is the hidden state, and O tis the hidden layer state variable. In this embodiment, the Remora Optimization Algorithm (ROA) is based on the core symbiotic strategy and the Whale Optimization Algorithm (WOA) and the Sailfish Optimizer (SFO) to perform global and local position updates and foraging.

[0067] The formula for initializing the remora population position is:

[0068] X i = lb + rand × (ub - lb) (7)

[0069] In Equation (7), X i is the position of individual i, ub and lb are the lower and upper bounds in the search space, and rand is a random number between 0 and 1. The position update is based on the SFO algorithm, and the switching of positions requires empirical accumulation judgment. The expression is:

[0070]

[0071] In Equation (8), X att is the tentative move, X pre represents the position of the previous generation, and randn is a random number between 0 and 1.

[0072]

[0073] H(i) = round(rand) (10)

[0074] Equation (9) is used to determine whether to switch hosts. f(X att ) are respectively and X att 's fitness values. In Equation (10), H(i) determines the host, and round is a rounding function. The foraging stage is based on the WOA algorithm, and its position information is:

[0075]

[0076]

[0077] In Equation (11), and are the next-level and current remora positions, and A is the distance the remora moves. In Equation (12), A is the distance the remora moves, B simulates the host volume, C is the restricted position parameter, rand is a number between 0 - 1, and X BThe individual with successful foraging is est, that is, the current optimal solution. Repeat the above steps, compare the fitness to obtain the required optimal solution, and take the last one as the optimization result of the gating mechanism in the LSTM model, and adjust the weights and biases of the LSTM to better adapt to the changing rules of time series data.

[0078] Specifically, in step 2, in the optimization of the gating mechanism of the LSTM by the ROA algorithm, the weight matrices W and bias vectors b of the three gates are respectively initialized to form a population according to equation (7), and at the same time, the individual position information (the initial values of W and b) is initialized; the number of neurons in the input layer and the hidden layer is set; the fitness of each move is calculated, and it is judged according to equation (9) whether it is necessary to continue the iterative calculation to update the position information, and it ends after reaching the maximum number of iterations to obtain the optimal parameter solution.

[0079] The optimized weight matrix increases the weight values on multiple information amounts, improving the high sensitivity to input features. In addition, the ROA continuously iterates the parameter combination of the adaptive activation function tanh to improve the model's ability to capture non-linear relationships, achieving the optimization of the activation function.

[0080] Combined with Figure 4 , in step 2, when using the ROA algorithm to optimize the learning rate and the number of neurons in the LSTM model, the learning rate and the number of neurons are used as the joint search space, and the joint search method in parallel is used to optimize the learning rate and the number of neurons. The specific optimization process is as follows:

[0081] (1) Interpolate, denoise, normalize the original data, divide the dataset to set the range and initial solution, and set the search ranges of the LSTM learning rate and the number of neurons.

[0082] (2) Model configuration and fitness evaluation: Initialize the population size of the ROA algorithm, configure the LSTM according to the parameter combination of each eel fish, train the model and record the fitness value, which is measured by the loss function.

[0083] (3) Generate and compare the reverse solutions: Generate reverse solutions (L i,op and N i,op ) for each eel fish, calculate their fitness values, compare the fitness of the reverse solutions with the current solutions, and retain the solutions with higher fitness. The reverse solutions are:

[0084] L i,op = L best - (L i - L best ) (13)

[0085] N i,op = N best - (N i - N best ) (14)

[0086] In equations (13) and (14), L best , N best represent the current optimal learning rate and the number of neurons. L i , N i represent the learning rate and the number of neurons of the i-th individual. The evaluation metrics of the training set and the test set are fused as the fitness function, and the fitness is defined as:

[0087]

[0088] In equation (15), m and n are the number of samples, y i is the actual value, and y x is the predicted value.

[0089] (4) Update the position of the solution: Update the position of each according to the fitness to make it approach the optimal solution. This process gradually adjusts the learning rate and the number of neurons by controlling the step size, and the update formula is as follows:

[0090] A t+1 = A t + r(A best - A t ) (16)

[0091] In equation (16), A t is the current individual position information, A t+1 is the updated individual position information, A bt is the current optimal position information, and r is a random factor used to control the step size.

[0092] (5) Iterative optimization and convergence: Repeat the above process until the fitness value reaches the maximum number of iterations, find the optimal solution, which is used as the optimal number of neurons and the optimal learning rate to optimize the convergence speed of the model and ensure the stability of the model.

[0093] Thirdly, introduce the attention mechanism, optimize the minimum loss function, and gradually adjust the model parameters.

[0094] Combined with Figure 5 , after the LSTM processes the input data, the state h t of the hidden layer is obtained, and h t is the feature representation at each time step. Introduce the attention mechanism into the hidden state, initialize a learnable context vector s, and s is used to focus on the importance of different time steps. Use the core Score function in the attention mechanism to operate each hidden state with the learnable context vector s to obtain a normalized score. There are usually three operation methods:

[0095]

[0096] socre(h t ,s) = v T tanh(W[h t ; s]) (18)

[0097]

[0098] In Eqs. (18) and (19), W is a trainable weight matrix, v is a trained vector. The scores at each time step are normalized by the Softmax function. The Softmax expression is:

[0099]

[0100] In Eq. (20), α t is the attention weight at time stamp t, score(h t ,s) is the time stamp score, and T is the total length of the sequence. Calculate the probability distribution of the key (Key) for the vector s and transfer it to the value (Value) to obtain the corresponding weight α t . Finally, replace the output of the original LSTM with the weighted sum of α t and h t . Continuously loop and train. By optimizing the minimum loss function and gradually adjusting the model parameters, it helps the model filter out interference and focus on key areas, thereby improving the model's robustness.

[0101] Fourthly, after meeting the maximum number of iterations, output the optimal parameter solution. Combine the attention improvement mechanism, input the test set into the trained ROA-LSTM model, and output the prediction result to complete the short-term prediction of water flow.

[0102] Furthermore, combine Figure 6 and Figure 7 to measure the flow and water level data of the Jingjiang section of the Yangtze River from May 15, 2024 to May 27, 2024 for a total of 17,280 minutes. Use 12,096 pieces of data as the training set. The data used as the training set is used to train and adjust the model weight values and coefficients. After training the model, 5,184 pieces of data are used as the test set, and the data of the first 3 days are used to predict the data of the next 1 - 3 days.

[0103] Compare the prediction results with the true values. At the same time, use the traditional LSTM model (Comparison 1) and the GRU model (Comparison 2) to predict the flow respectively. Analyzing the data shows that Figure 7 at Point 1 and Point 2, the prediction model constructed by ROA-LSTM is more sensitive to the changing trend of flow fluctuations, and at Point 3, the optimized model shows more accurate peak prediction.

[0104] Comparative analysis of root mean square error, mean absolute error, and the error rate of the prediction errors of different models compared with the measured values, the results are as Figure 8 shown.

[0105] Among them, the mean absolute error (MAE) represents the degree of agreement between the test value and the true value. Define the predicted value of the test set sample as y 1 , and the true value as y 2 , n is the number of samples, and its calculation formula is:

[0106]

[0107] The root mean square error (RMSE) represents the deviation between the predicted value and the true value, and its calculation formula is:

[0108]

[0109] The prediction error of the model optimized by the ROA algorithm is 5.2%. The prediction accuracy is increased by 3 times compared with the unoptimized LSTM model and more than 1.5 times compared with the GRU model, showing a good fitting effect. It can be seen that this embodiment combines the improved ROA optimization algorithm and the attention mechanism, and constructs a ROA-LSTM time series water flow prediction combined model through the optimization and improvement of the LSTM neural network, which has higher prediction performance, can accurately predict the flow changes of the river within three days, more sensitively reflect the fluctuation trend of the flow changes, and is also more accurate in predicting the peak value.

[0110] In an embodiment of the present invention, an electronic device is further provided, including: one or more processors; a storage device on which one or more programs are stored; when the one or more programs are executed by the one or more processors, the one or more processors implement the above-mentioned short-term river flow prediction method based on time series.

[0111] In an embodiment of the present invention, a computer-readable storage medium is further provided, on which a computer program is stored, and when the program is executed by a processor, the steps in the above-mentioned short-term river flow prediction method based on time series are implemented.

[0112] The above are only the preferred embodiments of the present invention. It should be noted that: for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.

Claims

1. A method for predicting short-term river flow based on time series, characterized in that: The steps include: Step S1, obtaining original data, including river flow data and water level height data, and preprocessing, normalizing, and dividing the original data into corresponding data; Step S2, initializing the LSTM model, initializing the ROA algorithm, the learning rate and the number of neurons, using the ROA algorithm to improve the gating mechanism and adaptive activation function of the LSTM model, and optimizing the learning rate, the number of neurons and the individual parameters of a single neuron; Step S3, construct the overall ROA-LSTM model, introduce the attention mechanism, improve the attention of different time steps of the LSTM model, optimize the minimum loss function through model training, and gradually adjust the ROA-LSTM model parameters; Step S4: After the maximum number of iterations is met, the optimal ROA-LSTM model parameter solution is output. Combined with the attention improvement mechanism, the test set is input into the trained ROA-LSTM model, the prediction result is output, and the prediction of river flow in the short term is completed.

2. The method for predicting short-term river flow based on time series according to claim 1 is characterized in that: In step S1, a transceiver-transmitter acoustic tomography flow measurement system is deployed on both sides of the river to obtain the water flow velocity of the river cross section, and the river flow data is calculated from the cross-sectional area; the real-time water level height data of the river is measured by a water level gauge; the river flow data and water level height data are taken as raw data, which are preprocessed and normalized and then divided into a training set and a test set.

3. The method for predicting short-term river flow based on time series according to claim 2 is characterized in that: In step S1, the training set is used to train and adjust the model weights and coefficients, and the test set is used as input to obtain the predicted output after model training. The river flow data and water level height data of the previous three days are used to predict the river flow data of the next day, and the error calculation and comparative analysis of the predicted results and the true values ​​are performed, including the absolute error, the root mean square error and the error rate between the predicted results and the true value.

4. The method for predicting short-term river flow based on time series according to claim 1 is characterized in that: In step S2, the internal neurons of the LSTM model include: a forget gate f r , input gate i t , cell state C t , output gate O t ; The adaptive activation function includes: Sigmoid activation function and tanh hyperbolic tangent curve activation function; The ROA algorithm performs global and local position updates and foraging based on the core symbiotic strategy, the WOA algorithm and the SFO algorithm; the position update is based on the SFO algorithm, and position switching is performed based on experience accumulation; the foraging is based on the WOA algorithm, which searches for successful foraging individuals, compares fitness, and obtains the optimal solution.

5. The method for predicting short-term river flow based on time series according to claim 4 is characterized in that: In step S2, the ROA algorithm is used to optimize the gating mechanism of the LSTM model as follows: S201, initialize the weight matrices W and bias vectors b of the three gates of the forget gate, input gate, and cell state in the LSTM model to form a population, and obtain Initial individual positions of fish population: X i =lb+rand×(ub-lb); Among them, X i is the position of individual i, ub and lb are the lower and upper bounds of the search space, and rand is a random number between 0 and 1; S202, initializing LSTM model parameters, including: setting the number of neurons in the input layer and hidden layer; S203, updating the position based on the SFO algorithm: Among them, X att For exploratory movement, X pre Indicates the previous generation position, X i is the position of individual i, the superscript t represents time, and randn is a random number between 0 and 1; S204, calculate the fitness of each movement, determine whether it is necessary to switch hosts, and continue to iterate and calculate to update the position information: H(i) = round(rand); in, f(X att ) are respectively With X att The fitness value of; H(i) is used to determine the host, and round is the rounding function; S205, the foraging phase is based on the WOA algorithm, and the location information is: in, and For the next level and current Fish position, A is The distance the fish moves, B simulates the host volume, C is the limit position parameter, X Best The individual that successfully forages is the current optimal solution; S206. Repeat steps S202, S203, S204, and S205. After reaching the preset maximum number of iterations, compare the fitness to obtain the optimal parameter solution, which is used as the optimization result of the gating mechanism in the LSTM model to adjust the weight and bias of the LSTM.

6. The method for predicting short-term river flow based on time series according to claim 4 is characterized in that: In step S2, the ROA algorithm is used to optimize the learning rate and the number of neurons of the LSTM model. The learning rate and the number of neurons are used as the joint search space, and the parallel joint search method is used to optimize the learning rate and the number of neurons. The method is as follows: S211. Based on the preprocessed raw data, set the learning rate and neuron number search range of the LSTM model; S212, initialize the ROA algorithm population size, according to each The parameter combination of the fish configures the LSTM model, trains the model and records the fitness value, which is measured by the validation set loss function; S213, for each The reverse solution of fish generation L i,op and N i,op , calculate the fitness value, compare the fitness of the reverse solution with the current solution, and retain the solution with higher fitness. The reverse solution is: L i,op =L best -(L i -L best ); N i,op =N best -(N i -N best ); Among them, L best 、N best Represents the current optimal learning rate and number of neurons, L i 、N i Represents the learning rate and number of neurons of individual i; S214, the evaluation indicators of the training set and the test set are integrated as the fitness function, and the fitness fit is defined as: Among them, m and n are the number of samples, y i is the actual value, y x is the predicted value; S215, update the position of each solution according to the fitness, approach the optimal solution, and gradually adjust the learning rate and the number of neurons by controlling the step size. The update formula is as follows: A t+1 =A t +r(A best -A t ); Among them, A t is the current individual location information, A t+1 is the updated individual location information, A best is the current optimal position information, r is a random factor used to control the step size; S216. Repeat steps S212, S213, S214, and S215 until the fitness value reaches the preset maximum number of iterations, and find the optimal solution as the optimal number of neurons and the optimal learning rate to optimize the convergence speed of the LSTM model.

7. The method for predicting short-term river flow based on time series according to claim 4 is characterized in that: In step S3, the attention mechanism is used to improve the attention of different time steps of the ROA-LSTM model as follows: S3.

1. After processing the input data based on the LSTM model, the state h of the hidden layer is obtained t ,h t is the feature representation for each time step; S3.2, introduce the attention mechanism in the hidden state and initialize the learnable context vector s, s is used to focus on the importance of different time steps; S3.3, using the core Score function in the attention mechanism, each hidden state is calculated with the learnable up and down vectors s to obtain a score, which is normalized by the Softmax function; S3.

4. The attention weight α of the timestamp t With h t The weighted sum is used to replace the output of the original LSTM model, and the training is repeated. By optimizing the minimum loss function, the ROA-LSTM model is improved, the model parameters are gradually adjusted, interference is filtered out, and the focus is on key areas to improve the robustness of the model.

8. The method for predicting short-term river flow based on time series according to claim 7 is characterized in that: In step S4, the preprocessed river flow data is input into the constructed ROA-LSTM model, and the absolute error, root mean square error and error rate with the true value are used as evaluation indicators to evaluate the improved ROA-LSTM model. The effectiveness of the ROA-LSTM model is verified by comparing it with LSTM and GRU, and the test set is input into the verified effective model to obtain the predicted water flow results.

9. An electronic device, characterized in that: include: one or more processors; a storage device having one or more programs stored thereon; When the one or more programs are executed by the one or more processors, the one or more processors implement the time series-based short-term river flow prediction method as described in any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the program is executed by a processor, the steps in the method for predicting short-term river flow based on time series described in any one of claims 1 to 8 are implemented.