Method for monitoring concentration of nitrogen substance in water body based on visible-near infrared spectrum technology
Through the PSO-MLP model, the monitoring of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen in water bodies is solved, and the problems of low accuracy and complex operation of water bodies nitrogen substances in traditional methods are achieved, and high-precision and rapid monitoring of water bodies nitrogen substances are achieved. Suitable for refined water quality management of urban rivers.
Patent Information
- Application Number
- CN202411082849.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-08
- Publication Date
- 2024-11-15
AI Technical Summary
The accuracy of monitoring nitrogen substances in water is low in combination with traditional algorithms and can be found in combination with visible-near-infrared spectroscopy technology. The existing methods are difficult to achieve the refinement of nitrogen substances in water due to high monitoring costs, cumbersome operation, poor timeliness, and restrictions on monitoring points layout. monitor.
Using the PSO-MLP model based on visible-near-infrared spectroscopy technology, the multi-layer perceptron model is optimized through the screening, normalization treatment and particle swarm of hyperspectral reflective spectroscopy samples to achieve ammonia nitrogen, protein, urea nitrogen, and nitrate nitrogen in water bodies. rapid monitoring.
It improves the accuracy and fine classification capability of nitrogen substance concentration monitoring in water bodies, and the monitoring accuracy can reach more than 85%, reduces monitoring steps, reduces operational complexity and duration, and is suitable for refined water quality management of urban rivers.
Smart Images

