Water pollution detection method based on improved whale optimization algorithm and bagging integration

Through improved whale optimization algorithm and bagged integration technology, the BP neural network model is optimized, and the lack of performance of traditional water pollutant detection technology in complex water quality environments is solved, and high-precision and robust water pollutant concentration detection is achieved.

CN120197144AInactive Publication Date: 2025-06-24ZHEJIANG UNIV OF TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510183442.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-19
Publication Date
2025-06-24
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Traditional water pollutant detection technology has problems such as long detection time, cumbersome operation, high cost, and high dependence on equipment and environmental conditions. Traditional machine learning methods are limited in processing data with high-dimensional, noisy, and nonlinear relationships. Deep learning models also face challenges such as weak cross-environmental adaptability, difficulty in selecting objective functions, and overfitting under complex water quality conditions.

Method used

The improved whale optimization algorithm (IWOA) is used to optimize the BP neural network model parameters, combined with bag integration (Bagging) technology, enhance the generalization ability and robustness of the model, and build an IWOA-BP-Bagging model for accurate detection of water pollutant concentration.

Benefits of technology

The global convergence performance and robustness of the model are significantly improved, ensuring that high-precision detection performance is maintained in complex water quality environments, with detection errors below 3%, and the average absolute error is reduced by 40% compared with traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120197144A_ABST
    Figure CN120197144A_ABST
Patent Text Reader

Abstract

The invention discloses a water pollution detection method based on an improved whale optimization algorithm and bagging integration, and the method comprises the steps: building an initial BP neural network model through measuring the multi-dimensional features of a water sample; performing iterative optimization on model parameters by using an improved whale optimization algorithm, improving global search and local optimization ability by combining dynamic step length adjustment and a Levy flight disturbance mechanism, and screening an optimal parameter group; based on bagged ensemble learning, multiple subsets are extracted from a training set in a replacement mode, part of features are shielded randomly, and an IWOA-BP neural network sub-model is trained through the optimized parameter set; and finally, a sub-model prediction result is fused through a quantile integration strategy. The method has rapid convergence, high robustness and strong generalization ability in the complex water quality environment, and can realize high-precision detection of the pollutant concentration in the complex water quality environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical fields of data analysis and water quality detection, and particularly relates to a method for detecting water pollutant concentration based on an optimization algorithm and ensemble learning. Background Art

[0002] In recent years, the problem of water pollution has become increasingly severe. How to achieve rapid, accurate, and comprehensive monitoring of pollutants in water bodies has become the core of water resource management and environmental protection work. Traditional water pollution detection technologies cover physical detection, chemical analysis, biological monitoring, and other means. To a certain extent, these technologies provide high-precision detection results, but they generally face limitations such as long detection time, cumbersome operation, high cost, and high dependence on equipment and environmental conditions, making it difficult to meet the actual needs of large-scale and efficient monitoring.

[0003] With the booming development of big data and artificial intelligence technologies, data-driven machine learning methods have gradually been applied to the field of water pollutant detection. These methods collect multi-dimensional feature data of water samples and construct models in combination with algorithms to achieve real-time monitoring and prediction of water quality. However, traditional machine learning methods, such as principal component analysis and decision trees, often have limited performance when dealing with high-dimensional, noisy, and non-linear relationship data, and it is difficult to meet the standards of high-precision detection. Although water pollutant detection models based on deep learning have improved the prediction performance to a certain extent, they have a high dependence on the quality and quantity of data, and there are still shortcomings in terms of computational resource requirements, real-time response, and model generalization ability. Under complex water quality conditions, these models may encounter challenges such as weak cross-environment adaptation ability, difficult selection of objective functions, and overfitting.

