River water quality prediction method based on IGWO-LSTM

By improving the Gray Wolf algorithm to optimize the hyperparameters of the LSTM model, the problem of superparameters easily falling into local optimization and limited prediction accuracy in river water quality prediction is solved, and higher prediction accuracy and generalization capabilities are achieved.

CN119441729APending Publication Date: 2025-02-14SHENYANG UNIVERSITY OF TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411516572.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-02-14

AI Technical Summary

Technical Problem

In the prediction of river water quality, traditional LSTM models have problems such as hyperparameters easily fall into local optimal solutions and limited prediction accuracy and generalization capabilities.

Method used

A river water quality prediction method based on IGWO-LSTM is proposed. By improving the gray wolf algorithm, the mixed chaotic sequence Tent-Logistic is introduced in the initialization process of population, and nonlinear control parameters and dynamic weight update strategy are introduced during the search iteration process to optimize Hyperparameters of LSTM model.

Benefits of technology

It effectively avoids the problem of manual parameter adjustment time and local optimization, improves the prediction accuracy and generalization ability of the model, and can better capture long-term dependencies and periodic changes in time series data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119441729A_ABST
    Figure CN119441729A_ABST
Patent Text Reader

Abstract

The invention provides a river water quality prediction method based on IGWO-LSTM. The method comprises the following steps: extracting monitored water quality index data; performing feature selection based on the preprocessed water quality data to obtain water quality feature data; generating a river water quality prediction data set; dividing the data set into a training set, a verification set and a test set; carrying out pre-training on the constructed LSTM model; a mixed chaotic sequence Tent-Logistic is introduced in the initialization process of the grey wolf population; dividing grey wolf individuals according to the generated fitness function, performing optimization searching through the grey wolf individuals, and introducing nonlinear control parameters in a search iteration process; a dynamic weight updating strategy based on a fitness function is introduced in the search iteration process of grey wolf individuals; an IGWO-LSTM model is constructed; inputting the training set into an IGWO-LSTM model for iterative training; the verification set is input into the IGWO-LSTM model after iteration training for optimization; and inputting the test set into the final optimized model to obtain a prediction result of the river water quality. According to the method, the long-term dependency relationship and periodic change in the time sequence data can be better captured, historical information can be reserved, and more accurate river water quality prediction can be carried out in the future.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of river water quality prediction, and in particular to a river water quality prediction method based on IGWO-LSTM. Background Art

[0002] Water is an indispensable basic element on Earth and is vital to all living things, including humans, animals, vegetables and plants. Without water, the Earth will not be able to sustain life. Currently, the deterioration of river water quality has a significant impact on the health of surface water and its tributary ecosystems, which in turn increases the challenge of sustainable use of water resources. Therefore, the development and application of water quality prediction technology and the qualitative and quantitative analysis of river water environment quality have become key means to ensure water environment safety and rational development and protection of water resources.

[0003] In recent years, various artificial intelligence technologies have been applied to the field of water quality prediction. Among them, the prediction of river water quality using memory neural networks takes the river water quality status information as the research object, and uses historical data to predict the spatiotemporal status of water quality in the future based on its spatiotemporal distribution characteristics. For example, a time series prediction technology: Long Short Term Memory (LSTM) neural network can make more accurate predictions of long-series water quality status. However, in practical applications, the traditional LSTM model still has certain limitations when dealing with water quality prediction problems. For example, when dealing with complex water environments, its hyperparameters are prone to fall into local optimal solutions, and the prediction accuracy and generalization ability are limited. Therefore, we urgently need to establish a prediction model that improves LSTM to predict river water quality, so as to effectively improve the prediction accuracy of the model. Summary of the invention

[0004] In view of the insufficient prediction ability of the above-mentioned neural network water quality prediction method, the present invention provides an improved group optimization algorithm to achieve the purpose of optimizing the LSTM neural network and improve its prediction accuracy for river water quality data.

[0005] To this end, the purpose of the present invention is to propose a river water quality prediction method based on IGWO-LSTM.