Figure CN118961655A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of water quality monitoring, and in particular relates to a method for monitoring the concentration of nitrogen substances in water based on visible-near infrared spectroscopy technology. Background Art
[0002] The pollution level of water nutrients is usually measured by the concentration of nitrogen substances. The nitrogen substances in natural water bodies are mainly ammonia nitrogen, nitrate nitrogen, protein, and urea nitrogen. Since excessive nitrogen content in rivers, lakes and other water bodies will lead to eutrophication of water bodies, there is an urgent need for rapid, simple, and low-cost monitoring of nitrogen substances in water.
[0003] At present, the main monitoring methods for nitrogen substances include artificial mobile monitoring, fixed site monitoring and remote sensing monitoring methods. However, the artificial mobile monitoring method is based on various chemical methods to monitor the concentration of various nitrogen substances in water, which has problems such as high detection cost, cumbersome operation, poor timeliness, large workload, and easy to cause secondary pollution; although the fixed site monitoring method has solved the above problems to a certain extent, the fixed sites are often deployed at provincial boundary sections, estuaries, tributary confluences, important lakes and border rivers. There are problems such as strict rules for the deployment of monitoring points, limited number, and high installation costs. It is difficult to achieve refined water quality management of urban rivers by this method alone; remote sensing monitoring methods can be used to timely determine the location and degree of river pollution, but traditional satellite remote sensing monitoring methods mainly realize water quality monitoring on a large scale, and are limited by low signal-to-noise ratio and instrument resolution. The monitoring results are relatively inaccurate for small urban rivers. The ground-based hyperspectral monitoring method can better avoid the above problems. The selection of monitoring points is less restricted and does not require complex atmospheric correction. It can effectively realize accurate monitoring of different nitrogen concentrations in water.
[0004] At present, the main research on hyperspectral water quality inversion of various water bodies is on ammonia nitrogen and total nitrogen. No detailed research on nitrogen substances in water bodies has been conducted by refining nitrogen substance indicators. The accuracy of traditional algorithms combined with visible-near infrared spectroscopy technology in monitoring nitrogen substances in water bodies is low. Summary of the invention
[0005] In order to solve the technical problem: Currently, the hyperspectral water quality inversion research of various water bodies is mainly carried out for ammonia nitrogen and total nitrogen, and the refined research on nitrogen substances in water bodies has not been carried out by refining nitrogen substance indicators. The accuracy of traditional algorithms combined with visible-near infrared spectroscopy technology to monitor nitrogen substances in water bodies is low.
[0006] In view of the above problems, the present invention proposes a method of monitoring four nitrogen substances in water, namely ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen, using visible-near infrared spectroscopy technology. The concentration of nitrogen substances in water can be quickly monitored without adding other reagents, which is of great significance for solving the problem of effective monitoring of nitrogen substances in water.
[0007] The present invention provides the following technical solutions:
[0008] A method for monitoring the concentration of nitrogen substances in water based on visible-near infrared spectroscopy technology comprises the following steps:
[0009] S1. Collect several water body hyperspectral reflectance spectrum samples, with the band collection range of 380nm-1000nm;
[0010] S2, synchronously with step S1, collecting water samples corresponding to the water body hyperspectral reflectance spectrum samples for filtering preprocessing, and dividing the water body samples into a training set, a validation set and a test set after filtering preprocessing;
[0011] S3. Determine the concentrations of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen in the water samples in each test set;
[0012] S4, screening the water body hyperspectral reflectance spectrum samples in step S1 using reflectance and normalized difference vegetation index;
[0013] S5, normalizing the screened water body hyperspectral reflectance spectrum samples;
[0014] S6. Input the water body hyperspectral reflectance spectrum sample data normalized in step S5 into the PSO-MLP model constructed by optimizing the MLP model using the PSO algorithm, and output the predicted concentrations of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen of the water body hyperspectral reflectance spectrum samples; and use the test set to check the performance of the PSO-MLP model.
[0015] Furthermore, the method for screening the water body hyperspectral reflectance spectrum samples in step S1 includes: if the reflectance of the water body hyperspectral reflectance spectrum sample at the first band is less than a set first threshold, and the normalized vegetation index of the water body hyperspectral reflectance spectrum sample is less than a set second threshold, and the reflectance of the water body hyperspectral reflectance spectrum sample at the second band is less than a set third threshold, then the water body hyperspectral reflectance spectrum sample is a normal water body hyperspectral reflectance spectrum sample and is retained; otherwise, it is an abnormal water body hyperspectral reflectance spectrum sample and is discarded.
[0016] Furthermore, in step S5, the normalization process of the water body hyperspectral reflectance spectrum samples includes:
[0017] The curve composed of the water body hyperspectral reflectance spectrum collected at the same location is smoothed and denoised, and several spectral band characteristics of the water body hyperspectral reflectance spectrum are obtained;
[0018] The water body hyperspectral reflectance spectrum is normalized using the formula:
[0019]
[0020] Where x norm is the normalized water body hyperspectral reflectance spectrum, x is the water body hyperspectral reflectance spectrum after denoising, and x min is the minimum reflectivity value at different wavelengths, x max is the maximum reflectivity value at different wavelengths.
[0021] Furthermore, the PSO-MLP model includes a PSO part and an MLP part. The MLP part includes an input layer, a hidden layer and an output layer. The input layer is used to receive the hyperspectral reflectance spectrum characteristics of the water body, the hidden layer is used to extract the hyperspectral reflectance spectrum characteristics of the water body, and the output layer is used to output the prediction results of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen in the water body; the PSO part is used to use the PSO algorithm to complete the optimization of the MLP part.
[0022] Furthermore, the training method of the PSO-MLP model includes:
[0023] (1) Prepare several water body hyperspectral reflectance spectrum samples;
[0024] (2) Construct a multi-layer perceptron model, namely, an MLP model, including an input layer, a hidden layer, and an output layer;
[0025] (3) Initialize PSO algorithm parameters: define the number of particles in the particle swarm; set the particle dimension to be consistent with the total weight and bias number in the MLP model, and randomly initialize the particle speed and position in the search space;
[0026] (4) Optimize the MLP model using the PSO algorithm to obtain the PSO-MLP model;
[0027] (5) Select the loss function, optimizer, and evaluation metric, and compile the PSO-MLP model;
[0028] (6) PSO-MLP model training and evaluation.
[0029] Furthermore, in the MLP model:
[0030] The input layer uses all wavelength collection points in the water body hyperspectral reflectance spectrum sample 380nm-1000nm as input neurons to receive the information of each feature in the input water body hyperspectral reflectance spectrum sample data, so as to provide enough information for the hidden layer to extract features;
[0031] The hidden layer is set to two layers, and the number of neurons in the first and second layers are set to 64 and 32 respectively;
[0032] The output layer has one neuron, which is used to output the prediction results of ammonia nitrogen, protein, urea nitrogen, and nitrate nitrogen corresponding to the hyperspectral reflectance spectrum of the water body.
[0033] Furthermore, the PSO algorithm is used to optimize the MLP model, including the following steps:
[0034] The PSO algorithm is used to optimize the MLP model, including the following steps:
[0035] Use the particle position, that is, the particle weight and bias, to initialize the MLP model and train the model, and use the training set data to calculate the loss value of the MLP model as the fitness value;
[0036] Use the PSO algorithm to update the position and speed of each particle. In each generation of evolution, if the current fitness value is better than its historical optimal value, then update pbest i If the current fitness value is better than its global historical optimal value, update gbest i , the formula can be expressed as:
[0037] v i =ωv i +c 1 rand()(pbest i -x i )+c 2 rand()(gbest i -x i ),
[0038] Where i is the number of spectral bands of the water body hyperspectral reflectance spectrum sample, ω is the inertia weight, and v i is the particle speed, rand() is a random number between (0,1), x i is the current position of the particle, c 1 、c 2 is the learning factor, pbest i is the optimal position of individual particles, gbest i is the optimal position of particles in the group;
[0039] The iteration is terminated when the maximum number of iterations is reached or the fitness value meets the predetermined minimum fitness threshold, the optimal weights and biases are output, and the PSO-MLP model is constructed using the optimal weights and biases.
[0040] Further, PSO-MLP model training and evaluation:
[0041] Input the training set data into the PSO-MLP model, use the Adam optimizer to further iteratively update the network weights based on the training set data, and adjust different learning rates until the preset number of training times or the preset training accuracy is reached;
[0042] Input the validation set data into the PSO-MLP model, calculate the loss and evaluation index of the PSO-MLP model, judge the generalization ability of the model, and adjust and optimize the PSO-MLP model according to the results of the validation set to obtain the final PSO-MLP model;
[0043] The test set data is input into the PSO-MLP model, the loss and evaluation indicators of the PSO-MLP model are calculated, and the final performance of the PSO-MLP model is evaluated.
[0044] Furthermore, the nth layer of the MLP model part of the PSO-MLP model, n = 1, 2, ...; the configuration parameter is the weight W n , enter X n , Deviation b n , function f uses sigmoid function or tanh function, and the output of this layer can be expressed as:
[0045] Y n =f(W n X n +b n )
[0046] After using the Adam optimizer, the weights and biases are updated with the gradient of the loss function at each iteration, expressed as:
[0047]
[0048] In the formula is the weight of the i-th row and j-th column of the n-th layer weight matrix, is the i-th bias of the n-th layer, To find the partial derivative of the loss function with respect to the bias, L(W,b) represents the loss function, W is the weight, b is the bias, and η is the learning rate, which represents the speed at which the neural network accumulates information within a preset time.
[0049] Furthermore, in step S6, the performance of the PSO-MLP model is checked using the test set, as follows:
[0050] The PSO-MLP model uses the ReLU function as the activation function and the determination coefficient R 2 Evaluate the prediction results of ammonia nitrogen, protein, urea nitrogen, and nitrate nitrogen, and select R 2 The highest parameter is taken as the final result, R 2 The formula is:
[0051]
[0052] Where p is the number of samples, y i is the measured value of various nitrogen substances in the i-th water sample, is the estimated value of various nitrogen species in the i-th water body hyperspectral reflectance spectrum sample, is the average value of the measured values of various nitrogen substances in p water samples.
[0053] Compared with the prior art, the present invention has the following beneficial effects:
[0054] 1. The present invention has a high accuracy in monitoring the concentration of various nitrogen substances in water bodies. Because the nitrogen substances in water bodies are not optically active and are non-photosensitive substances, there are problems such as the spectral curves of various nitrogen substances in water bodies do not change significantly and the spectral response bands are difficult to find, which makes the accuracy of monitoring nitrogen substances in water bodies using traditional algorithms combined with visible-near infrared spectroscopy technology low. The MLP model itself has powerful nonlinear mapping capabilities, high self-learning and adaptive capabilities, but it will take a long time to train; and optimizing the MLP model based on the PSO algorithm can provide better global search capabilities, optimize parameter initialization and accelerate training convergence speed, so as to achieve the purpose of improving the overall model performance and training efficiency, and then providing a better water quality inversion model capability. Therefore, the use of the PSO-MLP model can improve the accuracy and mobility of monitoring the concentration of nitrogen substances in water bodies, and its accuracy can reach more than 85%.
[0055] 2. The present invention has carried out a more refined classification monitoring of nitrogen substances in water bodies. Because the current hyperspectral water quality inversion for nitrogen substances in water bodies is mostly carried out for ammonia nitrogen and total nitrogen, but protein, urea nitrogen, and nitrate nitrogen also account for more than 50% of the nitrogen content, the fine classification monitoring of nitrogen substances in water bodies is of great significance for studying the process of river water eutrophication and preventing the occurrence of eutrophication of water bodies.
[0056] 3. The present invention reduces the steps of monitoring the concentration of various nitrogen substances in water. When using chemical methods to monitor the concentration of nitrogen substances, it is necessary to filter, add medicine, heat, digest and other steps to process water samples, which is cumbersome and time-consuming. Although the present invention needs to collect a large number of samples when training the model in the early stage, when the method is used to monitor the concentration of various nitrogen substances in the future, there is no need to collect or process a large number of water samples, and the average monitoring time is within 1 minute. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is a flow chart of the method for monitoring the concentration of nitrogen substances in water based on visible-near infrared spectroscopy technology of the present invention;
[0058] Figure 2 This is a flow chart for screening water body hyperspectral reflectance spectrum data of the present invention. DETAILED DESCRIPTION
[0059] The technical solution of the present invention will be clearly described below in conjunction with the accompanying drawings. Obviously, the described embodiments are not all embodiments of the present invention, and all other embodiments obtained by ordinary technicians in the field without making creative work are within the protection scope of the present invention.
[0060] like Figure 1 As shown, the present invention provides a method for monitoring the concentration of nitrogen substances in water based on visible-near infrared spectroscopy technology, comprising the following steps:
[0061] S1. Collect several water body hyperspectral reflectance spectrum samples at the test point;
[0062] In step S1, the water body hyperspectral reflectance spectrum sample belongs to the visible-near infrared spectrum, and the band collection range is 380nm-1000nm, wherein the optimal band range is 400nm-900nm.
[0063] S2. After collecting the water hyperspectral reflectance spectrum samples at the test point once, the water samples corresponding to the water hyperspectral reflectance spectrum samples collected each time are synchronously collected for filtering preprocessing. The filtering preprocessing is to remove impurities and suspended matter in the water samples; after filtering preprocessing, the water samples are classified into training set, validation set and test set.
[0064] In step S2, the water sample filtration pretreatment includes removing impurities and suspended matter using a filter membrane, the pore size of the filter membrane is ≤ 0.45 μm;
[0065] The number of water samples collected should be no less than 30, and the ratio of the number of water samples in the training set, validation set, and test set should be set to 8:1:1.
[0066] S3. Use chemical methods to determine the concentrations of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen in each water sample in the laboratory.
[0067] In step S3, the chemical method adopts ultraviolet-visible spectrophotometry, and under the condition of adding reagents corresponding to ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen, pure water is used as a reference solution to respectively measure the concentrations of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen in each water sample.
[0068] S4. Using reflectance and normalized vegetation index, the water body hyperspectral reflectance spectrum samples in step S1 are screened to remove abnormal spectrum data caused by foreign matter on the water surface.
[0069] In step S4, foreign matter on the water surface such as fallen leaves, plastic, dead fish and other floating objects are removed.
[0070] Abnormal spectral data refers to water body hyperspectral reflectance spectrum sample data whose reflectance is higher than that of normal water body due to abnormal spectrum and foreign matter on the water surface. The method for screening water body hyperspectral reflectance spectrum samples in step S1 by removing abnormal data includes the following steps: Figure 2 As shown:
[0071] If the reflectance of the water body hyperspectral reflectance spectrum sample at 420nm satisfies Rrs(420)<0.2, and the normalized vegetation index NDVI of the water body hyperspectral reflectance spectrum sample is<0.2, and the reflectance of the water body hyperspectral reflectance spectrum sample at 880nm satisfies Rrs(880)<0.15, then the water body hyperspectral reflectance spectrum sample is a normal water body hyperspectral reflectance spectrum sample and is retained; otherwise, it is an abnormal water body hyperspectral reflectance spectrum sample and is discarded.
[0072] S5. Normalize the screened water body hyperspectral reflectance spectrum samples.
[0073] In step S5, the normalization process of the water body hyperspectral reflectance spectrum samples includes:
[0074] (1) Smoothing and denoising the curve formed by the water body hyperspectral reflectance spectrum collected at the same location, and obtaining several spectral band characteristics of the water body hyperspectral reflectance spectrum;
[0075] The smoothing noise reduction is performed by using the Savitzky-Golay smoothing method.
[0076] (2) Normalize the water body hyperspectral reflectance spectrum, the formula is:
[0077]
[0078] Where x norm is the normalized water body hyperspectral reflectance spectrum, x is the water body hyperspectral reflectance spectrum after denoising, and x min is the minimum reflectivity value at different wavelengths, x max is the maximum reflectivity value at different wavelengths.
[0079] S6. The water body hyperspectral reflectance spectrum sample data after normalization in step S5 is input into the created multi-layer perceptron model optimized by the particle swarm optimization algorithm, i.e., the PSO-MLP model, to obtain the predicted concentrations of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen in the water body at the test point. The test set is used as a subsequent PSO-MLP model performance test sample to check whether the model has any offset.
[0080] In step S6, the PSO-MLP model includes a PSO part and an MLP part, and the MLP part architecture includes an input layer, a hidden layer, and an output layer. The input layer is used to receive the hyperspectral reflectance spectrum characteristics of the water body, the hidden layer is used to extract the hyperspectral reflectance spectrum characteristics of the water body, and the output layer is used to output the prediction results of ammonia nitrogen, protein, urea nitrogen, and nitrate nitrogen in the water body.
[0081] The PSO part includes the number of particles and particle dimension settings, which are used to find the best weights and biases with fitness values better than the historical optimal values to complete the optimization of the MLP part.
[0082] The nth layer configuration parameter of the MLP model part of the PSO-MLP model is the weight W n , enter X n , Deviation b n , n=1,2,…, function f uses sigmoid function or tanh function, the output of this layer can be expressed as:
[0083] Y n =f(W n X n +b n ),
[0084] The training method of the PSO-MLP model includes:
[0085] (1) Data preparation: Prepare ≥ 300 water body hyperspectral reflectance spectrum samples;
[0086] (2) Constructing MLP model: Constructing a multi-layer perceptron (MLP) model, which includes an input layer, a hidden layer, and an output layer;
[0087] a. The input layer uses all wavelength collection points of the water body hyperspectral reflectance spectrum sample 380nm-1000nm as input neurons to receive the information of each feature in the input water body hyperspectral reflectance spectrum sample data, so as to provide sufficient information for the hidden layer to extract features;
[0088] b. Through continuous adjustment and experimentation, it is determined that the hidden layer can be set to two layers. The number of neurons in the first and second layers is set in the range of 20-100 respectively. It is a reasonable choice to set the number of neurons in the first and second layers to 64 and 32 respectively, which can effectively avoid poor model performance or overfitting.
[0089] c. The output layer has one neuron, which is used to output the prediction results of ammonia nitrogen, protein, urea nitrogen, and nitrate nitrogen corresponding to the water body hyperspectral reflectance spectrum;
[0090] (3) Initialize the particle swarm optimization (PSO) algorithm parameters: define the number of particles in the particle swarm, preferably 20-50; set the particle dimension to be consistent with the total weight and bias number of the MLP model, and randomly initialize the particle speed and position in the search space to prepare for the subsequent particle swarm optimization process;
[0091] a. Assume that the input layer has n neurons and the first hidden layer has m 1 neurons, and the second hidden layer has m 2 There are k neurons in the output layer, and the total weight α is calculated as follows:
[0092] α=(n×m 1 )+(m 1 ×m 2 )+(m 2 ×k),
[0093] b. The number of biases should be consistent with the number of neurons.
[0094] (4) Use the PSO algorithm to optimize the MLP model. The process is as follows:
[0095] a. Use the particle positions (i.e. weights and biases) to initialize the MLP model and train the model, and use the training data to calculate the model's loss value as the fitness value;
[0096] b. Use the PSO algorithm to update the position and speed of each particle. In each generation of evolution, if the current fitness value is better than the historical optimal value, update pbest i If the current fitness value is better than the global historical optimal value, update gbest i . This formula can be expressed as:
[0097] v i =ωv i +c 1 rand()(pbest i -x i )+c 2 rand()(gbest i -x i ),
[0098] Where i is the number of spectral bands of the sample, ω is the inertia weight (starting from 0.9 and gradually optimized), v i is the particle speed, rand() is a random number between (0,1), x i is the current position of the particle, c 1 , c 2 is the learning factor (usually c 1 =c 2 =2), pbest iis the optimal position of individual particles, gbest i is the optimal position of a particle in a group; in the particle swarm optimization algorithm (PSO), each particle represents a potential solution to the problem, and the entire particle swarm represents the search for the problem solution space. Each particle will record the best position it finds during the search process (the historical optimal value of the individual particle, pbest i ), and the entire particle swarm will also record the best position found among all particles, that is, the global historical optimal position (global historical optimal value, gbest i ). This global historical optimal position is the optimal solution reached by all particles during the search process, which reflects the best performance of the entire particle swarm in the current iteration.
[0099] c. When the maximum number of iterations is reached or the fitness value meets the predetermined minimum fitness threshold, the iteration is terminated, the optimal weights and biases are output, and the PSO-MLP model is constructed using the optimized weights and biases;
[0100] (5) Compile the PSO-MLP model: Select the loss function, optimizer, and evaluation metric, and compile the PSO-MLP model;
[0101] (6) Overall PSO-MLP model training and evaluation:
[0102] Input the training set data into the PSO-MLP model, use the Adam optimizer to further implement iterative updates of network weights based on the training set data, and adjust different learning rates until a certain number of training times or a certain training accuracy is reached; input the validation set data into the PSO-MLP model, calculate the model's loss and evaluation indicators, judge the model's generalization ability, and adjust and optimize the model according to the results of the validation set, such as adjusting model parameters, increasing the number of neurons in the hidden layer, and other optimizations to obtain the final PSO-MLP model; input the test set data into the PSO-MLP model, calculate the PSO-MLP model's loss and evaluation indicators, and evaluate the final performance of the PSO-MLP model.
[0103] After using the Adam optimizer, the weights and biases are updated with the loss function gradient at each iteration, expressed as:
[0104]
[0105] In the formula is the weight of the i-th row and j-th column of the n-th layer weight matrix, is the i-th bias of the n-th layer, To find the partial derivative of the loss function with respect to the bias, L(W,b) represents the loss function, and η is the learning rate, which represents the speed at which the neural network accumulates information within a certain period of time.
[0106] In step S6, the PSO-MLP model uses the ReLU function as the activation function and the determination coefficient R 2 Evaluate the prediction results of ammonia nitrogen, protein, urea nitrogen, and nitrate nitrogen, and select R 2 The highest parameter is taken as the final result, R 2 The formula is:
[0107]
[0108] Where p is the number of samples, y i is the measured value of various nitrogen substances in the i-th sample, is the estimated value of various nitrogen substances in the i-th sample, is the average value of the measured values of various nitrogen substances in p samples.
[0109] (7) The created PSO-MLP model was used to monitor the concentrations of ammonia nitrogen, protein, urea nitrogen, and nitrate nitrogen in water bodies, and the performance of the PSO-MLP model was checked using a test set.
[0110] The above technical features constitute the best embodiment of the present invention, which has strong adaptability and best implementation effect. Non-essential technical features can be added or reduced according to actual needs to meet the needs of different situations.
[0111] Finally, it should be noted that the above content is only used to illustrate the technical solution of the present invention, rather than to limit the scope of protection of the present invention. Simple modifications or equivalent substitutions of the technical solution of the present invention by ordinary technicians in this field do not deviate from the essence and scope of the technical solution of the present invention.
Claims
1. A method for monitoring nitrogen concentration in water based on visible-near infrared spectroscopy technology. It is characterized in that The steps include: S1. Collect several water body hyperspectral reflectance spectrum samples, with the band collection range of 380nm-1000nm; S2, synchronously with step S1, collecting water samples corresponding to the water body hyperspectral reflectance spectrum samples for filtering preprocessing, and dividing the water body samples into a training set, a validation set and a test set after filtering preprocessing; S3. Determine the concentrations of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen in the water samples in each test set; S4, screening the water body hyperspectral reflectance spectrum samples in step S1 using reflectance and normalized difference vegetation index; S5, normalizing the screened water body hyperspectral reflectance spectrum samples; S6. Input the water body hyperspectral reflectance spectrum sample data normalized in step S5 into the PSO-MLP model constructed by optimizing the MLP model using the PSO algorithm, and output the predicted concentrations of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen of the water body hyperspectral reflectance spectrum samples; and use the test set to check the performance of the PSO-MLP model.
2. The method according to claim 1, It is characterized in that In step S4, the method for screening the water body hyperspectral reflectance spectrum samples in step S1 includes: if the reflectance of the water body hyperspectral reflectance spectrum sample at the first band is less than the set first threshold, and the normalized vegetation index of the water body hyperspectral reflectance spectrum sample is less than the set second threshold, and the reflectance of the water body hyperspectral reflectance spectrum sample at the second band is less than the set third threshold, then the water body hyperspectral reflectance spectrum sample is a normal water body hyperspectral reflectance spectrum sample and is retained; otherwise, it is an abnormal water body hyperspectral reflectance spectrum sample and is discarded.
3. The method according to claim 1, It is characterized in that In step S5, the normalization process of the water body hyperspectral reflectance spectrum samples includes: The curve composed of the water body hyperspectral reflectance spectrum collected at the same location is smoothed and denoised, and several spectral band characteristics of the water body hyperspectral reflectance spectrum are obtained; The water body hyperspectral reflectance spectrum is normalized using the formula: Where x norm is the normalized water body hyperspectral reflectance spectrum, x is the water body hyperspectral reflectance spectrum after denoising, and x min is the minimum reflectivity value at different wavelengths, x max is the maximum reflectivity value at different wavelengths.
4. The method according to claim 1, It is characterized in that In step S6, the PSO-MLP model includes a PSO part and an MLP part. The MLP part includes an input layer, a hidden layer and an output layer. The input layer is used to receive the hyperspectral reflectance spectrum characteristics of the water body, the hidden layer is used to extract the hyperspectral reflectance spectrum characteristics of the water body, and the output layer is used to output the prediction results of ammonia nitrogen, protein, urea nitrogen and nitrate nitrogen in the water body; the PSO part is used to use the PSO algorithm to complete the optimization of the MLP part.
5. The method according to claim 4, It is characterized in that The training methods of the PSO-MLP model include: (1) Prepare several water body hyperspectral reflectance spectrum samples; (2) Construct a multi-layer perceptron model, namely, an MLP model, including an input layer, a hidden layer, and an output layer; (3) Initialize PSO algorithm parameters: define the number of particles in the particle swarm; set the particle dimension to be consistent with the total weight and bias number in the MLP model, and randomly initialize the particle speed and position in the search space; (4) Optimize the MLP model using the PSO algorithm to obtain the PSO-MLP model; (5) Select the loss function, optimizer, and evaluation metric, and compile the PSO-MLP model; (6) PSO-MLP model training and evaluation.
6. The method according to claim 5, It is characterized in that In the MLP model: The input layer uses all wavelength collection points in the water body hyperspectral reflectance spectrum sample 380nm-1000nm as input neurons to receive the information of each feature in the input water body hyperspectral reflectance spectrum sample data, so as to provide enough information for the hidden layer to extract features; The hidden layer is set to two layers, and the number of neurons in the first and second layers are set to 64 and 32 respectively; The output layer has one neuron, which is used to output the prediction results of ammonia nitrogen, protein, urea nitrogen, and nitrate nitrogen corresponding to the hyperspectral reflectance spectrum of the water body.
7. The method according to claim 5, It is characterized in that The PSO algorithm is used to optimize the MLP model, including the following steps: Use the particle position to initialize the MLP model and train the model, and use the training set data to calculate the loss value of the MLP model as the fitness value; Use the PSO algorithm to update the position and speed of each particle. In each generation of evolution, if the current fitness value is better than its historical optimal value, then update pbest i If the current fitness value is better than its global historical optimal value, update gbest i , the formula can be expressed as: v i =ωv i +c 1 rand()(pbest i -x i )+c 2 rand()(gbest i -x i ), Where i is the number of spectral bands of the water body hyperspectral reflectance spectrum sample, ω is the inertia weight, and v i is the particle speed, rand() is a random number between (0,1), x i is the current position of the particle, c 1 、c 2 is the learning factor, pbest i is the optimal position of individual particles, gbest i is the optimal position of particles in the group; The iteration is terminated when the maximum number of iterations is reached or the fitness value meets the predetermined minimum fitness threshold, the optimal weights and biases are output, and the PSO-MLP model is constructed using the optimal weights and biases.
8. The method according to claim 7, It is characterized in that PSO-MLP model training and evaluation: Input the training set data into the PSO-MLP model, use the Adam optimizer to further iteratively update the network weights based on the training set data, and adjust different learning rates until the preset number of training times or the preset training accuracy is reached; Input the validation set data into the PSO-MLP model, calculate the loss and evaluation index of the PSO-MLP model, judge the generalization ability of the model, and adjust and optimize the PSO-MLP model according to the results of the validation set to obtain the final PSO-MLP model; The test set data is input into the PSO-MLP model, the loss and evaluation indicators of the PSO-MLP model are calculated, and the final performance of the PSO-MLP model is evaluated.
9. The method according to claim 8, It is characterized in that The nth layer of the MLP model part of the PSO-MLP model, n = 1, 2, ..., the configuration parameter is the weight W n , enter X n , Deviation b n , function f uses sigmoid function or tanh function, and the output of this layer is expressed as: Y n =f(W n X n +b n ), After using the Adam optimizer, the weights and biases are updated with the gradient of the loss function at each iteration, expressed as: In the formula is the weight of the i-th row and j-th column of the n-th layer weight matrix, is the i-th bias of the n-th layer, To find the partial derivative of the loss function with respect to the bias, L(W,b) represents the loss function, W is the weight, b is the bias, and η is the learning rate, which represents the speed at which the neural network accumulates information within a preset time.
10. The method according to claim 8, It is characterized in that In step S6, the performance of the PSO-MLP model is checked using the test set, as follows: The PSO-MLP model uses the ReLU function as the activation function and the determination coefficient R 2 Evaluate the prediction results of various nitrogen substances including ammonia nitrogen, protein, urea nitrogen, and nitrate nitrogen, and select R 2 The highest parameter is taken as the final result, R 2 The formula is: Where p is the number of samples, y i is the measured value of various nitrogen substances in the i-th water sample, is the estimated value of various nitrogen species in the i-th water body hyperspectral reflectance spectrum sample, It is the average value of the measured values of various nitrogen substances in p water samples.