[0004] At the level of model optimization, as a powerful non-linear fitting tool, the BP neural network has been widely used in water pollutant detection modeling. The BP neural network iteratively optimizes model parameters through the gradient descent method, making the loss function value converge to the minimum along the gradient direction. However, traditional BP network optimization methods have many deficiencies, such as being sensitive to initial parameters, slow convergence rate, and being prone to falling into local optimal solutions. These defects seriously hinder the improvement of the detection performance of the BP network in complex water quality environments. Therefore, there is an urgent need to develop an efficient, robust, and pollutant detection method suitable for complex water quality environments to effectively meet the actual needs of water resource management and environmental protection work. Summary of the Invention

[0005] To overcome the deficiencies of the existing technologies, the present invention provides a water pollution detection method based on an improved whale optimization algorithm and bagging integration, which has high performance and high accuracy. By optimizing the global search and local optimization capabilities, the convergence performance of the model is improved. At the same time, combined with the bagging integration technology, the generalization ability and robustness of the model are enhanced, and high-precision detection performance can still be maintained in a complex water quality environment.

[0006] To solve the above technical problems, the present invention provides the following technical solutions:

[0007] A water pollution detection method based on an improved whale algorithm (Improved Whale Optimization Algorithm, abbreviated as IWOA) and bagging integration (Bootstrap Aggregating, abbreviated as Bagging). Multiple characteristic measurements are performed on the water sample to construct an initial BP neural network model for water pollutant detection; the search space and optimization objectives of the model parameters are set, and the improved whale optimization algorithm is used to iteratively optimize the parameter population, dynamically adjust the step size and enhance the local optimization ability to obtain an optimized model parameter group; combined with the bagging integration technology, multiple sub-models are selected with replacement, and the optimized parameter group is used to train the BP neural network sub-model to construct an IWOA-BP-Bagging model. The water sample characteristic data is input into this model, and finally the accurate detection of the water pollutant concentration is realized.

[0008] Furthermore, the method includes the following steps:

[0009] Step 1: Sample data collection and preprocessing

[0010] Perform multi-dimensional characteristic measurements on the water sample to obtain multi-dimensional environmental parameters. The multi-dimensional environmental parameters include excitation wavelength, emission wavelength, absorbance, pH value, fluorescence intensity, dissolved oxygen, and turbidity. Construct an original data set D=(x1, x2,..., x n , y), where x n represents the nth feature of the data sample, and y represents the label corresponding to this sample, that is, the true concentration of the sample; perform numerical operation on the label y, perform data cleaning and data normalization operations on the data set D, and divide the original data into a training set and a test set;

[0011] Step 2: Establish a basic BP neural network model

[0012] Set the initial network structure, including the number of layers in the input layer, hidden layer, and output layer, and initialize the model parameters, including weights, biases, learning rate, and activation function; The network model is designed with a three-layer structure: input layer, hidden layer, and output layer; The number of nodes in the input layer is the same as the dimension of the features after dimensionality reduction. The hidden layer adopts a double-layer structure, and the number of nodes in each layer is 1.5 times that of the input layer. The ReLU activation function is selected to enhance the non-linear expression ability, and the expression is:

[0013] ReLU(x n ) = max(0, x n ) (1)

[0014] where x n is the feature of the sample data;

[0015] The output layer is a single node, and a linear activation function is used to directly output the pollutant concentration. The weight initialization adopts the He method (the weight initialization method for ReLU), and the obtained objective function is:

[0016]

[0017] where n in is the number of nodes in the input layer, that is, the number of features; The weights W are randomly sampled from a normal distribution with a mean of 0 and a variance of ;

[0018] The loss function adopts the weighted mean squared error WMSE to enhance the sensitivity to low-concentration samples, and the obtained objective function is expressed as:

[0019]

[0020] where L represents the value of the loss function, n represents the total number of samples, w i represents the weight of the i-th sample, y i represents the true concentration value of the i-th sample, represents the predicted concentration value of the i-th sample; ∈ is a small positive number used to avoid the denominator being zero, called the smoothing parameter;

[0021] In backpropagation, the expression for the error gradient of the output layer is:

[0022]

[0023] where z (L) is the weighted input of the output layer, that is, the value before applying the activation function;

[0024] The gradient of the hidden layer is passed through the chain rule, and the expression is:

[0025]

[0026] where δ (l) represents the gradient error of the l-th layer, represents the transpose of the weight matrix of the (l + 1)-th layer, and ⊙ represents element-wise multiplication, which is used to multiply the corresponding elements of two vectors or matrices with the same dimension;

[0027] The parameter update adopts an adaptive learning rate strategy, which decays with the number of training rounds. The expression is:

[0028] η(t) = η0·e -kt (6)

[0029] where η(t) represents the learning rate at the t-th round of training, η0 represents the initial learning rate, and the initial learning rate is set to 0.01; k represents the decay rate, which is used to control the speed of learning decay;

[0030] Step 3: Optimize the model parameters using IWOA

[0031] Due to the defect that the traditional whale optimization algorithm is prone to falling into local optimum, a dynamic step size adjustment and Lévy flight perturbation (an optimization mechanism based on the Lévy distribution random walk strategy) are introduced. The objective function is defined as the mean squared error of the validation set, and the expression is as follows:

[0032]

[0033] a. Encircling prey stage: Adjust the search step size through adaptive weight adjustment, where and are coefficient vectors, and the expression is as follows:

[0034]

[0035] where represents the search position at the (t + 1)-th iteration, ω(t) is used to control the size of the search step, which changes from 1 to 0 over time; represents the optimal solution found at the t-th iteration, is used to adjust the search direction, represents the distance between the current optimal solution and the current search position;

[0036] b. Bubble net attack stage: Combine Lévy flight perturbation to enhance the global exploration ability. The expression is as follows:

[0037]

[0038] where e blrepresents the attenuation factor, which is used to simulate the search intensity of whales during the bubble net attack phase. cos(2πl) is used to simulate the random search behavior of whales. a is the coefficient that controls the intensity of Lévy flight perturbation. Lévy(β) represents the Lévy flight perturbation, and β is the shape parameter of the Lévy distribution, which is used to simulate long-distance random jumps;

[0039] c. The step size is generated by the Lévy distribution, and the expression is as follows:

[0040]

[0041] where β is the parameter that controls the heavy-tailed characteristic of the step size distribution. Through iterative optimization, the optimal parameter group that minimizes the objective function is screened, which significantly improves the global convergence performance of the model;

[0042] Step 4: Train the IWOA-BP-Bagging concentration prediction model

[0043] Use the optimal hyperparameter group optimized by IWOA to train the BP-Bagging model to obtain the IWOA-BP-Bagging model. Adopt the Bootstrap sampling strategy to draw M sub-training sets from the original training set with replacement. Each subset independently trains an IWOA-BP sub-model. In view of the spatio-temporal heterogeneity of water quality data, a feature perturbation mechanism is introduced: 10% of the input features are randomly masked during each sampling to enhance the robustness of the model to missing data. After the sub-models are trained, the quantile integration strategy is used to fuse the prediction results, and the expression is as follows:

[0044]

[0045] where Q 0.25 and Q 0.75 are the lower and upper quartiles of the predicted value distribution, is the final prediction result. This strategy significantly improves the stability of the model in a complex water quality environment by suppressing the influence of outliers. The performance of the finally constructed IWOA-BP-Bagging model on the test set is quantified by the coefficient of determination R 2 and the root mean square error RMSE:

[0046]

[0047] where represents the average value of all sample true values, and R 2 represents the proportion of the variability explained by the model in the total variability; RMSE represents the average difference between the predicted value and the true value, and the smaller the value, the higher the prediction accuracy of the model.

[0048] In the present invention, when all the data for obtaining the characteristic values required for modeling, such as the excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen, and turbidity of the water sample to be measured, are obtained, these characteristics are input into the IWOA-BP-Bagging model, and the output of the model is the concentration of water pollutants in the water sample. Through IWOA for hyperparameter adjustment, the prediction ability of the BP neural network model is significantly enhanced, thus achieving faster calculation and more accurate prediction of the concentration of water pollutants.