[0006] In order to achieve the above-mentioned purpose, the technical solution of the present invention provides a river water quality prediction method based on IGWO-LSTM. The prediction method includes: step S1: extracting monitoring water quality index data from a water quality monitoring site; step S2: preprocessing the extracted monitoring water quality index data; step S3: performing feature selection based on the preprocessed water quality data to obtain water quality characteristic data; step S4: normalizing the water quality characteristic data, and then using a sliding window tool to slice the normalized water quality characteristic data to generate a data set for river water quality prediction; step S5: dividing the data set for river water quality prediction into a training set, a validation set and a test set according to a preset ratio; step S6: constructing an LSTM model, inputting the training set into the LSTM model for pre-training, and evaluating the prediction performance of the trained LSTM model; step S7: improving the gray wolf algorithm so that the mixed chaotic sequence Tent-Logistic is introduced during the initialization of the gray wolf population; step S8: generating a fitness function based on the prediction error in the prediction performance; step Step S9: Divide the gray wolf individuals according to the fitness function, then perform optimization search through the gray wolf individuals, and introduce nonlinear control parameters in the search iteration process to adjust the global optimization and local optimization capabilities of the gray wolf population; Step S10: In the search iteration process of the gray wolf individuals, introduce a dynamic weight update strategy based on the fitness function; Step S11: Output the optimal solution after the improved gray wolf algorithm iteration stops, and construct an IGWO-LSTM river water quality prediction model according to the optimal hyperparameters corresponding to the optimal solution; Step S12: Input the training set into the IGWO-LSTM river water quality prediction model for iterative training. After the iterative training is completed, input the verification set into the iteratively trained IGWO-LSTM river water quality prediction model for optimization, and save the final optimized model; Step S13: Input the test set into the final optimized model to obtain the prediction result of the river water quality, and use the evaluation index to evaluate the prediction performance of the final optimized model.

[0007] Preferably, the step S2 specifically includes: step S2.1: using the K-nearest neighbor method to find the K most similar samples to the monitoring water quality index data whose missing values ​​need to be supplemented, and using the average value of the most similar K samples to fill the missing values; step S2.2: using the isolation forest algorithm to process abnormal data; step S2.3: using the Pearson correlation coefficient to calculate the correlation between the time series and the monitoring water quality index data processed by the isolation forest algorithm, and organizing the calculated Pearson correlation coefficient into a correlation matrix; wherein each element in the correlation matrix represents the correlation coefficient between the time series and the monitoring water quality index data processed by the isolation forest algorithm; step S2.4: based on the size of the correlation matrix and the correlation coefficient, obtaining the monitoring water quality index data with a higher correlation with the time series.

[0008] Preferably, the step S4 specifically includes: step S4.1: applying the minimum-maximum normalization method to the water quality characteristic data, i.e. first finding the maximum and minimum values ​​for each water quality parameter in the water quality characteristic data, and then limiting the value corresponding to each water quality characteristic data to between 0 and 1; step S4.2: according to the periodicity of the water quality characteristic data, using a sliding window tool to slice the normalized water quality characteristic data to generate a data set for river water quality prediction; wherein, a window with a length close to the period is selected for data segmentation, each window is regarded as a sample, the data in the window is regarded as a time series, and all samples are converted into a three-dimensional array; the first dimension represents the number of samples, the second dimension represents the number of time steps, and the third dimension represents the number of features for each time step.

[0009] Preferably, the step S7 specifically includes: improving the gray wolf algorithm so that in the process of initializing the gray wolf population, a hybrid chaotic sequence Tent-Logistic that integrates the Tent chaotic sequence and the Logistic sequence is introduced, and the formula is expressed as follows:

[0010]

[0011] In formula (1), x h+1 and x h is the individual position of the wolf pack; r is in the range of (0,4], which means that within the value range of r, the system is in a chaotic state.

[0012] Preferably, the step S9 specifically includes: updating the individual positions of the wolf pack according to the fitness function, and introducing a nonlinear control parameter a based on a tangent function in the search iteration process, which is expressed as follows:

[0013]

[0014] In formula (2), a maxis the maximum value of the control parameter; a min is the minimum value of the control parameter; t is the current iteration number; t max is the maximum number of iterations.

[0015] Among them, when the improved grey wolf algorithm starts to execute, the decreasing rate of a is small, which increases the global search capability; in the later stage of the execution of the improved grey wolf algorithm, the decreasing rate of a is large, which improves the convergence rate of the algorithm's local optimization problem.

[0016] Preferably, the step S10 is specifically as follows: during the search iteration process of the gray wolf individual, a position update weight ω based on the fitness function is introduced. i , in order to give wolves with better fitness values ​​higher position update rights, the formula is as follows:

[0017]

[0018] In formula (3), α, β, and δ are the weights of the wolf; α s , β s ,δ s are the fitness values ​​of α, β, and δ wolves respectively;

[0019] Among them, the better the fitness function value, the greater the fitness value of the corresponding wolf individual; after each iteration, the fitness value of each updated wolf is re-evaluated, that is, the performance of the LSTM model corresponding to the new hyperparameter combination is re-evaluated, and α wolf, β wolf and δ wolf are updated according to the fitness value. When the set maximum number of iterations is reached, or when the fitness value no longer decreases significantly, the improved gray wolf algorithm stops iterating, and it is considered that the relatively optimal hyperparameter combination has been found.

