A method for detecting COD of water body based on spectral technology

By combining the continuous projection algorithm and least squares support vector machine with particle swarm optimization, the problems of data redundancy and noise in the spectral method are solved, and efficient and accurate COD detection in water is achieved.

CN117033938BActive Publication Date: 2025-12-19XIAN UNIV OF POSTS & TELECOMM
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310999702.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-09
Publication Date
2025-12-19
Estimated Expiration
2043-08-09

AI Technical Summary

Technical Problem

Existing spectroscopic methods for water quality testing suffer from problems such as large data volume, excessive redundant information, low analysis efficiency, and impaired model accuracy, especially in the case of inaccurate COD content detection in complex water bodies.

Method used

A detection model is established by extracting spectral feature wavelengths using a continuous projection algorithm, combining least squares support vector machine and particle swarm optimization algorithm, and removing noise using the SG smoothing algorithm.

Benefits of technology

It improves the prediction efficiency and accuracy of COD detection in water bodies, is suitable for water quality testing with small sample sizes, and can quickly obtain stable and accurate COD content.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117033938B_ABST
    Figure CN117033938B_ABST
Patent Text Reader

Abstract

The present application relates to water body COD detection technical field, specifically to a kind of water body COD detection method based on spectral technology, comprising the following steps: S1: obtaining standard absorbance data: using ultraviolet absorption spectrometry, the spectral data of COD standard solution is collected, and standard absorbance data is obtained;S2: the characteristic extraction of standard absorbance data is carried out by continuous projection algorithm, and the standard absorbance data is screened using feature information;S3: with least square support vector machine as detection model, the data obtained by step S2 screening is divided into training set and test set, training detection model using training set, then the detection result accuracy of detection model is tested using test set;S4: the absorbance data of the water sample to be measured is collected, and the detection model obtained in step S3 is used to detect the COD content of the water sample to be measured;The present application determines the detection model parameter using particle swarm optimization algorithm, and the COD content of the water sample to be measured can be accurately obtained by obtaining the detection model.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of water body COD detection, and particularly relates to a water body COD detection method based on spectral technology. BACKGROUND

[0002] With the rapid development of economy, the water quality is significantly decreased, which affects the sustainable development of human life and the survival of people; the water quality is measured according to water quality index parameters, the index parameters include physical indexes and chemical indexes, wherein the chemical indexes include biochemical oxygen demand (BOD), chemical oxygen demand (COD), total organic carbon (TOC), total oxygen demand (TOD), total nitrogen, total phosphorus, pH value and heavy metals, etc. The chemical oxygen demand is one of the important index parameters for detecting the water quality, which reflects the content of the reducing pollutants mainly in the form of soluble organic matter in the water body.

[0003] There are many detection methods for the chemical oxygen demand (COD), which are mainly divided into three categories of chemical method, spectral method and biosensor method, the spectral method includes near-infrared spectroscopy, ultraviolet-visible spectroscopy and fluorescence spectroscopy, however, the following problems exist in the detection of water quality by using the spectral method:

[0004] (1) The spectrometer obtains hundreds of spectral data of wavelengths, and the data amount is very large. In addition, a certain sample amount is also required for spectral analysis, so that the spectral matrix contains a large amount of redundant information, which leads to low efficiency and long time of spectral data analysis, and the irrelevant information contained in the spectral matrix will affect the accuracy of the prediction model;

[0005] (2) The ultraviolet-visible spectroscopy selects the original data after preprocessing to establish a COD-absorbance partial least squares prediction model in the modeling of COD detection, but the composition of the actual water sample is complex, and the absorbance and the COD concentration are in a nonlinear relationship, which is not suitable for the detection of the COD content in the complex water body. SUMMARY

[0006] The present application aims to overcome the defects of the prior art, and provides a water body COD detection method based on spectral technology.

[0007] The present application provides a water body COD detection method based on spectral technology, which comprises the following steps:

[0008] S1: obtaining standard absorbance data:

[0009] The spectral data of the COD standard solution are collected by using the ultraviolet absorption spectroscopy to obtain the standard absorbance data;

[0010] S2: performing feature extraction on the standard absorbance data by a continuous projection algorithm, and screening the standard absorbance data by using the feature information;