[0049] The technical concept of the present invention is as follows: The present invention proposes an efficient water quality pollutant detection method by integrating the improved whale optimization algorithm (IWOA) with the BP neural network and combining Bagging ensemble learning. First, a BP neural network is constructed using multi-dimensional water quality characteristic data, and the model parameters are optimized through IWOA to avoid the limitations of random initialization, improve the convergence speed and prediction accuracy. IWOA dynamically balances global search and local optimization through adaptive weights and combines the Lévy flight mechanism to enhance the parameter optimization ability, thus breaking through the local optimum. To enhance the robustness of the model, the present invention adopts the Bagging ensemble technology, uses Bootstrap sampling to train multiple IWOA-BP sub-models, and introduces a feature perturbation strategy to randomly mask some input features, improving the adaptability of the model to feature loss and noise interference. In the prediction stage, a quantile ensemble strategy is adopted to aggregate the outputs of the sub-models, suppressing the influence of outliers and ensuring stable detection performance in a high-noise and multi-interference environment.

[0050] The beneficial technical effects of the present invention are mainly manifested in the following aspects: 1. Global optimization and efficient convergence: By dynamically adjusting the parameter search strategy through the improved whale optimization algorithm (IWOA), combining the adaptive weight and the Lévy flight perturbation mechanism, the global search ability of model parameter optimization is significantly improved, avoiding the problems that the traditional BP neural network is sensitive to initial parameters and prone to falling into local optima, increasing the model convergence speed by more than 50%, and ensuring the stability of the parameter combination at the same time. 2. Ensemble learning enhances robustness: Combining the Bagging ensemble technology, multiple sub-training sets are generated by random sampling with replacement, and a feature perturbation strategy is introduced to force the sub-models to learn the redundant correlation of multi-dimensional features, effectively improving the adaptability of the model to data noise, feature loss, and environmental fluctuations. Under the conditions of turbidity > 100 NTU and coexistence of multiple interfering substances, the detection error is still lower than 3%. 3. High precision and generalization performance: The quantile ensemble strategy is adopted to fuse the prediction results of multiple sub-models. By aggregating the median interval of the predicted value distribution, the influence of outliers is suppressed, reducing the mean absolute error of pollutant concentration detection by 40% compared with the traditional method, and showing excellent cross-scene generalization ability in different water quality environments. Description of the Drawings

[0051] Figure 1It is a flow chart for constructing the IWOA-BP-Bagging model.

[0052] Figure 2 It is a flow chart for calculating the IWOA algorithm.

[0053] Figure 3 It is a flow chart for constructing the BP model.

[0054] Figure 4 It is a flow chart for calculating the Bagging algorithm. Specific implementation manners

[0055] To make the objectives, technical solutions and advantages of the embodiments of the present invention clearer and more understandable, the present invention will be further described below in combination with specific embodiments and the accompanying drawings. In this way, a more detailed description of the present invention is made. Here, the schematic embodiments of the present invention and their descriptions are used to explain the operation process of the present invention, but not as the only operation of the present invention.

[0056] Refer to Figures 1 to 4 , a water pollution detection method based on an improved whale optimization algorithm and bagging integration. First, multiple feature measurements are performed on water samples to construct an initial BP neural network model for water pollutant detection; the search space and optimization objectives of the model parameters are set, and the improved whale optimization algorithm is used to iteratively optimize the parameter population, dynamically adjust the step size and enhance the local optimization ability to obtain an optimized model parameter group; combined with the bagging integration technology, multiple sub-models are selected with replacement, and the optimized parameter group is used to train the BP neural network sub-models to construct a Bagging-IWOA-BP model. The water sample feature data is input into this model, and finally, the accurate detection of the water pollutant concentration is realized.

[0057] The water pollution detection method based on the improved whale optimization algorithm and bagging integration includes the following steps:

[0058] Step 1: Sample data collection and preprocessing