[0020] Beneficial effects of the present invention:

[0021] (1) The river water quality prediction method provided by the present invention is based on the IGWO-LSTM model, which is a new river water quality prediction model based on a time series memory neural network. Compared with the traditional river water quality prediction model, the IGWO-LSTM model can better capture the long-term dependencies and periodic changes in time series data, and can also retain historical information and make more accurate river water quality predictions for the future.

[0022] (2) The river water quality prediction method based on IGWO-LSTM provided by the present invention optimizes the LSTM neural network algorithm by using the IGWO group optimization algorithm, which effectively avoids the time of manual parameter adjustment and the problem of falling into the local optimality. The global search mechanism of IGWO can jump out of the local optimality and find a better hyperparameter combination of LSTM. In addition, when processing data with more data noise, the IGWO algorithm can also find the global optimal solution through algorithm iteration and always maintain good prediction performance.

[0023] The above-mentioned beneficial technical effects make the IGWO-LSTM prediction model more accurate and reliable in river water quality prediction.

[0024] Additional aspects and advantages of the invention will become apparent from the following description, or may be learned by practice of the invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] Figure 1 A schematic flow chart of a river water quality prediction method based on IGWO-LSTM according to an embodiment of the present invention is shown;

[0026] Figure 2 A schematic diagram showing the workflow of the IGWO-LSTM river water quality prediction model according to an embodiment of the present invention is shown;

[0027] Figure 3a A schematic diagram showing a comparison of the MAPE evaluation index in the performance evaluation of the LSTM initial model and the optimized IGWO-LSTM model on four water quality indicators of dissolved oxygen (COD, mg / L), PH, ammonia nitrogen (NH3-N, mg / L), and total phosphorus (TP, mg / L) according to an embodiment of the present invention;

[0028] Figure 3b A schematic diagram showing the comparison of MAE evaluation indicators in the performance evaluation of the LSTM initial model and the optimized IGWO-LSTM model on four water quality indicators of dissolved oxygen (COD, mg / L), PH, ammonia nitrogen (NH3-N, mg / L), and total phosphorus (TP, mg / L) according to an embodiment of the present invention;

[0029] Figure 3c A schematic diagram showing the comparison of RMSE evaluation indicators in the performance evaluation of the LSTM initial model and the optimized IGWO-LSTM model in four water quality indicators of dissolved oxygen (COD, mg / L), pH, ammonia nitrogen (NH3-N, mg / L), and total phosphorus (TP, mg / L) according to an embodiment of the present invention;

[0030] Figure 3dThe performance evaluation of the LSTM initial model and the optimized IGWO-LSTM model of an embodiment of the present invention on four water quality indicators: dissolved oxygen (COD, mg / L), pH, ammonia nitrogen (NH3-N, mg / L), and total phosphorus (TP, mg / L) is shown in Figure 1. 2 Schematic diagram of the comparison of evaluation indicators;

[0031] Figure 4 A schematic diagram showing a comparison between the prediction results of the IGWO-LSTM model of an embodiment of the present invention on a validation set and the prediction of the original data for the next 7 days is shown. DETAILED DESCRIPTION

[0032] In order to more clearly understand the above-mentioned objectives, features and advantages of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.

[0033] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Therefore, the protection scope of the present invention is not limited to the specific embodiments disclosed below.

[0034] Figure 1 FIG. 1 is a schematic flow chart of a river water quality prediction method based on IGWO-LSTM according to an embodiment of the present invention. Figure 1 As shown, the river water quality prediction method based on IGWO-LSTM includes:

[0035] Step S1: extracting monitoring water quality index data from a water quality monitoring site;

[0036] Step S2: preprocessing the extracted monitoring water quality index data;

[0037] Step S3: performing feature selection based on the pre-processed water quality data to obtain water quality feature data;

[0038] Step S4: normalizing the water quality characteristic data, and then using a sliding window tool to slice the normalized water quality characteristic data to generate a data set for river water quality prediction;

[0039] Step S5: dividing the river water quality prediction data set into a training set, a validation set and a test set according to a preset ratio;

[0040] Step S6: construct an LSTM model, input the training set into the LSTM model for pre-training, and evaluate the prediction performance of the trained LSTM model;

[0041] Step S7: improving the gray wolf algorithm so that a mixed chaotic sequence Tent-Logistic is introduced during the gray wolf population initialization process;