[0011] S3: taking a least squares support vector machine as a detection model, dividing the data screened in step S2 into a training set and a test set, training the detection model by using the training set, and testing the detection result accuracy of the detection model by using the test set;

[0012] S4: collecting absorbance data of a water body sample to be detected, and detecting the COD content of the water body sample by using the detection model obtained in step S3.

[0013] Further, the method further comprises, before step S3, pre-processing the standard absorbance data to remove data noise;

[0014] Further, the pre-processing method is an SG smoothing algorithm;

[0015] Further, step S2 specifically comprises:

[0016] S21, an initial iteration vector is , the number of extracted variables is N, the number of spectral matrix array variables is J, and the spectral matrix X;

[0017] S22, before the first iteration, optionally, a 1st column (jth column) of the spectral matrix is selected, the jth column of the training set is assigned to , and is recorded as ;

[0018] A set of positions of column vectors that are not selected is recorded as R, R={j; 1≤j≤J, J∉{k(0),…,k(n-1)}}.

[0019] S23, a selected column vector is calculated , the projection of the remaining vectors is recorded as , and the formula is:

[0020] ;

[0021] S24, a spectral wavelength of the maximum projection vector is extracted ,

[0022] , and ;

[0023] wherein, let , the column vector is reselected, and is recorded as the maximum projection vector calculated before;

[0024] S25, when n=n+1, the extracted wavelength sequence is {k(n); n=0,⋯,N-1}.

[0025] Further, step S25 further comprises if , then the calculation is looped by step S23, a new round of column vector selection is continued, and the band feature data of the selected column vector is extracted.

[0026] Further, in step S3, the nonlinear function expression of the least squares support vector machine is:

[0027] (9);

[0028] wherein x i is the input of the i-th sample, α i is the Lagrange multiplier, is the bias term, and is the kernel function.

[0029] Further, step S4 specifically comprises:

[0030] S31, first, initialize various parameters; population size m, initial position and speed of the particle, maximum number of iterations T, inertia weight w and learning factor, iteration number t; map the positive programming parameter Y and the kernel parameter epsilon into a group of particles, initialize the position and speed of the particle;

[0031] S32, determine the fitness function of the particle; the fitness function expression of the i-th particle is:

[0032] ;

[0033] wherein, is the i-th particle LSSVM training output value of the j-th sample, is the expected output of the j-th sample, and n is the number of particles;

[0034] S33, calculate the fitness function; calculate the fitness value of each particle using the fitness function of step 32;

[0035] S34, set the individual extreme value and the group extreme value; take the individual extreme value with the best fitness value in step 33 as the initial global extreme value , and set the individual extreme value of the particle to the current position,

[0036] S35, update the speed and position of the particle;

[0037] (10);

[0038] (11);

[0039] in formula (10) and formula (11), and is an acceleration factor, and is a random number in [0,1], is the i-th particle. In addition, t is the iteration number, is an inertia weight, is the particle update speed, is the individual extremum of the particle when the iteration number is t, is the global extremum of the particle when the iteration number is t, is the position of the particle when the iteration number is t.

[0040] The speed and position of the current particle are updated according to formula (10) and formula (11);

[0041] S36, the fitness of the particle is updated; the fitness of each particle is updated according to the set fitness function;

[0042] S37, the individual extremum and the global extremum are updated; the smaller the fitness of the particle is, the better the position of the particle is; the fitness of each updated particle is compared with the fitness of the global optimal position of the group, if , the position of the particle is taken as the initial global extremum of the group;

[0043] S38, it is checked whether the optimization condition is met; the optimization condition is the maximum iteration number or the prediction accuracy set in advance; the optimal solution is obtained; the optimal solution is the global optimal position of the group, which is mapped to the positive programming parameter Y and the kernel parameter epsilon, which are parameters of the detection model, and the parameters of the detection model are used for detecting the COD content in the water sample to be detected.

[0044] Further, step S38 further includes, if the optimization condition cannot be met, turning to step S33 to continue a new round of optimization search; through continuous iteration, the particle update speed and position are updated; finally, the optimization condition is met; the optimal solution is obtained; the optimal solution is used to obtain the parameters of the detection model, i.e., the positive programming parameter Y and the kernel parameter epsilon.

[0045] Compared with the prior art, the present application has the following beneficial effects:

[0046] ​(1) The present application adopts particle swarm optimization algorithm to determine the parameters of least squares support vector machine, and the least squares support vector machine is a detection model, which has few parameters, good robustness and short calculation time, is suitable for small sample water quality detection, and through the obtained detection model, more stable and accurate COD content of the water sample to be detected can be quickly obtained;

[0047] (2) The present application adopts continuous projection algorithm to extract feature wavelength information in standard absorbance data, removes redundant and non-information wavelength variables, and improves the prediction efficiency and accuracy of the detection model;

[0048] (3) The present application adopts SG smoothing algorithm to eliminate high-frequency noise in original spectral absorbance data caused by light source, light path and spectrometer, and improve the prediction accuracy of the detection model. BRIEF DESCRIPTION OF DRAWINGS

[0049] The following drawings only schematically illustrate and explain the present application, and do not limit the scope of the present application, in which:

[0050] Figure 1 : The detection method flow chart of the present application;

[0051] Figure 2 : The ultraviolet spectral imaging system diagram in the embodiment of the present application;

[0052] Figure 3 : The ultraviolet absorbance curve diagram in the embodiment of the present application;

[0053] Figure 4 : The spectral diagram after SG smoothing in the embodiment of the present application;

[0054] Figure 5 : The spectral feature data flow chart obtained by the continuous projection algorithm of the present application for screening the pretreated original spectral data;

[0055] Figure 6 : The detection value flow chart of the COD content of the water sample to be detected obtained by the PSO-LSSVM algorithm of the present application;

[0056] Figure 7 : The detection model prediction value and true value comparison diagram of the present application. DETAILED DESCRIPTION

[0057] In order to make the purpose, technical scheme, design method and advantages of the present application more clear and explicit, the present application is further described in detail by specific embodiments combined with the drawings. It should be understood that the specific embodiments described herein are only used to explain the present application, and are not used to limit the present application.

[0058] As Figures 1-7As shown, the present application provides a water body COD detection method based on spectral technology, and the specific steps are as follows:

[0059] S1: obtaining original spectral data; including obtaining the COD content true data of each water quality sample by using the ultraviolet spectral imaging system and obtaining the water quality spectral data of each water quality sample; the water quality spectral data of each water quality sample represents the absorbance of each water quality sample in a preset wavelength range;

[0060] A plurality of groups of water quality samples with different COD concentrations are configured;

[0061] In a specific implementation, the present application selects a COD standard solution with a concentration of 500 mg / L, and dilutes it according to the solution dilution concentration calculation formula. A group of standard solutions is prepared every 5 mg / L, from 5 mg / L to 500 mg / L, a total of 100 groups;

[0062] According to the principle of Lambert Beer's law of ultraviolet absorption spectrum, an ultraviolet spectral imaging system for obtaining sample absorbance is designed; the ultraviolet spectral imaging system mainly includes a light source, a collimating lens, a quartz cuvette, a focusing lens and a spectrometer.

[0063] The light source selected is RK-DL305 deuterium halogen lamp of Riko Optoelectronics, which emits a wavelength range of 200-2500 nm, which meets the required ultraviolet light waveband of the subject. The optical fiber selected is a quartz optical fiber, which avoids the occurrence of model prediction error due to absorption of ultraviolet light. The collimating lens and the focusing lens respectively adopt a group of aspheric lenses to realize accurate control. The light source emits light of different wavebands, which is input to the collimating lens to change the light beam into parallel light, then passes through the quartz cuvette containing the water sample to be measured, and the light beam transmitted through the cuvette is transmitted to the output fiber through the focusing lens. The spectrometer receives the light wave at the output end of the output fiber, converts the light signal into an electrical signal for the host computer, and the ultraviolet spectral imaging system is as shown in Figure 2 ;

[0064] The water quality spectral data of the water quality sample is collected in the following manner: a USB4000 spectrometer of Ocean Optics is used to scan 100 groups of COD standard liquid samples, and the scanning waveband is 200-500 nm. The ultraviolet waveband absorbance curve of each sample is as shown in Figure 3 . Since the light emitted by the light source has weak intensity between 200 nm and 250 nm, the COD in the sample has strong absorption to the light of this waveband, resulting in a large amount of noise in the transmission spectrum in this waveband, so this waveband has no use value. The 250-310 nm waveband forms an absorption characteristic peak, which is mainly formed by the action of benzene ring functional groups. With the increase of the sample concentration, the absorption capacity of the functional group absorption band is obviously enhanced, and there is no absorption saturation phenomenon. Therefore, the 250-310 nm waveband well expresses the characteristics of the organic pollutants in the sample;