[0059] Perform multi-dimensional feature measurements on water samples to obtain multi-dimensional environmental parameters. The multi-dimensional environmental parameters include excitation wavelength, emission wavelength, absorbance, pH value, fluorescence intensity, dissolved oxygen, turbidity, etc., and construct an original data set D = (x1, x2,..., x n , y), where x n represents the nth feature of the data sample, and y represents the label corresponding to the sample, that is, the true concentration of the sample; perform numerical operation on the label y, perform data cleaning and data normalization operations on the data set D, and divide the original data into a training set and a test set;

[0060] Step 2: Establish a basic BP neural network model

[0061] Set the initial network structure, including the number of layers of the input layer, hidden layer, output layer, etc., and initialize the model parameters, including hyperparameters such as weights, biases, learning rates, activation functions, etc.; The network model is designed as a three-layer structure: input layer, hidden layer, and output layer; The number of nodes in the input layer is the same as the feature dimension after dimensionality reduction. The hidden layer adopts a two-layer structure, and the number of nodes in each layer is 1.5 times that of the input layer. The ReLU activation function is selected to enhance the non-linear expression ability, and the expression is:

[0062] ReLU(x n ) = max(0, x n ) (1)

[0063] where x n is the feature of the sample data;

[0064] The output layer is a single node, and a linear activation function is used to directly output the pollutant concentration. The weight initialization adopts the He method (the weight initialization method for ReLU), and the obtained objective function is:

[0065]

[0066] where n in is the number of nodes in the input layer, that is, the number of features; The weights W are randomly sampled from a normal distribution with a mean of 0 and a variance of ;

[0067] The loss function adopts the weighted mean square error WMSE to enhance the sensitivity to low-concentration samples, and the obtained objective function is expressed as:

[0068]

[0069] where L represents the value of the loss function, n represents the total number of samples, w i represents the weight of the i-th sample, y i represents the true concentration value of the i-th sample, represents the predicted concentration value of the i-th sample; ∈ is a small positive number used to avoid the denominator being zero, called the smoothing parameter;

[0070] In backpropagation, the expression for the error gradient of the output layer is:

[0071]

[0072] where z (L) is the weighted input of the output layer, that is, the value before applying the activation function;

[0073] The hidden layer gradient is passed through the chain rule, and the expression is:

[0074]

[0075] where δ (l) represents the gradient error of the l-th layer, represents the transpose of the weight matrix of the (l + 1)-th layer, and ⊙ represents element-wise product, which is used to multiply the corresponding elements of two vectors or matrices with the same dimension;

[0076] The parameter update adopts an adaptive learning rate strategy, which decays with the number of training rounds. The expression is:

[0077] η(t) = η0·e -kt (6)

[0078] where η(t) represents the learning rate at the t-th round of training, η0 represents the initial learning rate, and the initial learning rate is set to 0.01; k represents the decay rate, which is used to control the speed of learning decay;

[0079] Step 3: Optimize the model parameters using IWOA

[0080] To address the defect that the traditional whale optimization algorithm is prone to falling into local optima, a dynamic step size adjustment and Lévy flight perturbation (an optimization mechanism based on the Lévy distribution random walk strategy) are introduced. The objective function is defined as the mean squared error of the validation set, and the expression is as follows:

[0081]

[0082] a. Encircling prey stage: Adjust the search step size through adaptive weight adjustment, where and are coefficient vectors, and the expressions are as follows:

[0083]

[0084] where represents the search position at the (t + 1)-th iteration, ω(t) is used to control the size of the search step, which changes from 1 to 0 over time; represents the optimal solution found at the t-th iteration, is used to adjust the search direction, represents the distance between the current optimal solution and the current search position;

[0085] b. Bubble-net attacking stage: Combine Lévy flight perturbation to enhance the global exploration ability. The expression is as follows:

[0086]

[0087] where e blIt represents the attenuation factor, which is used to simulate the search intensity of whales during the bubble net attack phase. cos(2πl) is used to simulate the random search behavior of whales. a is the coefficient that controls the intensity of Lévy flight perturbation. Lévy(β) represents the Lévy flight perturbation, and β is the shape parameter of the Lévy distribution, which is used to simulate long-distance random jumps;