[0042] Step S8: generating a fitness function according to the prediction error in the prediction performance;

[0043] Step S9: Divide the gray wolf individuals according to the fitness function, and then perform optimization search through the gray wolf individuals, and introduce nonlinear control parameters in the search iteration process to adjust the global optimization and local optimization capabilities of the gray wolf population;

[0044] Step S10: In the process of searching and iterating by the individual gray wolf, a dynamic weight updating strategy based on the fitness function is introduced;

[0045] Step S11: outputting the optimal solution after the improved grey wolf algorithm stops iterating, and constructing the IGWO-LSTM river water quality prediction model according to the optimal hyperparameters corresponding to the optimal solution;

[0046] Step S12: input the training set into the IGWO-LSTM river water quality prediction model for iterative training. After the iterative training is completed, input the validation set into the iteratively trained IGWO-LSTM river water quality prediction model for optimization, and save the final optimized model;

[0047] Step S13: Input the test set into the final optimized model to obtain the prediction result of river water quality, and use the evaluation index to evaluate the prediction performance of the final optimized model.

[0048] In this embodiment, the river water quality prediction method provided by the present invention is based on the IGWO-LSTM model, which is a new river water quality prediction model based on a time series memory neural network. Compared with the traditional river water quality prediction model, the IGWO-LSTM model can better capture the long-term dependencies and periodic changes in time series data, and can also retain historical information and make more accurate river water quality predictions for the future.

[0049] Furthermore, the river water quality prediction method based on IGWO-LSTM provided by the present invention optimizes the LSTM neural network algorithm by using the IGWO group optimization algorithm, which effectively avoids the time of manual parameter adjustment and the problem of falling into the local optimality, and the global search mechanism of IGWO can jump out of the local optimality and find a better hyperparameter combination of LSTM; in addition, when processing data with more data noise, the IGWO algorithm can also find the global optimal solution through algorithm iteration and always maintain good prediction performance.

[0050] In one embodiment of the present invention, the step S2 specifically includes: step S2.1: using the K-nearest neighbor method to find the K most similar samples to the monitoring water quality index data that need to supplement missing values, and using the average value of the most similar K samples to fill the missing values; step S2.2: using the isolation forest algorithm to process abnormal data; step S2.3: using the Pearson correlation coefficient to calculate the correlation between the time series and the monitoring water quality index data processed by the isolation forest algorithm, and organizing the calculated Pearson correlation coefficient into a correlation matrix; wherein each element in the correlation matrix represents the correlation coefficient between the time series and the monitoring water quality index data processed by the isolation forest algorithm; step S2.4: based on the size of the correlation matrix and the correlation coefficient, obtaining the monitoring water quality index data with a higher correlation with the time series.

[0051] In one embodiment of the present invention, the step S4 specifically includes: step S4.1: applying the minimum-maximum normalization method to the water quality characteristic data, namely, first finding the maximum and minimum values ​​of each water quality parameter in the water quality characteristic data, and then limiting the value corresponding to each water quality characteristic data to between 0 and 1; step S4.2: according to the periodicity of the water quality characteristic data, using a sliding window tool to slice the normalized water quality characteristic data to generate a data set for river water quality prediction; wherein, a window with a length close to the period is selected for data segmentation, each window is regarded as a sample, the data in the window is regarded as a time series, and all samples are converted into a three-dimensional array; the first dimension represents the number of samples, the second dimension represents the number of time steps, and the third dimension represents the number of features for each time step.

[0052] In one embodiment of the present invention, step S7 is specifically: improving the gray wolf algorithm so that in the process of initializing the gray wolf population, a hybrid chaotic sequence Tent-Logistic that integrates the Tent chaotic sequence and the Logistic sequence is introduced, and the formula is expressed as follows:

[0053]

[0054] In formula (1), x h+1 and x h is the individual position of the wolf pack; r is in the range of (0,4], which means that within the value range of r, the system is in a chaotic state.

[0055] In one embodiment of the present invention, the step S9 is specifically as follows: updating the individual positions of the wolf pack according to the fitness function, and introducing a nonlinear control parameter a based on a tangent function in the search iteration process, which is expressed as follows:

[0056]

[0057] In formula (2), a max is the maximum value of the control parameter; a min is the minimum value of the control parameter; t is the current iteration number; t max is the maximum number of iterations.

[0058] Among them, when the improved grey wolf algorithm starts to execute, the decreasing rate of a is small, which increases the global search capability; in the later stage of the execution of the improved grey wolf algorithm, the decreasing rate of a is large, which improves the convergence rate of the algorithm's local optimization problem.