[0065] S2: performing feature extraction on the standard absorbance data by a successive projections algorithm, and screening the standard absorbance data by using the feature information;

[0066] In order to improve the precision and efficiency of the model, reduce the redundant information in the spectral data, and extract the characteristic wavelength beneficial to the model, the successive projection algorithm is selected for feature information extraction. The successive projection algorithm is a forward variable selection algorithm, and the goal is to solve the collinearity problem of the modeling variable, so as to improve the modeling and prediction effect of the multivariable. The idea of the algorithm is that a new variable set is constructed by using the method of projecting and mapping the spectral data, and the prediction effect of the new variable is evaluated. A small amount of wavelength data in the original spectral data is selected as the characteristic wavelength, and most of the spectral information of the sample is contained, so that the redundant information is eliminated to the greatest extent. When performing feature extraction, the preprocessed data is divided into 80% training set and 20% test set, the number of characteristic wavelengths with the minimum RMSE is selected after cross validation, and the selected characteristic wavelengths are saved as a new spectral data matrix for model training. The specific process of obtaining the spectral feature data by screening the preprocessed original spectral data through the successive projection algorithm is as shown in Figure 5

[0067] Figure 5 The specific process of obtaining the spectral feature data by screening the preprocessed original spectral data through the successive projection algorithm is as shown in

[0068] S21, the initial iteration vector is denoted as , the number of variables to be extracted is N, the number of spectral matrix array variables is J, and the spectral matrix X is

[0069] S22, before the first iteration (n=1, n is the iteration number), 1 column (the jth column) of the spectral matrix is selected at will, the jth column of the training set (the first 80% of the preprocessed original spectral data is used as the modeling set) is assigned to , and is denoted as .

[0070] The set of positions of the unselected column vectors is denoted as R, R={j;1≤j≤J,J∉{k(0),…,k(n-1)}}.

[0071] S23, the selected column vector is calculated The projection of the remaining vector is denoted as , and the formula is:

[0072] .

[0073] S24, the spectral wavelength of the maximum projection vector is extracted , ​

[0074] and .

[0075] wherein let , reselect the column vector (denoted as before the maximum projection vector calculated).

[0076] S25,n=n+1, the extracted waveband sequence is {k(n); n=0, …, N-1}, if n<N, then the step (23) is cycled to calculate, a new round of column vector selection is continued, and the waveband feature data of the selected column vector is extracted;

[0077] It should be noted that for k(0) and N in each cycle, a prediction model is established respectively, a root mean square error of cross validation (RMSECV) of the modeling set is obtained, and the k(0) and N corresponding to the minimum RMSECV value are the optimal values.

[0078] S3: pre-processing the standard absorbance data by the SG smoothing algorithm to remove data noise;

[0079] The steps of pre-processing the original spectrum by the SG smoothing algorithm are as follows:

[0080] Firstly, the parameters of SG smoothing include the derivative order s (the original spectrum is smoothed as O order derivative), the polynomial degree n and the smoothing point number 2m+1.

[0081] Secondly, the SG smoothing takes 2m+1 continuous points in the spectrum interval as a window, and each point in the window is least square fitted by a polynomial (with the point numbers 0, ±1, ±2, … ±m as variables) to obtain the corresponding polynomial coefficients.

[0082] Then the smoothing value of the center wavelength point of the window is calculated by using the obtained polynomial coefficients. By moving the window, the smoothing value of each window center point can be obtained, and thus the original SG smoothed spectrum is obtained.

[0083] Wherein, the window width is set to 19 (n=2m+1), the polynomial order is taken as 3 order, each measurement point is m, and the value is 0, ±1, ±2, …, ±9, and the fitting formula y is:

[0084] (1).

[0085] In the above formula, X is the absorbance of the sample, the measurement point value corresponding to a window, Y is the COD concentration of the sample, , , , is the polynomial fitting coefficient.