[0088] c. The step size is generated by the Lévy distribution, and the expression is as follows:

[0089]

[0090] where β is the parameter that controls the heavy-tailed characteristic of the step size distribution. Through iterative optimization, the optimal parameter group that minimizes the objective function is selected, which significantly improves the global convergence performance of the model;

[0091] Step 4: Train the IWOA-BP-Bagging concentration prediction model

[0092] The optimal hyperparameter group optimized by IWOA is used to train the BP-Bagging model to obtain the IWOA-BP-Bagging model. The Bootstrap sampling strategy is adopted to draw M sub-training sets from the original training set with replacement. Each subset independently trains an IWOA-BP sub-model. In view of the spatio-temporal heterogeneity of water quality data, a feature perturbation mechanism is introduced: 10% of the input features are randomly masked during each sampling to enhance the robustness of the model to missing data. After the sub-models are trained, the quantile integration strategy is used to fuse the prediction results, and the expression is as follows:

[0093]

[0094] where Q 0.25 and Q 0.75 are the lower quartile and upper quartile of the predicted value distribution, is the final prediction result. This strategy significantly improves the stability of the model in a complex water quality environment by suppressing the influence of outliers; The performance of the finally constructed IWOA-BP-Bagging model on the test set is quantified by the coefficient of determination R 2 and the root mean square error RMSE:

[0095]

[0096] where represents the average value of all sample true values, and R 2 represents the proportion of the variability explained by the model in the total variability; RMSE represents the average difference between the predicted value and the true value, and the smaller the value, the higher the prediction accuracy of the model;

[0097] In the present invention, when all the data for obtaining the characteristic values required for modeling, such as the excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen, and turbidity of the water sample to be measured, are obtained, these characteristics are input into the IWOA-BP-Bagging model, and the model output is the concentration of water pollutants in the water sample. Through the IWOA for hyperparameter adjustment, the prediction ability of the BP neural network model is significantly enhanced, thus realizing faster calculation and more accurate prediction of the water pollutant concentration.

[0098] In this embodiment, by measuring the absorbance, fluorescence intensity, turbidity, pH value, and temperature in the unknown water sample, and substituting the measured data into the corresponding independent variables in the IWOA-BP-Bagging detection model, a water pollution detection method based on the improved whale optimization algorithm and bagging integration is obtained.

[0099] Taking the detection of potassium hydrogen phthalate in water as an example, the specific implementation steps are as follows:

[0100] Step 1: Configure a potassium hydrogen phthalate gradient solution with a COD value of 5 - 200 mg / L, which contains 50 samples. Measure the fluorescence intensity, turbidity, pH value, and temperature of each sample at an excitation wavelength of 250 - 400 nm and an emission wavelength of 300 - 550 nm, establish a concentration label, standardize all numerical data to the range of 0 - 1 to eliminate the influence of dimensions, and divide the obtained data into training samples (40) and test samples (10). Extract 3 independent fluorescence groups as the model input features through parallel factor analysis; subsequently, construct an initial BP neural network model. The number of nodes in the input layer is 3, the hidden layer is designed as a two-layer structure (5 nodes in each layer), the ReLU activation function is selected to enhance the non-linear expression ability, and the output layer is a single-node linear output. The weight initialization adopts the He method, and the bias is initialized to zero. The loss function is defined as the weighted mean square error WMSE to strengthen the attention to low-concentration samples, where, i is the true concentration value, is the model prediction value, and the expression is:

[0101]

[0102] Step 2: Refer to Figure 1 As shown in the IWOA algorithm calculation flowchart, set the search space of the model parameters, the weight range is [-2, 2][-2, 2], the bias range is [-1, 1][-1, 1], and the learning rate range is [0.001, 0.1][0.001, 0.1]. Initialize the IWOA algorithm, the population size is 50, and the number of iterations is 100. In the stage of surrounding the prey, the search step size is dynamically adjusted through the adaptive weight coefficient, where, and are the dynamic coefficient vectors, is the current optimal individual position, and the expression is:

[0103]

[0104] In the bubble net attack stage, a Lévy flight perturbation mechanism is introduced to generate random step sizes to enhance the global exploration ability. By minimizing the mean square error (MSE) of the validation set, the top 10% of the elite individuals are selected as the optimal parameter combination, and the expression is:

[0105]

[0106] Step 3: Use the Bagging ensemble model to train the BP model optimized by the improved whale optimization algorithm. 50 subsets are drawn with replacement from the training set, and each subset contains 80% of the original data. 15% of the features are randomly masked during each sampling to improve the robustness of the model to data missing; an IWOA-BP sub-model is independently trained for each subset, and an adaptive learning rate strategy is adopted, with an initial value of 0.01 and a 20% decay every 50 rounds; after training is completed, the quantile ensemble strategy is used to fuse the prediction results, where Q 0.25 and Q0.75 are the lower and upper quartiles of the predicted values respectively, and the expression is:

[0107]

[0108] Step 4: After obtaining the fusion strategy integrated by the bagging algorithm, bring the fusion strategy into the IWOA-BP model described in Step 2 above for training. Finally, a model composed of multiple sub-models is obtained, and the relationship between fluorescence intensity, temperature, pH value, and potassium hydrogen phthalate concentration is established. By subsequently measuring the fluorescence intensity, pH value, and temperature of the actual water sample at the excitation wavelength of 250 - 400 nm and the emission wavelength of 300 - 550 nm, and substituting them into the established IWOA-BP-Bagging model, the potassium hydrogen phthalate concentration in the water sample can be calculated through formula (11).

[0109] The content described in the embodiments of this specification is only a list of implementation forms of the inventive concept and is only for illustrative purposes. The protection scope of the present invention should not be regarded as limited to the specific forms stated in this embodiment. The protection scope of the present invention also extends to equivalent technical means that can be conceived by those of ordinary skill in the art based on the inventive concept of the present invention.

Claims

1. A water pollution detection method based on improved whale optimization algorithm and bag integration, characterized in that: By measuring the multi-dimensional characteristics of water samples, an initial BP neural network model is constructed; the improved whale optimization algorithm is used to iteratively optimize the model parameters, and the dynamic step size adjustment and Lévy flight perturbation mechanism are combined to improve the global search and local optimization capabilities, and screen the optimal parameter group; based on the Bagging integration technology, multiple subsets are extracted from the training set with replacement and some features are randomly masked, and the BP neural network sub-model is trained with the optimized parameter group; finally, the sub-model prediction results are fused through the quantile integration strategy to output high-precision water pollutant concentration detection values.