[0059] In one embodiment of the present invention, step S10 is specifically as follows: during the search iteration process of the gray wolf individual, a position update weight ω based on a fitness function is introduced. i , in order to give wolves with better fitness values ​​higher position update rights, the formula is as follows:

[0060]

[0061] In formula (3), α, β, and δ are the weights of the wolf; α s , β s , δ s are the fitness values ​​of α, β, and δ wolves respectively;

[0062] Among them, the better the fitness function value, the greater the fitness value of the corresponding wolf individual; after each iteration, the fitness value of each updated wolf is re-evaluated, that is, the performance of the LSTM model corresponding to the new hyperparameter combination is re-evaluated, and α wolf, β wolf and δ wolf are updated according to the fitness value. When the set maximum number of iterations is reached, or when the fitness value no longer decreases significantly, the improved gray wolf algorithm stops iterating, and it is considered that the relatively optimal hyperparameter combination has been found.

[0063] The technical solution of the present invention will be demonstrated below with a specific embodiment. The specific implementation steps of the river water quality prediction method based on IGWO-LSTM of the present invention are as follows:

[0064] Step 1: Extract monitoring water quality index data from the water quality monitoring station of the Liaohe River in Shenyang; the monitoring water quality index data is monitored every 4 hours and includes 9 monitoring indicators;

[0065] Step 2: Preprocess the extracted monitoring water quality index data. First, use the K-nearest neighbor method to find the K most similar samples to the monitoring water quality index data that need to supplement the missing values, and use their average value to fill the missing values; then use the isolation forest algorithm to process the abnormal data, and then use the Pearson correlation coefficient to calculate the correlation between time and the monitoring water quality index data processed by the isolation forest algorithm according to the relationship between the water quality data and the time series, and organize the calculated Pearson correlation coefficient into a correlation matrix; wherein each element in the correlation matrix represents the correlation coefficient between the time series and the monitoring water quality index data processed by the isolation forest algorithm; according to the size of the correlation matrix and the correlation coefficient, the monitoring water quality index data with a higher correlation with the time series is obtained, that is, the features with a higher correlation with the time series are selected as the input of the model, and finally four features of dissolved oxygen (COD, mg / L), PH, ammonia nitrogen (NH3-N, mg / L), and total phosphorus (TP, mg / L) are selected;

[0066] Step 3: Normalize the water quality characteristic data to ensure that data of different magnitudes are converted to the same magnitude. The minimum-maximum normalization method is used for the water quality characteristic data, that is, first find the maximum and minimum values ​​of each water quality parameter in the water quality characteristic data, and then limit the values ​​corresponding to each water quality characteristic data to between 0 and 1. The specific normalization formula is:

[0067] X′=(XX min ) / (X max -X min ) (4)

[0068] In formula (4), X represents the original data; X′ represents the normalized value; the value range of X is between the minimum value min and the maximum value max of the input parameter;

[0069] Furthermore, according to the periodicity of water quality characteristic data, the sliding window tool is used to slice the normalized water quality characteristic data to generate a data set for river water quality prediction; specifically, according to the periodicity of water quality characteristic data, a window with a length close to the period is selected for data segmentation, each window is regarded as a sample, and the data in the window is regarded as a time series, and all samples are converted into a three-dimensional array; where the first dimension represents the number of samples, the second dimension represents the number of time steps, and the third dimension represents the number of features for each time step. Each window contains 24 hours of data, with 4 features per hour, so the shape of the input data is (n, 24, 4), and the input samples are divided into a test set, a training set, and a validation set in a ratio of 8:1:1;

[0070] Steps 4 to 7: Combine Figure 2The workflow diagram of the IGWO-LSTM river water quality prediction model is used to show the specific implementation process, such as Figure 2 The specific workflow is as follows:

[0071] First, build an LSTM model for pre-training (i.e., build an initial LSTM model). Specifically, initialize the LSTM input parameters, set the number of neurons in each hidden layer to 64, the learning rate to 0.001, the time step to 24, and the number of LSTM layers to 2. Use the training set for 20-50 rounds of iterative training. If the loss function no longer decreases during the iteration process, stop training, and then use the root mean square error as the loss function to evaluate the performance of the initial LSTM model.

[0072] Furthermore, the gray wolf population is initialized (i.e., the gray wolf algorithm parameters are initialized). Specifically, the initial population size is set to 30, the maximum number of iterations is 100, and then the hyperparameter range to be optimized is defined, the number of hidden layer neurons is [32, 256], the learning rate is [0.0001, 0.01], the number of LSTM layers is [1, 3], and the batch size is [16, 128];