[0086] According to the width of the window, 19 equations similar to equation (1) can be listed, which form a 4-element linear equation group, which can be expressed by a matrix:

[0087] (2) ;

[0088] In equation (2), m=9, A is the fitting coefficient matrix, and E is the infinitesimal deviation matrix. The coefficient matrix A can be obtained by least square fitting, and is denoted as Ȧ. The expression of the least square solution Ȧ can be written as:

[0089] (3) ;

[0090] Then, the filtered value matrix Ȏ of the sample COD concentration Y can be expressed as:

[0091] (4) ;

[0092] It should be noted that the SG smoothing algorithm uses an n-order polynomial to fit the data points in a moving window of a certain size, thereby achieving data smoothing. According to the actual spectral data, the SG filter window size is selected to be 19, and the polynomial order is selected to be 3. Figure 4 The spectrum after SG smoothing is shown in Fig. 2.

[0093] Since there are high-frequency noises caused by light sources, optical devices and spectrometers in the data, as well as scattering caused by contaminant particles in the configuration, the SG smoothing preprocessing method is selected to eliminate the high-frequency noises caused by light sources, optical paths and spectrometers in the original spectral absorbance data, so as to improve the prediction accuracy of subsequent modeling.

[0094] S3: Using the least square support vector machine as a detection model, the data selected in step S2 is divided into a training set and a test set, the training set is used to train the detection model, and then the test set is used to test the detection result accuracy of the detection model;

[0095] S4: Collecting the absorbance data of the water sample to be detected, using the detection model obtained in step S3 to detect the COD content of the water sample to be detected.

[0096] It should be noted that the least square support vector machine (LSSVM) is improved on the basis of the support vector machine (SVM), which is similar to the support vector machine.

[0097] The least squares support vector machine performs function fitting by mapping input data from a regular space to a high-dimensional space, replacing inequality constraints with equality constraints, solving a minimum loss function in the high-dimensional space, and obtaining a linear fitting function.

[0098] The least squares support vector machine (LSSVM) is an extension of the support vector machine (SVM) and has strong capabilities in nonlinear modeling, solving small sample problems, and data mining. When performing function fitting, the least squares support vector machine maps input data from a regular space to a high-dimensional space, replaces inequality constraints with equality constraints, and uses the sum of squared errors as the empirical loss of the training set. Thus, solving a quadratic programming problem is converted into solving a linear equation system, improving the speed and convergence accuracy of problem solving.

[0099] Figure 6 As shown, the spectral feature data is modeled by the particle swarm optimization least squares support vector machine to obtain a detection model, and the specific steps are as follows:

[0100] Given a sample data {x i , y i}, where i = 1, 2, …, x i is the input of the i-th sample, and y is the output of the i-th sample. LSSVM uses nonlinear mapping to map the training sample set to a high-dimensional feature space, thereby converting the nonlinear function estimation problem into a linear function estimation problem in the high-dimensional feature space. The regression function is assumed to be y = <w· >+b, where w is the weight vector, <·> is the inner product, and b is the bias term.

[0101] In the least squares support vector regression, the regression problem becomes:

[0102] (5) ;

[0103] In the formula, ξ is an error variable, and ϒ is a penalty coefficient.

[0104] LSSVM replaces inequality constraints with equality constraints, and KKT conditions are used to solve optimization problems with inequality constraints. KKT conditions convert the extreme value of inequality constraints into the extreme value of equality constraints, thereby completely converting into the extreme value problem of unconditional constraints. The Lagrange operator is commonly used in the solution of equality constraint optimization and is a special form of KKT conditions. In order to solve special equality constraint problems, the Lagrange function is introduced to obtain:

[0105] (6) ;

[0106] In the formula, a i is a Lagrange multiplier;

[0107] The Lagrange multiplier method converts the original equality constraint optimization problem into an equivalent unconstrained optimization problem , and the optimal solution of the unconstrained optimization problem is necessary , and the following linear equations can be obtained:

[0108] (7) ;

[0109] In the formula, P=[ , , , ], is a symmetric matrix of the kernel function; I is a unit matrix, ; q= , is a result matrix of the regression function; a= , is a Lagrange multiplier matrix.

[0110] According to the Mercer condition (a necessary and sufficient condition for the kernel function is that the K matrix is semi-positive definite), the kernel function expression is:

[0111] (8) ;

[0112] After a and b are obtained by simultaneously solving formula (7) and formula (8), the nonlinear function formula of LSSVM can be obtained:

[0113] (9) ;

[0114] The least square support vector machine needs to determine the kernel function, and there is a difference in the results of different kernel functions.

[0115] The particle swarm optimization (PSO) method is adopted to select the regularization parameter gamma and the kernel parameter epsilon of the LSSVM; a good nonlinear function formula of the LSSVM is obtained, which is set as a detection model, and the COD content detection value of the water body sample to be detected is obtained through the detection model;

[0116] The kernel function has a polynomial kernel function, and the RBF kernel function is selected as the kernel function in the LSSVM model, the RBF (radial basis) kernel function is a kind of nonlinear kernel function, which can effectively reduce the calculation complexity of modeling and improve the prediction performance of the model;

[0117] Two types of parameters are crucial in LSSVM modeling: the normalization parameter γ and the kernel parameter ε. Determining the optimal normalization and kernel parameters is a model selection problem. A common parameter selection method is cross-validation, but this is very time-consuming. This paper proposes using particle swarm optimization (PSO) to select the normalization parameter γ and kernel parameter ε for LSSVM.

[0118] Particle Swarm Optimization (PSO) is a numerical optimization algorithm based on the principle of "information sharing." It boasts fast convergence, few parameters, and simple implementation (faster than genetic algorithms for high-dimensional problems). The core idea of ​​PSO is to use particles to represent individual birds. Each particle searches the search space, and its flight is the search process. The flight speed can be dynamically adjusted based on the particle's historical best position and the population's historical best position. The particle's current position is a candidate solution to the optimization problem, called the individual extremum. The optimal individual extremum in the swarm is called the global optimum. Through continuous iteration, particles update their speed and position, and the final globally optimal solution that satisfies the given conditions is the target (the required parameters).

[0119] like Figure 6 As shown, a detection model is obtained by modeling the spectral feature data using particle swarm optimization least squares support vector machine. The specific steps are as follows:

[0120] S31, first initialize various parameters; population size m, initial positions of particles. and speed The maximum number of iterations T, the inertia weight w, and the learning factor, and the number of iterations t; map the positive programming parameters ϒ and kernel parameters ε to a group of particles, and initialize the position and velocity of the particles.

[0121] S32, Determine the fitness function of the particles; Select the root mean square error function expression that reflects the LSSVM regression performance. for:

[0122] ;

[0123] As the fitness function of the i-th particle, where, It is the LSSVM training output value of the i-th particle of the j-th sample. is the expected output of the j-th sample, and n is the number of particles.

[0124] S33, Calculate the fitness function; use the fitness function from step 32 to calculate the fitness value of each particle;

[0125] S34, Set the initial individual extreme value and the population extreme value; take the individual extreme value with the best fitness value in step 33 as the initial global extreme value. , the individual extremum of the particle is set to the current position,

[0126] S35, update the velocity of the particle and position ; calculate the inertia weight ,

[0127] ;

[0128] (10);

[0129] (11);

[0130] wherein, and is an acceleration factor, and is a random number in [0, 1], is the i-th particle,

[0131] t is the iteration number, is the inertia weight, is the particle update velocity, is the individual extremum of the particle at the iteration number t, is the global extremum of the particles at the iteration number t, is the position of the particle at the iteration number t.

[0132] update the velocity and position of the current particle according to formula (10) and formula (11);

[0133] S36, update the fitness of the particle; update the fitness of each particle according to the set fitness function.

[0134] S37, update the individual extremum and the global extremum; the smaller the fitness of the particle is, the better the position of the particle is; compare the fitness of each updated particle with the fitness of the global optimal position , if < , the position of the particle is taken as the initial global extremum of the group.

[0135] S38, check whether the optimization end condition is met (such as reaching the pre-set maximum iteration number or the prediction accuracy), if the optimization end condition is met, end the optimization and obtain the optimal solution (the optimal position of the global particle ​Mapping to normalization parameters γ and kernel parameters ε), and using this as the optimization result, we obtain a well-established LSSVM model for prediction; otherwise, we go to step 33 to continue a new round of optimization search. Through continuous iteration, the particle updates its speed and position, and the final global optimal solution that meets the conditions is the target.