2. The water pollution detection method based on improved whale optimization algorithm and bagged integration as claimed in claim 1 is characterized in that: The method comprises the following steps: Step 1: Sample data collection and preprocessing The multidimensional characteristics of the water sample are measured to obtain multidimensional environmental parameters, including excitation wavelength, emission wavelength, absorbance, pH value, fluorescence intensity, dissolved oxygen and turbidity, and the original data set D = (x1, x2, ..., x n ,y), where x n represents the nth feature of the data sample, and y represents the label corresponding to the sample, that is, the true concentration of the sample; the label y is digitized, the data set D is cleaned and normalized, and the original data is divided into a training set and a test set; Step 2: Establish the BP neural network basic model Set the initial network structure, including the number of input layers, hidden layers, and output layers, and initialize the model parameters, including weights, biases, learning rates, and activation functions. The network model is designed as a three-layer structure: input layer, hidden layer, and output layer. The number of nodes in the input layer is consistent with the feature dimension after dimensionality reduction. The hidden layer adopts a double-layer structure, and the number of nodes in each layer is 1.5 times that of the input layer. The activation function uses ReLU to enhance the nonlinear expression ability. The expression is: ReLU(x n )=max(0,x n ) (1) where x n is the characteristic of the sample data; The output layer is a single node, and a linear activation function is used to directly output the pollutant concentration. The weight initialization uses the He method, and the objective function is: Where n in is the number of input layer nodes, that is, the number of features; the weight W has a mean of 0 and a variance of Random sampling from a normal distribution; The loss function uses the weighted mean square error WMSE to enhance the sensitivity to low-concentration samples. The obtained objective function is expressed as: Where L represents the value of the loss function, n represents the total number of samples, and w i represents the weight of the i-th sample, y i represents the true concentration value of the i-th sample, Represents the predicted concentration value of the i-th sample; ∈ is a small positive number used to avoid the situation where the denominator is zero, called the smoothing parameter; In back propagation, the output layer error gradient expression is: where z (L) is the weighted input to the output layer, i.e. the value before the activation function is applied; The hidden layer gradient is transferred through the chain rule, expressed as: δ (l) =(W (l+1)T ·δ (l+1) )⊙ReLU′(z (l) ) (5) where δ (l) represents the gradient error of the lth layer, represents the transpose of the weight matrix of the l+1th layer, ⊙ represents the element product, which is used to multiply the corresponding elements of two vectors or matrices of the same dimension; The parameter update adopts an adaptive learning rate strategy, which decays with the training rounds. The expression is: η(t)=η0·e -kt (6) Where η(t) represents the learning rate at the tth round of training, η0 represents the initial learning rate, which is set to 0.01; k represents the decay rate, which is used to control the speed of learning decay; Step 3: Optimize model parameters using IWOA Dynamic step size adjustment and Lévy flight perturbation are introduced, and the objective function is defined as the mean square error of the validation set, which is expressed as follows: a. Encircling the prey phase: The search step length is adjusted by adaptive weights, where and is the coefficient vector, and the expression is as follows: in represents the search position at the t+1th iteration, ω(t) is used to control the size of the search step and changes from 1 to 0 over time; represents the optimal solution found at the tth iteration, Used to adjust the search direction. Indicates the distance between the current optimal solution and the current search position; b. Bubble net attack phase: Combine Lévy flight disturbance to enhance global exploration capability. The expression is as follows: where e bl represents the attenuation factor, which is used to simulate the search intensity of whales during the bubble net attack phase, cos(2πl) is used to simulate the random search behavior of whales, a is the coefficient that controls the intensity of Lévy flight disturbance, Lévy(β) represents the Lévy flight disturbance, β is the shape parameter of the Lévy distribution, which is used to simulate long-distance random jumps; c. The Lévy distribution generates the step length, which is expressed as follows: Among them, β is a parameter that controls the heavy-tail characteristic of the step size distribution. Through iterative optimization, the optimal parameter group that minimizes the objective function is screened out, which significantly improves the global convergence performance of the model. Step 4: Train the IWOA-BP-Bagging concentration prediction model The optimal hyperparameter group optimized by IWOA is used to train the BP-Bagging model to obtain the IWOA-BP-Bagging model. The Bootstrap sampling strategy is used to extract M sub-training sets from the original training set with replacement. Each subset independently trains an IWOA-BP sub-model. In view of the spatiotemporal heterogeneity of water quality data, a feature perturbation mechanism is introduced: 10% of the input features are randomly masked each time sampling to enhance the robustness of the model to missing data; after the sub-model training is completed, the quantile integration strategy is used to fuse the prediction results, and the expression is as follows: Where Q 0.25 With Q 0.75 are the lower and upper quartiles of the predicted value distribution, is the final prediction result; the performance of the final constructed IWOA-BP-Bagging model on the test set is determined by the coefficient of determination R 2 Quantified with root mean square error RMSE: in Represents the average value of all samples, R 2 It indicates the proportion of variability explained by the model to the total variability; RMSE indicates the average difference between the predicted value and the true value. The smaller the value, the higher the prediction accuracy of the model.

Citation Information

Cited By

  • Quantum sensing technology-driven water quality pollution rapid detection method

    CN120870182A