Water quality detection method based on transmission spectrum analysis and electronic equipment
By improving the BP neural network and feature extraction module optimized by the starfish optimization algorithm, combined with the preprocessing and dimensionality reduction of spectral transmittance data, the problem of poor detection effect of existing water quality detection systems in complex environments is solved, achieving more accurate and Reliable water quality inspection.
Patent Information
- Application Number
- CN202510062712.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2045-01-15
AI Technical Summary
Existing water quality detection systems are difficult to provide comprehensive and accurate water quality detection results under complex environmental conditions, especially when facing mixture interference and baseline drift.
The water quality detection model composed of BP neural network and feature extraction module optimized by improved starfish optimization algorithm is used to achieve accurate detection of water quality through pre-processing of spectral transmittance data, dimensionality reduction and multi-scale feature extraction.
It improves the accuracy and reliability of water quality detection, and can effectively identify water quality changes under complex environmental conditions to meet the needs of water quality detection.
Smart Images

Figure CN119474843A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of water quality detection, and specifically relates to a water quality detection method and electronic equipment based on transmission spectrum analysis. Background Art
[0002] With the increasing awareness of environmental protection and the advancement of science and technology, water quality testing technology has developed rapidly. At present, most water quality testing systems on the market rely on single spectral analysis or limited pattern recognition technology. Although they can provide reliable results to a certain extent, the performance of existing technologies is still limited under complex environmental conditions, especially when facing problems such as mixture interference and baseline drift. Traditional single-mode inversion methods are difficult to fully 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 baseline reference spectral data, existing water quality testing systems are unable to timely reflect subtle changes in water quality conditions based solely on static references. Summary of the invention
[0003] In response to the above-mentioned problems, many researchers have proposed a variety of solutions, but the effects are not significant. In order to actually solve the current technical difficulties, the present invention discloses a water quality detection method and electronic equipment based on transmission spectrum analysis. The method forms a water quality detection model by improving the BP neural network optimized by the starfish optimization algorithm and the feature extraction module, which is used to accurately detect the water quality.
[0004] The present invention is implemented by the following technical solutions: A water quality detection method based on transmission spectrum analysis, comprising the following steps: 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 has obtained the optimal threshold and optimal weight, and use the trained water quality detection model to detect water quality.
[0005] Further preferably, 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.
[0006] 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.
[0007] Further preferably, the number of nodes in the output layer of the BP neural network is consistent with the number of prediction results.
[0008] Further preferably, 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].
[0009] Further preferably, step 6 comprises 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 (connect) to merge the features extracted by 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.
[0010] 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, the various steps of the water quality detection method based on transmission spectroscopy analysis are implemented.
[0011] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, each step of the water quality detection method based on transmission spectroscopy analysis is implemented.
[0012] The beneficial effects of the present invention are as follows: the BP neural network optimized by the improved starfish optimization algorithm is used for water quality detection, which solves the problem that the threshold and weight of the BP neural network are difficult to select accurately, and the water quality can be accurately detected. After the threshold and weight are optimized by 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
[0013] Figure 1 It is the flow chart of improved starfish optimization algorithm.
[0014] Figure 2 This is a comparison chart of the convergence curves before and after the improvement of the Starfish optimization algorithm. DETAILED DESCRIPTION
[0015] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Example 1
[0016] A water quality detection method based on transmission spectroscopy analysis comprises the following steps: 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 3.1: Standardize the spectral transmittance dataset to obtain a standardized spectral transmittance dataset , use the kernel function and nonlinear function to calculate the covariance and get the covariance matrix: ; Where: E represents the covariance matrix; is the jth sample data after processing, ; m is the number of samples, is a non-linear function. Step 3.2: The eigenvalues and eigenvectors in the covariance matrix E satisfy the following relationship: ; Where: is the eigenvalue of the covariance matrix E; V is the eigenvector of the covariance matrix E; Step 3.3: Linear transformation of nonlinear function: ; In the formula, is the constant coefficient before the nonlinear function.
[0017] Step 3.4: The principal component of any sample in the feature space The projection onto is: ; Among them, K is the kernel matrix vector.
[0018] 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 4.1: Determine the number of input layer nodes of the BP neural network. During the construction process, the number of input layer nodes 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 input layer nodes of the BP neural network is 10.
[0019] Step 4.2: Determine the number of hidden layer nodes of the BP neural network. The number of output layer nodes is consistent with the number of prediction results, so the number of output layer nodes is 1.
[0020] 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 as follows: ; 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, It is a constant between [1,10]. After calculation, the number of hidden layer nodes of the present invention is determined to be 12.
[0021] 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 5.1: Use the original threshold and original weight of the BP neural network as the initial position of the starfish population; Step 5.2: Starfish are marine invertebrates belonging to the class Echinodermata, which usually have five arms and a central disk, giving them a unique star-like appearance. SFOA mainly consists of two stages: exploration and exploitation. The exploration stage simulates the exploration behavior of starfish and adopts a hybrid search mode that combines five-dimensional and one-dimensional search modes to improve computational efficiency and ensure search capacity. The exploitation stage simulates the predation and regeneration behavior of starfish and adopts a two-way search strategy and special movements to ensure the convergence of exploitation. The process of improving the starfish optimization algorithm is as follows: Figure 1 As shown in Figure 2, the convergence curves of the improved starfish optimization algorithm and the original starfish optimization algorithm are as follows: Figure 2 shown.
[0022] Step 5.2.1: Set the population size and maximum number of iterations; Step 5.2.2: Population initialization; The Henon chaotic map is introduced to initialize the population to solve the problem of uneven distribution of the initial population caused by the random generation of the initial population in the original algorithm.
[0023] ; ; ; 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).
[0024] Step 5.2.3: Calculate fitness; Step 5.2.4: Exploration phase; If the dimension of the optimization problem is greater than 5, the search space of the problem is very wide, requiring the starfish to move all five arms to explore the surrounding environment. Therefore, a mathematical model for this stage is established: In view of the shortcoming of the slow convergence speed of the starfish optimization algorithm, an adaptive factor is introduced to improve the exploration stage: ; ; ; 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].
[0025] 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 this case, the starfish only has one arm moving to search for food sources, using the position information of other starfish. The updated position can be established as: ; ; 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.
[0026] Step 5.2.5: Development phase; In the development phase, predation and regeneration behaviors are considered to seek a global solution, so two update strategies are designed in the development phase. In order to simulate the predation phase of the starfish, the starfish optimization algorithm adopts a parallel two-way search strategy, which requires the use of information from other starfish individuals and the best position of the current population. First, the five distances between the best position and other starfish individuals are calculated, and then two distances are randomly selected as confirmation, and the position of each starfish individual is updated using a parallel two-way 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. Therefore, 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.
[0027] Step 5.2.6: Escape mechanism; In view of the shortcoming that the starfish optimization algorithm is prone to fall into the local optimal value in the later stage of iteration, an escape mechanism is introduced to improve it. The position 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.
[0028] Step 6. Use convolution kernels of different sizes as feature extraction modules in parallel, connect the extracted multi-scale features through a 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 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 (connect) to merge the features extracted by 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.
[0029] 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 has obtained the optimal threshold and optimal weight, and use the trained water quality detection model to detect water quality. Example 2
[0030] This embodiment 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, the various steps of the water quality detection method based on transmission spectroscopy analysis as described in Example 1 are implemented. Example 3
[0031] This embodiment provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the various steps of the water quality detection method based on transmission spectroscopy analysis as described in Example 1 are implemented.
[0032] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A 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 has obtained the optimal threshold and optimal weight, and use the trained water quality detection model to detect water quality.
2. The water quality detection method based on transmission spectrum analysis according to claim 1 is characterized in that: 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.
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 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.
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 output layer of the BP neural network is consistent with the number of prediction results.
5. 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].
6. 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.
7. 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 6 are implemented.
8. 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 6 is implemented.
Citation Information
Patent Citations
Double-layer BP neural network water quality prediction method and system based on genetic optimization algorithm
CN115358470A
Sea cucumber culture water quality prediction method for optimizing GRU neural network based on whale algorithm
CN115859057A
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
Method for predicting moisture content of tea leaves by optimizing BP neural network based on genetic algorithm
CN118230854A
Cited By
Power distribution automatic control system based on fault positioning
CN120073717A