[0136] Finally, a pre-established LSSVM model is built using particle swarm optimization least squares support vector machine to predict the spectral feature data. The established LSSVM model is set as the detection model. Through the detection model, the COD concentration in the water sample to be tested can be obtained more quickly and stably.

[0137] It should be noted that commonly used models in ultraviolet spectroscopy for COD detection in water quality, such as partial least squares (PLS), neural networks, and PSO-LSSVM, were selected for comparison. The three models were trained on the preprocessed and feature-extracted data, and the prediction accuracy of different model combinations was compared. The results are shown in Table 1, which shows the prediction results of different modeling methods after SG smoothing preprocessing.

[0138]

[0139] Table 1

[0140] The results table shows that when the samples are divided into 82 training sets and 18 prediction sets, the predicted values ​​of the detection model tend to be consistent with the actual values. Figure 7 As shown, the prediction performance of the SG smoothing preprocessing combined with the PSO-LSSVM model is superior to other algorithm combinations. The normalization parameter γ and kernel parameter ε in the LSSVM algorithm, after particle swarm optimization, are determined to be 609.55 and 1.67, respectively. The number of feature wavelengths extracted by the continuous projection algorithm is 14, and the RMSE is 16.14. By obtaining the detection model, a more stable and accurate COD concentration in the water sample can be quickly obtained. This invention uses a particle swarm optimized least squares support vector machine regression detection model. Compared with nonlinear neural networks and linear PLS models, this detection model has fewer parameters, better robustness, and shorter computation time, making it suitable for small sample size water quality detection.

[0141] It should be noted that 1) the spectrometer obtains hundreds of spectral data of wavelengths, and the data amount is very large. In addition, a certain amount of samples are required for spectral analysis, resulting in that the spectral matrix contains a large amount of redundant information, leading to low efficiency and long time of spectral data analysis, and irrelevant information contained in the spectral matrix will affect the accuracy of the prediction model. Therefore, in order to obtain the wavelength variable beneficial to modeling from the collected spectral data, remove the redundant and non-information wavelength variable, and improve the accuracy of the light prediction model, the application adopts the continuous projection algorithm to extract the characteristic wavelength of the original spectrum. 2) The actual water body is relatively complex, and the correlation between the COD concentration and the absorbance data of the ultraviolet light band is unstable, and is not a linear relationship, but the prediction model used in many studies is the partial least squares algorithm, which is not suitable for the detection of COD content in complex water bodies. The least squares support vector machine combined with particle swarm optimization regression prediction model used in the detection scheme has fewer parameters, shorter prediction time and is suitable for small sample water quality detection compared with the nonlinear model neural network and the linear model PLS.

[0142] It should be noted that: 1) the particle swarm optimization algorithm is used to determine the parameters of the least squares support vector machine, and the least squares support vector machine is used as a detection model, which has fewer parameters, good robustness and short calculation time, and is suitable for small sample water quality detection. The detection model can quickly obtain more stable and accurate COD content of the water sample to be detected;

[0143] 2) The continuous projection algorithm is used to extract the characteristic wavelength information in the standard absorbance data, remove the redundant and non-information wavelength variable, and improve the prediction efficiency and accuracy of the model.

[0144] 3) The SG smoothing algorithm is used in the application to eliminate the high-frequency noise in the original spectral absorbance data caused by the light source, light path and spectrometer, so as to improve the prediction accuracy of subsequent modeling.

[0145] The above has described the embodiments of the application, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes are obvious to those skilled in the art without departing from the scope and spirit of the described embodiments. The selection of the terms used herein is intended to best explain the principles, practical applications or technical improvements in the market of the embodiments, or to enable other ordinary skilled persons in the art to understand the embodiments disclosed herein.

Claims