[0073] Furthermore, in the step of implementing the improved gray wolf algorithm, the wolf group position must first be initialized, so that in the process of gray wolf population initialization, the mixed chaotic sequence Tent-Logistic method of mixed Tent chaotic sequence and Logistic sequence is used to initialize the individual positions of the wolf group, which can ensure the diversity of the initial population and make it evenly distributed in the search space. The formula is as follows:

[0074]

[0075] In formula (1), x h+1 and x h is the individual position of the wolf pack; r is in the range of (0,4], which means that within the value range of r, the system is in a chaotic state.

[0076] Logistic and Tent chaotic sequences have certain complementarity in distribution characteristics and search capabilities. The probability of taking values ​​in the middle of the Logistic chaotic sequence is relatively uniform, but the probability is higher at both ends; the mixed sequence can make the distribution of the initial population of gray wolves more uniform and stable, so that the algorithm has a faster search speed and generates a more efficient initial population;

[0077] Each individual gray wolf represents a hyperparameter combination of the LSTM model. Each individual dimension corresponds to four hyperparameters to be optimized, namely the number of hidden layer neurons, the learning rate, the number of LSTM layers, and the batch size. The position of each wolf can be represented as a four-dimensional vector.

[0078] Furthermore, a fitness function is generated based on the prediction error in evaluating the prediction performance of the trained LSTM model. The fitness of each wolf is measured by the prediction error of the LSTM model, and the root mean square error (RMSE) is selected as the fitness function; for each individual, an LSTM model is constructed and trained according to its hyperparameter combination, the model is trained using training data, and the RMSE of the model is evaluated using test data. The smaller the RMSE, the better the fitness. The expression of the fitness function is:

[0079]

[0080] In formula (5), y i is the actual data value, is the predicted data value of the model, and N is the number of samples corresponding to each batch of training data or test data when adjusting the LSTM model.

[0081] According to the generated fitness function, the gray wolf individuals are divided, the positions of the gray wolf individuals are updated, and then the optimization search is carried out through the gray wolf individuals, that is, whether the maximum number of iterations is reached or whether the fitness value converges; at the same time, nonlinear control parameters are introduced in the search iterative process to adjust the global optimization and local optimization capabilities of the gray wolf population.

[0082] Specifically, the positions of α, β, and δ wolves are determined. α wolf is the best solution found so far, with the lowest RMSE. β wolf and δ wolf are the second and third best solutions, respectively. The remaining wolves (ω wolves) update their positions and move closer to α, β, and δ wolves.

[0083] In the gray wolf optimization process, since the algorithm itself is prone to fall into the local optimum, the individual positions of the wolf pack are updated according to the fitness function. In the search iteration process, a nonlinear control parameter a based on the tangent function is introduced to improve the optimization ability. The specific formula is as follows:

[0084]

[0085] In formula (2), a max is the maximum value of the control parameter; a min is the minimum value of the control parameter; t is the current iteration number; t max is the maximum number of iterations.

[0086] Among them, when the improved grey wolf algorithm starts to execute, the decreasing rate of a is small, which increases the global search capability; in the later stage of the execution of the improved grey wolf algorithm, the decreasing rate of a is large, which improves the convergence rate of the algorithm's local optimization problem.

[0087] Due to the averaging mechanism of the original gray wolf algorithm, it is difficult for individuals in the population to approach the optimal solution, which in turn affects the convergence rate and global optimization performance of the algorithm. Therefore, the position update weight ω based on fitness is introduced.i , giving wolves with better fitness a higher position update right, gradually adjusting the hyperparameter position of each wolf to move them in the direction of better fitness. The algorithm simulates the hunting process of gray wolves, so that each wolf pack individual gradually updates its position around the current optimal individual (α wolf), that is, adjusts the hyperparameter value. The specific formula is as follows:

[0088]

[0089] In formula (3), α, β, and δ are the weights of the wolf; α s , β s ,δ s are the fitness values ​​of α, β, and δ wolves respectively; the better the fitness, the larger the corresponding fitness value;

[0090] Among them, the better the fitness function value, the greater the fitness value of the corresponding wolf individual; after each iteration, the fitness value of each updated wolf is re-evaluated, that is, the performance of the LSTM model corresponding to the new hyperparameter combination is re-evaluated, and α wolf, β wolf and δ wolf are updated according to the fitness value. When the set maximum number of iterations is reached, or when the fitness value no longer decreases significantly, the improved gray wolf algorithm stops iterating, and it is considered that the relatively optimal hyperparameter combination has been found.

[0091] Each wolf updates its position according to the following formula:

[0092] X(T+1)=(ω a X a +ω β X β +ω δ X δ ) (6)

[0093] In formula (6), X α , X β , X δ Respectively represent the positions of α, β, and δ wolves in the iteration; T represents the number of iterations; ω α Denoted as α, the position update weight of the wolf; ω β Denoted as β wolf position update weight; ω δ Denoted as δ wolf position update weight;

[0094] After each iteration, the fitness of each updated wolf, that is, the LSTM model performance of the new hyperparameter combination, is re-evaluated, and the α wolf, β wolf, and δ wolf (representing the top three optimal individuals, respectively) are updated according to the RMSE value. When the set maximum number of iterations is reached, or when the RMSE is no longer significantly reduced, IGWO stops iterating, and it is considered that the relatively optimal hyperparameter combination has been found.

[0095] Step 8: Use the improved gray wolf algorithm to find the optimal hyperparameter combination; specifically, perform optimization search through gray wolf individuals, that is, determine whether the maximum number of iterations has been reached or whether the fitness value has converged; when the judgment result is yes, determine the optimal LSTM hyperparameters by the gray wolf position; retrain the LSTM prediction model, which will have the best prediction performance, that is, construct the IGWO-LSTM river water quality prediction model;

[0096] Finally, the dataset was used to train, verify and test the IGWO-LSTM river water quality prediction model. Specifically, the training set was input into the IGWO-LSTM river water quality prediction model for iterative training. After the iterative training was completed, the verification set was input into the iteratively trained IGWO-LSTM river water quality prediction model for optimization, and the final optimized model was saved; the test set was input into the final optimized model to obtain the prediction results of river water quality, and the prediction performance of the final optimized model was evaluated using evaluation indicators. That is, the original data was compared to check the prediction accuracy, and the prediction performance was evaluated using mean absolute error (MAE), root mean square error (RMSE), mean absolute percentage error (MAPE) and determination coefficient (R2).

[0097] Figure 3a , Figure 3b , Figure 3c and Figure 3d The comparison charts of the evaluation indicators of the initial LSTM model and the optimized IGWO-LSTM model on four water quality indicators, namely, dissolved oxygen (COD, mg / L), pH, ammonia nitrogen (NH3-N, mg / L), and total phosphorus (TP, mg / L), are shown respectively. Figure 3a , Figure 3b , Figure 3c and Figure 3d As shown in the figure, it can be concluded that the IGWO-LSTM model has the smallest value under the RMSE, MAE, and MAPE evaluation indicators, and has a large determination coefficient (R2), which fully proves that after IGWO optimizes the LSTM model, it has a higher prediction accuracy, as shown in Table 1:

[0098] Table 1

[0099]

[0100] Figure 4 This is a comparison chart of the prediction results of the IGWO-LSTM model on the validation set and the original data for the next 7 days. Figure 4 As shown: By comparison, it can be found that the prediction results of the method of the present invention are highly accurate and can better handle the prediction problem of future water quality data in time series. Compared with the traditional water quality prediction model, IGWO-LSTM can better capture the long-term dependencies and periodic changes in time series data.

[0101] It is proved that the improved grey wolf algorithm (IGWO) of the present invention has a strong global search capability and can converge to the global optimal solution more quickly, thereby accelerating the training process of the LSTM neural network. Moreover, the IGWO algorithm can dynamically adjust the search space and range and can more flexibly adapt to different optimization stages of the LSTM neural network, thereby maintaining the diversity and stability of the algorithm.

[0102] In summary, the river water quality prediction method based on IGWO-LSTM of the present invention has unsurpassed technical advantages in related technologies.

[0103] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A river water quality prediction method based on IGWO-LSTM, characterized in that: include: Step S1: extracting monitoring water quality index data from a water quality monitoring site; Step S2: preprocessing the extracted monitoring water quality index data; Step S3: performing feature selection based on the pre-processed water quality data to obtain water quality feature data; Step S4: normalizing the water quality characteristic data, and then slicing the normalized water quality characteristic data using a sliding window tool to generate a data set for river water quality prediction; Step S5: dividing the data set for river water quality prediction into a training set, a validation set and a test set according to a preset ratio; Step S6: constructing an LSTM model, inputting the training set into the LSTM model for pre-training, and evaluating the prediction performance of the trained LSTM model; Step S7: improving the gray wolf algorithm so that a mixed chaotic sequence Tent-Logistic is introduced during the gray wolf population initialization process; Step S8: generating a fitness function according to the prediction error in the prediction performance; Step S9: dividing the gray wolf individuals according to the fitness function, and then performing optimization search through the gray wolf individuals, and introducing nonlinear control parameters in the search iteration process to adjust the global optimization and local optimization capabilities of the gray wolf population; Step S10: In the process of searching and iterating by the individual gray wolf, a dynamic weight updating strategy based on the fitness function is introduced; Step S11: outputting the optimal solution after the improved grey wolf algorithm stops iterating, and constructing the IGWO-LSTM river water quality prediction model according to the optimal hyperparameters corresponding to the optimal solution; Step S12: inputting the training set into the IGWO-LSTM river water quality prediction model for iterative training. After the iterative training is completed, inputting the verification set into the iteratively trained IGWO-LSTM river water quality prediction model for optimization, and saving the final optimized model; Step S13: inputting the test set into the final optimized model to obtain the prediction result of river water quality, and using evaluation indicators to evaluate the prediction performance of the final optimized model.

