A water quality detection method and electronic equipment based on transmission spectrum analysis
By improving the BP neural network and feature extraction module optimized by the starfish optimization algorithm, combined with the pre-processing and dimensionality reduction of spectral transmittance data, the problem of inaccurate detection of existing water quality detection systems in complex environments is solved, and more accurate water quality detection is achieved.
Patent Information
- Application Number
- CN202510062712.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-05-20
- Estimated Expiration
- 2045-01-15
AI Technical Summary
Existing water quality detection systems are difficult to fully and accurately reveal the chemical reaction mechanism and interaction relationship inside water bodies under complex environmental conditions, and perform poorly when facing mixture interference and baseline drift.
The BP neural network and feature extraction module optimized by improved starfish optimization algorithm are used to form a water quality detection model. Through the pre-processing of spectral transmittance data, dimensionality reduction and multi-scale feature extraction, accurate detection of water quality is achieved.
By improving the starfish optimization algorithm to optimize the threshold and weight of the BP neural network, the problem of selecting BP neural network parameters is solved, the accuracy of water quality detection is improved, and the needs of complex water quality detection can be better met.
Smart Images

Figure CN119474843B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of water quality detection, and particularly relates to a water quality detection method and an electronic device based on transmission spectrum analysis. Background Art
[0002] With the increasing awareness of environmental protection and the progress of science and technology, water quality detection technology has developed rapidly. At present, most water quality detection systems on the market rely on single spectrum analysis or limited pattern recognition technology. Although they can provide reliable results to a certain extent, under complex environmental conditions, especially when facing problems such as mixture interference and baseline drift, the performance of existing technologies still has limitations. Traditional single-modal inversion methods are difficult to comprehensively and accurately reveal the complex chemical reaction mechanisms and interaction relationships inside the water body when dealing with multi-component and multi-source water quality problems. When establishing reference spectral data for existing water quality detection systems, it is difficult to timely reflect the subtle changes in water quality conditions only by static reference. Summary of the Invention
[0003] In view of the above-mentioned problems, many researchers have proposed various solutions, but the effects are not significant. In order to actually solve the current technical problems, the present invention discloses a water quality detection method and an electronic device based on transmission spectrum analysis. The method consists of a water quality detection model composed of a BP neural network optimized by an improved starfish optimization algorithm and a feature extraction module, which is used to accurately detect the water quality.
[0004] The present invention is realized by the following technical solutions. A water quality detection method based on transmission spectrum analysis includes the following steps:
[0005] Step 1. Use a spectrometer to scan the collected water body, and obtain spectral transmittance data through whiteboard correction;
[0006] Step 2. Use two preprocessing methods, normalization and mean centering, to unify the dimensions and center points of the spectral data, and obtain the final spectral transmittance data set;
[0007] Step 3. Use kernel principal component analysis to reduce the dimension of the spectral transmittance data set, and obtain the reduced-dimensional sample data set;
[0008] Step 4. Build a BP neural network and determine the number of nodes in the input layer, hidden layer, and output layer of the BP neural network;
[0009] Step 5. Use the original threshold and original weight of the BP neural network as the initial population position of the improved starfish optimization algorithm to perform optimization, and obtain the optimal threshold and optimal weight of the BP neural network;
[0010] Step 6. Convolution kernels of different sizes are used as the feature extraction module in parallel. The extracted multi-scale features are connected through a splicing layer and inserted between the input layer and the hidden layer of the BP neural network, so as to extract multi-scale features from the data;
[0011] Step 7. Use the sample data set after dimensionality reduction to train the water quality detection model composed of the BP neural network and the feature extraction module that have obtained the optimal threshold and optimal weights, and use the trained water quality detection model to detect the water quality.
[0012] Further preferably, the process of the improved starfish optimization algorithm in Step 5 is as follows:
[0013] Step 5.2.1: Set the population size and the maximum number of iterations;
[0014] Step 5.2.2: Initialize the population;
[0015] Introduce the Henon chaotic map to initialize the population;
[0016] ;
[0017] ;
[0018] ;
[0019] In the formula, X represents the initialized population, represents the j-th dimensional position of the i-th starfish individual after chaotic mapping, i ∈ 1, 2, …, n; j ∈ 1, 2, …, d; n is the population size, and d is the dimension of the problem; represents the j-th dimensional position of the i-th starfish individual before chaotic mapping; each starfish individual represents a set of parameter solutions of the original threshold and original weights of the BP neural network, rand is a random number between 0 and 1, and are the upper and lower bounds of the problem respectively; r represents a random number between (0, 1);
[0020] Step 5.2.3: Calculate the fitness;
[0021] Step 5.2.4: Exploration stage;
[0022] If the dimension of the optimization problem is greater than 5, update the position according to the following formula:
[0023] ;
[0024] ;
[0025] ;
[0026] and respectively represent the updated position and the current position of the p - dimension of the i - th starfish individual, represents the p - dimension of the current best position, T is the current iteration number, is the maximum iteration number, is a constant value, θ is an adaptive factor that changes with the iteration number, and θ is in the range of [0, π / 2];
[0027] If the dimension of the optimization problem is no more than 5, the one - dimensional search mode is adopted to update the position in the exploration stage:
[0028] ;
[0029] ;
[0030] In the formula, and are two random numbers between (-1, 1) respectively, is the energy of the starfish; and are the current positions of the p - dimension of two randomly selected starfish individuals;
[0031] Step 5.2.5: Exploitation stage;
[0032] First, calculate the five distances between the best position and other starfish individuals, then randomly select two distances as confirmations, and use the parallel bidirectional search strategy to update the position of each starfish individual. The distance calculation formula is:
[0033] ;
[0034] Among them, is the distance between the 5 obtained global best starfish individuals and other starfish individuals, is one of the 5 randomly selected starfish individuals, represents the current best position. Model the update rule of each starfish individual in the predation behavior as:
[0035] ;
[0036] ;
[0037] Among them, represents the updated position of the i - th starfish individual, represents the current position of the i - th starfish individual, and are random numbers between (0, 1), and are Two random values therein; N is the set number of populations;
[0038] Step 5.2.6: Escape mechanism;
[0039] The position update process is as follows:
[0040] ;
[0041] In the formula: is a random number within the interval;
[0042] Step 5.2.7: Update the fitness and determine whether the maximum number of iterations is reached. If not, continue the iteration; otherwise, stop the iteration and output the optimal solution, which is the optimal threshold and optimal weight of the BP neural network.
[0043] Further preferably, the number of nodes in the input layer of the BP neural network is equal to the dimension of the input vector, and the dimension of the input vector is the dimension of the selected sample data set.
[0044] Further preferably, the number of nodes in the output layer of the BP neural network is the same as the number of prediction results.
[0045] Further preferably, the number of nodes in the hidden layer of the BP neural network is determined by the following formula:
[0046] ;
[0047] In the formula, N h represents the number of nodes in the hidden layer, N p represents the number of nodes in the input layer, N o represents the number of nodes in the output layer, is a constant between [1, 10].
[0048] Further preferably, Step 6 includes the following sub-steps:
[0049] Step 6.1: Perform multi-scale feature extraction on the data input to the input layer in parallel with three branches using convolution kernels of 3×3, 5×5, and 7×7 respectively;
[0050] Step 6.2: Use a concatenation layer (connect) to merge the features extracted from the three branches to obtain a one-dimensional data sequence;
[0051] Step 6.3: Connect to the hidden layer of the BP neural network through a connection layer.
[0052] The present invention also provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory. When the computer program is executed by the processor, each step of the water quality detection method based on transmission spectrum analysis is implemented.
[0053] The present invention also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, each step of the water quality detection method based on transmission spectrum analysis is implemented.
[0054] Advantages of the present invention: The improved starfish optimization algorithm is used to optimize the BP neural network for water quality detection, which solves the problem that it is difficult to accurately select the thresholds and weights of the BP neural network. It can accurately detect the water quality. After optimizing the thresholds and weights with the improved starfish optimization algorithm, the water quality detection of the BP neural network will be more accurate and can meet the needs of water quality detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] Figure 1 It is a flowchart of the improved starfish optimization algorithm.
[0056] Figure 2 It is a comparison chart of the convergence curves before and after the improvement of the starfish optimization algorithm. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0057] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0058] Embodiment 1
[0059] A water quality detection method based on transmission spectrum analysis includes the following steps:
[0060] Step 1. Use a spectrometer to scan the collected water body and obtain spectral transmittance data through whiteboard calibration;
[0061] Step 2. Use two preprocessing methods, normalization and mean centering, to unify the dimensions and central points of the spectral data to obtain the final spectral transmittance data set;
[0062] Step 3. Use kernel principal component analysis to reduce the dimension of the spectral transmittance data set to obtain the reduced-dimensional sample data set;
[0063] Step 3.1: Perform standardization processing on the spectral transmittance data set to obtain a standardized spectral transmittance data set Calculate the covariance using the kernel function and the non - linear function to obtain the covariance matrix:
[0064] ;
[0065] In the formula: E represents the covariance matrix; is the j - th sample data after processing, ; m is the number of samples, is the non - linear function.
[0066] Step 3.2: The eigenvalues and eigenvectors in the covariance matrix E satisfy the following relationship:
[0067] ;
[0068] In the formula: is the eigenvalue of the covariance matrix E; V is the eigenvector of the covariance matrix E;
[0069] Step 3.3: Perform a linear transformation on the non - linear function:
[0070] ;
[0071] In the formula, is the constant coefficient before the non - linear function.
[0072] Step 3.4: The projection of any sample on the principal component in the feature space is:
[0073] ;
[0074] where, K is the kernel matrix vector.
[0075] Step 4. Build a BP neural network and determine the number of nodes in the input layer, hidden layer, and output layer of the BP neural network;
[0076] Step 4.1: Determine the number of nodes in the input layer of the BP neural network. During the building process, the number of nodes in the input layer of the BP neural network is equal to the dimension of the input vector. In the present invention, the dimension of the input vector is the dimension of the selected sample data set. Therefore, the number of nodes in the input layer of the BP neural network is 10.
[0077] Step 4.2: Determine the number of nodes in the output layer of the BP neural network. The number of nodes in the output layer is the same as the number of prediction results. Therefore, the number of nodes in the output layer is 1.
[0078] Step 4.3: Determine the number of nodes in the hidden layer of the BP neural network. The number of nodes in the hidden layer is determined by the following formula:
[0079] ;
[0080] In the formula, N h represents the number of hidden layer nodes, N p represents the number of input layer nodes, N o represents the number of output layer nodes, is a constant between [1, 10]. After calculation, the number of hidden layer nodes of the present invention is determined to be 12.
[0081] Step 5. Use the original thresholds and original weights of the BP neural network as the initial population positions of the improved starfish optimization algorithm to perform optimization, and obtain the optimal thresholds and optimal weights of the BP neural network;
[0082] Step 5.1: Use the original thresholds and original weights of the BP neural network as the initial positions of the starfish population;
[0083] A starfish is a marine invertebrate belonging to the class Asteroidea of the phylum Echinodermata. It usually has 5 arms and a central disc, giving it a unique star-like appearance. The SFOA mainly includes two stages: exploration and exploitation. The exploration stage simulates the exploration behavior of starfish and adopts a hybrid search mode combining five-dimensional and one-dimensional search modes, which improves the computational efficiency and ensures the search capacity. The exploitation stage simulates the predation and regeneration behaviors of starfish and adopts a two-way search strategy and special movement to ensure the convergence of exploitation. The process of the improved starfish optimization algorithm is as Figure 1 shown, and the convergence curves of the improved starfish optimization algorithm and the original starfish optimization algorithm are as Figure 2 shown.
[0084] Step 5.2.1: Set the population size and the maximum number of iterations;
[0085] Step 5.2.2: Initialize the population;
[0086] Introduce the Henon chaotic map to initialize the population, and solve the problem of uneven distribution of the initial population caused by the random generation of the initial population of the original algorithm.
[0087] ;
[0088] ;
[0089] ;
[0090] In the formula, X represents the initialized population, represents the j-th dimensional position of the i-th starfish individual after chaotic mapping, where i ∈ 1, 2, …, n; j ∈ 1, 2, …, d; n is the population size, and d is the dimension of the problem; Represents the j-th dimensional position of the i-th starfish individual before chaotic mapping; each starfish individual represents a set of parameter solutions of the original thresholds and original weights of a BP neural network, rand is a random number between 0 and 1, and are the upper and lower bounds of the problem respectively; r represents a random number between (0,1).
[0091] Step 5.2.3: Calculate the fitness;
[0092] Step 5.2.4: Exploration stage;
[0093] If the dimension of the optimization problem is greater than 5, the search space of this problem is very wide, and it is necessary for the starfish to move all five arms to explore the surrounding environment. Therefore, a mathematical model for this stage is established:
[0094] Aiming at the disadvantage of the slow convergence speed of the starfish optimization algorithm, an adaptive factor is introduced to improve the exploration stage:
[0095] ;
[0096] ;
[0097] ;
[0098] and represent the updated position and the current position of the p-th dimension of the i-th starfish individual respectively, represents the p-th dimension of the current best position, T is the current iteration number, is the maximum iteration number, is a constant value, θ is an adaptive factor that changes with the iteration number, and θ is in the range of [0,π / 2].
[0099] If the dimension of the optimization problem is not greater than 5, the exploration stage adopts a one-dimensional search mode to update the position. In this case, only one arm of the starfish moves to search for the food source, using the position information of other starfish. The updated position can be established as:
[0100] ;
[0101] ;
[0102] In the formula, and are two random numbers between (-1,1) respectively, is the energy of the starfish; and are the current positions of the p-th dimension of two randomly selected starfish individuals.
[0103] Step 5.2.5: Development stage;
[0104] In the development stage, predation and regeneration behaviors are considered to seek the global solution. Therefore, two update strategies are designed in the development stage. To simulate the predation stage of starfish, the starfish optimization algorithm adopts a parallel bidirectional search strategy, which requires using the information of other starfish individuals and the best position of the current population. First, five distances between the best position and other starfish individuals are calculated, and then two distances are randomly selected as confirmations to update the position of each starfish individual using the parallel bidirectional search strategy. The distance calculation formula is:
[0105] ;
[0106] where, is the distance between the five obtained global best starfish individuals and other starfish individuals, is one of the five randomly selected starfish individuals, represents the current best position. Therefore, the update rule of each starfish individual in the predation behavior is modeled as:
[0107] ;
[0108] ;
[0109] where, represents the updated position of the i-th starfish individual, represents the current position of the i-th starfish individual, and are random numbers between (0, 1), and are two random values in; N is the set number of populations.
[0110] Step 5.2.6: Escape mechanism;
[0111] Aiming at the disadvantage that the starfish optimization algorithm is prone to falling into local optimal values in the later stage of iteration, an escape mechanism is introduced to improve it. The position update process is as follows:
[0112] ;
[0113] In the formula: is a random number within the interval;
[0114] Step 5.2.7: Update the fitness and determine whether the maximum number of iterations is reached. If not, continue the iteration; otherwise, stop the iteration and output the optimal solution, which is the optimal threshold and optimal weight of the BP neural network.
[0115] Step 6. Use convolution kernels of different sizes as a feature extraction module in parallel, and connect the extracted multi-scale features through a connection layer (connect), inserting it between the input layer and the hidden layer of the BP neural network, so as to perform multi-scale feature extraction on the data;
[0116] Step 6.1: Respectively use 3×3, 5×5, and 7×7 convolution kernels to perform multi-scale feature extraction on the data input to the input layer in a parallel manner with three branches;
[0117] Step 6.2: Use a connection layer (connect) to merge the features extracted from the three branches to obtain a one-dimensional data sequence;
[0118] Step 6.3: Connect it to the hidden layer of the BP neural network through a connection layer.
[0119] Step 7. Use the downscaled sample data set to train the water quality detection model composed of the BP neural network and the feature extraction module that have obtained the optimal threshold and optimal weights, and use the trained qualified water quality detection model to detect the water quality.
[0120] Example 2
[0121] This example provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory. When the computer program is executed by the processor, it implements each step of the water quality detection method based on transmission spectrum analysis as described in Example 1.
[0122] Example 3
[0123] This example provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements each step of the water quality detection method based on transmission spectrum analysis as described in Example 1.
[0124] Finally, it should be noted that the above are only the preferred embodiments of the present invention and are not used to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, for those skilled in the art, they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A water quality detection method based on transmission spectroscopy analysis, characterized in that: The following steps are involved: Step 1. Use a spectrometer to scan the collected water body and obtain spectral transmittance data through whiteboard correction; Step 2. Use normalization and mean centering preprocessing methods to unify the dimension and center point of the spectral data to obtain the final spectral transmittance data set; Step 3. Use kernel principal component analysis to reduce the dimension of the spectral transmittance data set to obtain a sample data set after dimension reduction; Step 4. Build a BP neural network and determine the number of nodes in the input layer, hidden layer, and output layer of the BP neural network; Step 5. Use the original threshold and original weight of the BP neural network as the initial population position of the improved starfish optimization algorithm to search for the optimal threshold and optimal weight of the BP neural network; Step 6. Use convolution kernels of different sizes in parallel as feature extraction modules, connect the extracted multi-scale features through the splicing layer, and insert them between the input layer and the hidden layer of the BP neural network to extract multi-scale features of the data; Step 7. Use the sample data set after dimensionality reduction to train the water quality detection model composed of the BP neural network and feature extraction module that have obtained the optimal threshold and optimal weight, and use the trained qualified water quality detection model to detect water quality; The process of improving the starfish optimization algorithm described in step 5 is as follows: Step 5.2.1: Set the population size and maximum number of iterations; Step 5.2.2: Population initialization; Introduce Henon chaotic mapping to initialize the population; ; ; ; In the formula, X represents the initialization population, represents the j-th dimensional position of the i-th starfish individual after chaotic mapping, i∈1,2,…,n; j∈1,2,…,d; n is the population size, d is the dimension of the problem; represents the j-th dimensional position of the i-th starfish individual before the chaotic mapping; each starfish individual represents a set of parameter solutions of the original threshold and original weight of the BP neural network, and rand is a random number between 0 and 1. and are the upper and lower bounds of the problem respectively; r represents a random number between (0,1); Step 5.2.3: Calculate fitness; Step 5.2.4: Exploration phase; If the dimension of the optimization problem is greater than 5, the position is updated as follows: ; ; ; and They represent the p-th dimension updated position and current position of the i-th starfish individual, represents the pth dimension of the current best position, T is the current number of iterations, is the maximum number of iterations, is a constant value, θ is an adaptive factor that changes with the number of iterations, and θ is in the range of [0,π / 2]; If the dimension of the optimization problem is not greater than 5, the exploration phase uses a one-dimensional search mode to update the position: ; ; In the formula, and are two random numbers between (-1,1), for the energy of the starfish; and is the current position of the p-th dimension of two randomly selected starfish individuals; Step 5.2.5: Development phase; First, five distances between the best position and other starfish individuals are calculated, and then two distances are randomly selected as confirmation. The position of each starfish individual is updated using a parallel bidirectional search strategy. The distance calculation formula is: ; in, is the distance between the 5 best starfish individuals and other starfish individuals, is one of five randomly selected starfish individuals, represents the current best position, and the update law of each starfish individual in predation behavior is modeled as: ; ; in, represents the updated position of the i-th starfish individual, represents the current position of the i-th starfish individual, and is a random number between (0,1), and yes Two random values in; N is the set population size; Step 5.2.6: Escape mechanism; The location update process is as follows: ; Where: yes Random numbers in the interval; Step 5.2.7: Update the fitness and determine whether the maximum number of iterations has been reached. If not, continue the iteration; otherwise, stop the iteration and output the optimal solution, which is the optimal threshold and optimal weight of the BP neural network.
2. The water quality detection method based on transmission spectrum analysis according to claim 1 is characterized in that: The number of nodes in the input layer of the BP neural network is equal to the dimension of the input vector, and the dimension of the input vector is the dimension of the selected sample data set.
3. The water quality detection method based on transmission spectrum analysis according to claim 1 is characterized in that: The number of nodes in the output layer of the BP neural network is consistent with the number of prediction results.
4. The water quality detection method based on transmission spectrum analysis according to claim 1 is characterized in that: The number of nodes in the hidden layer of the BP neural network is determined by the following formula: ; Where N h Represents the number of hidden layer nodes, N p Represents the number of input layer nodes, N o represents the number of output layer nodes, is a constant between [1,10].
5. The water quality detection method based on transmission spectrum analysis according to claim 1 is characterized in that: Step 6 includes the following sub-steps: Step 6.1: Use 3×3, 5×5 and 7×7 convolution kernels in parallel to extract multi-scale features from the input data of the input layer; Step 6.2: Use the concatenation layer to merge the features extracted from the three branches to obtain a one-dimensional data sequence; Step 6.3: Connect with the hidden layer of BP neural network through the connection layer.
6. An electronic device, comprising a memory, a processor, and a computer program stored in the memory, characterized in that: When the computer program is executed by the processor, the various steps of the water quality detection method based on transmission spectroscopy analysis as described in any one of claims 1 to 5 are implemented.
7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, each step of the water quality detection method based on transmission spectroscopy analysis as described in any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
GIS equipment temperature rise prediction method and system based on improved salmons algorithm optimization
CN116127858A
PV-TEG system MPPT method and system based on ISFOA
CN116225144A