1. A method for detecting COD of water body based on spectral technology, characterized in that, The method comprises the following steps: S1: obtaining standard absorbance data: Using ultraviolet absorption spectrum method, the spectral data of COD standard solution is collected to obtain standard absorbance data; S2: extracting features of the standard absorbance data by using a continuous projection algorithm, and screening the standard absorbance data by using the feature information, specifically comprising: S21, initial iteration vector is , the number of extracted variables is N, the number of spectral matrix variable is J, and the spectral matrix X; S22, before the first iteration, optionally one column of the spectral matrix, the jth column of the training set is assigned the value , denoted ; The set of positions of the unselected column vectors is R, R={j;1≤j≤J,J∉{k(0),…,k(n-1)}}; S23, get the selected column vector The projection of the remaining vector, denoted as , projection formula is: ; S24, extracting spectral wavelengths of the maximum projection vector , and ; where let , reselect the column vector, denoted as before the maximum projection vector calculated; S25, the extracted wave band sequence is {k(n);n=0,⋯,N-1}; S3: taking the least squares support vector machine as a detection model, dividing the data screened in step S2 into a training set and a test set, training the detection model by using the training set, then testing the detection result accuracy of the detection model by using the test set; and determining the parameters of the least squares support vector machine by using a particle swarm optimization algorithm; S4: collecting absorbance data of a water body sample to be detected, and detecting the COD content of the water body sample to be detected by using the detection model obtained in step S3.

2. The method for detecting COD of water body based on spectral technology according to claim 1, characterized in that, The method further comprises, before step S3, pre-processing the standard absorbance data to remove data noise.

3. The method for detecting COD of water body based on spectral technology according to claim 2, characterized in that, The pre-processing method is an SG smoothing algorithm.

4. The method for detecting COD of water body based on spectral technology according to claim 1, characterized in that, Step S25 also includes if then loop calculation by step S23, continue a new round of column vector selection, and extract the band feature data of the selected column vector.

5. The method for detecting COD of water body based on spectrum technology according to claim 1, characterized in that, In step S3, the non-linear function expression of the least squares support vector machine is is: (9); where x i is the input of the i-th sample, a i is the Lagrange multiplier, is the bias term, is the kernel function.

6. The method for detecting COD of water body based on spectral technology according to claim 1, characterized in that, The particle swarm optimization algorithm is used to determine the parameters of the least squares support vector machine, specifically comprising: S31, first initialize various parameters; population size m, initial position of particles and velocity , maximum number of iterations T, inertia weight w and learning factor, iteration number t; map positive programming parameters Y and kernel parameters epsilon to a group of particles, initialize the position and velocity of particles; S32, determining a fitness function of the particle; the fitness function expression of the ith particle is is: ; In the formula, is the i-th particle LSSVM training output value of the j-th sample, is the expected output of the j-th sample, and n is the number of particles. S33, calculating the fitness function; the fitness value of each particle is calculated by using the fitness function of step 32; S34, setting the initial individual extreme value and the group extreme value; taking the individual extreme value with the best fitness value in step 33 as the initial global extreme value , the individual extreme value of the particle is set as the current position, S35, updating the speed and position of the particle; (10); (11); in formula (10) and formula (11), and is an acceleration factor, and is a random number in [0, 1], is the i-th particle; t is the iteration number, is an inertia weight, is the particle update speed, is the individual extremum of the particle when the iteration number is t, is the overall extremum of the particle when the iteration number is t, is the position of the particle when the iteration number is t; The speed and position of the current particle are updated according to formula (10) and formula (11); S36, updating the fitness calculation of the particle; the fitness value of each particle is updated according to the set fitness function; S37, Update individual and group extreme values; the smaller the particle's fitness value, the better its position; update the values ​​of each particle... with the group's optimal position Comparing fitness values, if Then the particle's As the initial global extremum of the group ; S38, check if the optimization condition is met, the optimization condition is a pre-set maximum iteration number or a prediction accuracy, find the optimal solution, the optimal solution is the group optimal position , the group optimal position mapping to positive programming parameters Y and kernel parameters epsilon, the positive programming parameters Y and kernel parameters epsilon are parameters of the detection model.

7. The method according to claim 6, characterized in that, Step S38 further comprises, if the optimization condition cannot be met, turning to step S33 to continue a new round of optimization search, and through continuous iteration, the speed and position of the particle are updated, finally the optimization condition is met, the optimal solution is obtained, and the parameter γ and the kernel parameter ε of the detection model are obtained through the optimal solution.

Citation Information

Patent Citations

  • Multi-substance parameter detection device and method

    CN113358593A

  • Distributed industrial energy operation optimization platform automatically constructing intelligent models and algorithms

    US20220382263A1