2. The river water quality prediction method based on IGWO-LSTM according to claim 1 is characterized in that: The step S2 specifically includes: Step S2.1: Use the K-nearest neighbor method to find the K samples that are most similar to the monitored water quality index data whose missing values ​​need to be supplemented, and use the average value of the K most similar samples to fill the missing values; Step S2.2: Use the isolation forest algorithm to process abnormal data; Step S2.3: using the Pearson correlation coefficient to calculate the correlation between the time series and the monitored water quality index data processed by the isolation forest algorithm, and arranging the calculated Pearson correlation coefficient into a correlation matrix; wherein each element in the correlation matrix represents the correlation coefficient between the time series and the monitored water quality index data processed by the isolation forest algorithm; Step S2.4: According to the correlation matrix and the size of the correlation coefficient, the monitored water quality index data with a high correlation with the time series is obtained.

3. The river water quality prediction method based on IGWO-LSTM according to claim 1 is characterized in that: The step S4 specifically includes: Step S4.1: applying a minimum-maximum normalization method to the water quality characteristic data, that is, first finding the maximum and minimum values ​​of each water quality parameter in the water quality characteristic data, and then limiting the values ​​corresponding to each water quality characteristic data to between 0 and 1; Step S4.2: According to the periodicity of the water quality characteristic data, the normalized water quality characteristic data are sliced ​​using a sliding window tool to generate a data set for river water quality prediction; wherein a window close to the period length is selected for data segmentation, each window is regarded as a sample, the data within the window is regarded as a time series, and all samples are converted into a three-dimensional array; the first dimension represents the number of samples, the second dimension represents the number of time steps, and the third dimension represents the number of features for each time step.

4. The river water quality prediction method based on IGWO-LSTM according to claim 1 is characterized in that: The step S7 is specifically as follows: improving the gray wolf algorithm so that in the process of initializing the gray wolf population, a hybrid chaotic sequence Tent-Logistic that integrates the Tent chaotic sequence and the Logistic sequence is introduced, and the formula is as follows: In formula (1), x h+1 and x h is the individual position of the wolf pack; r is in the range of (0,4], which means that within the value range of r, the system is in a chaotic state.

5. The river water quality prediction method based on IGWO-LSTM according to claim 1 is characterized in that: The step S9 is specifically as follows: updating the individual positions of the wolf pack according to the fitness function, and introducing a nonlinear control parameter a based on a tangent function in the search iteration process, which is expressed as follows: In formula (2), a max is the maximum value of the control parameter; a min is the minimum value of the control parameter; t is the current iteration number; t max is the maximum number of iterations. Among them, when the improved grey wolf algorithm starts to execute, the decreasing rate of a is small, which increases the global search capability; in the later stage of the execution of the improved grey wolf algorithm, the decreasing rate of a is large, which improves the convergence rate of the algorithm's local optimization problem.

6. The river water quality prediction method based on IGWO-LSTM according to claim 1 is characterized in that: The step S10 is specifically as follows: during the search iteration process of the gray wolf individual, a position update weight ω based on the fitness function is introduced. i , in order to give wolves with better fitness values ​​higher position update rights, the formula is as follows: In formula (3), α, β, and δ are the weights of the wolf; α s , β s , δ s are the fitness values ​​of α, β, and δ wolves respectively; Among them, the better the fitness function value, the greater the fitness value of the corresponding wolf individual; after each iteration, the fitness value of each updated wolf is re-evaluated, that is, the performance of the LSTM model corresponding to the new hyperparameter combination is re-evaluated, and α wolf, β wolf and δ wolf are updated according to the fitness value. When the set maximum number of iterations is reached, or when the fitness value no longer decreases significantly, the improved gray wolf algorithm stops iterating, and it is considered that the relatively optimal hyperparameter combination has been found.