A total dissolved solids detection method, system and device based on the Internet of Things
By adopting the use of the Internet of Things -based general soluble solid detection methods in water quality testing, and using deep learning technology and sparrow optimization algorithm, the existing water quality detection methods have been solved. Precise water quality testing.
Patent Information
- Application Number
- CN202410437793.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-12
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-04-12
AI Technical Summary
The existing water quality detection methods have problems such as time-consuming, costly, inability to detect real-time, long detection cycles, and inability to detect water pollution in time. Especially in adapting to the detection standards of different water areas, the implementation process is complex, the real-time and efficiency is low. low.
Adopt the general solution solid detection method based on the Internet of Things, establish a TDS prediction network model through multi -scale feature extraction networks, CONVLSTM networks, and poly head convolution sparse self -attention mechanisms, and use the sparrow optimization algorithm to optimize the network model to achieve the realization Real -time data collection, pre -processing and wireless transmission, combined with cloud data update model weight parameters.
A total soluble solid detection of portable, high efficiency and accuracy is realized, the detection cost and power consumption is reduced, the detection efficiency and accuracy are improved, water body pollution can be discovered in time, and the detection needs of different water areas can be adapted to different waters.
Smart Images

Figure CN118520286B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of water quality detection, and in particular to a total dissolved solids detection method, system and device based on the Internet of Things. Background Art
[0002] Water is the source of life and is vital to human health and ecological balance. However, population growth, industrialization and improper disposal of domestic waste have made the water environment increasingly serious. Therefore, water quality testing is not only a scientific and technological activity, but also a key link in maintaining human health, ecological balance and sustainable development. Traditional water quality testing methods mainly include physical, chemical and biological methods. Physical methods usually include measuring the temperature and turbidity of water bodies; chemical methods measure various chemical components in water, such as pH, conductivity and total dissolved solids (TDS); biological methods assess the health of water bodies by detecting the types and number of aquatic organisms. However, these traditional water quality testing methods have the disadvantages of being time-consuming and labor-intensive, costly, unable to detect in real time, long testing cycles and unable to detect water pollution in a timely manner.
[0003] The Chinese patent publication number is "CN117288696A", and the name is "A water quality detection method, device, electronic device and storage medium". The invention establishes multiple water quality relationship models corresponding to different types of water bodies, and predicts the predicted concentration data of the target substance in the water sample to be detected; the weight of each water quality relationship model is determined according to each predicted concentration data and actual concentration data, and then the model is used to perform water quality detection. Establishing multiple water quality relationship models for different types of water bodies in advance solves the problem that a single water quality model cannot be applied to all water quality detection occasions. Although this method can adapt to different detection standards in different waters, the implementation process is complicated, the real-time performance is not high, and the efficiency is low.
[0004] In summary, how to design a portable, efficient and highly accurate total dissolved solids detection method is an urgent problem to be solved by technical personnel in this field. Summary of the invention
[0005] The main purpose of the embodiments of the present invention is to propose a total dissolved solids detection method, system and device based on the Internet of Things, aiming to design a portable, efficient and highly accurate total dissolved solids detection method.
[0006] The technical solution of the present invention to solve the above technical problems is to provide a total dissolved solids detection method based on the Internet of Things, comprising the following steps:
[0007] Collect and process data:
[0008] Collect water quality information data of water areas and pre-process the data;
[0009] Divide the preprocessed data into training set, validation set and test set;
[0010] Build the network model:
[0011] The water quality data is feature extracted through a multi-scale feature extraction network, and learning and training are performed through a cascaded ConvLSTM network;
[0012] Through the multi-head convolutional sparse self-attention mechanism (MCSA), a TDS prediction network model is formed;
[0013] The sparrow optimization algorithm (SSA) is used to optimize the hyperparameters of the network model to obtain the final TDS prediction network model;
[0014] Training network model:
[0015] Input the training set data set into the TDS prediction network model for training; minimize the loss function between the network output result and the label until the number of training times reaches the set threshold or the value of the loss function reaches the set range, the model parameters are considered to have been trained and saved;
[0016] Predicted water quality data:
[0017] Input the water quality information data of the water area into the trained TDS prediction network model for prediction to obtain the final result;
[0018] The result data is transmitted to the cloud to expand the data set, and the weight parameters of the model are regularly updated based on the cloud data.
[0019] Furthermore, the step of collecting water quality information data of the water area and preprocessing the data includes:
[0020] Collect water quality information data of water areas;
[0021] The preprocessing method for water quality data without abnormal points is data normalization;
[0022] For water quality data with missing data or large deviations, the random forest method is first used to process the abnormal data, and then data normalization is used.
[0023] Furthermore, for water quality data with missing data or large deviation, the random forest method is first used to process the abnormal data, and then the data is normalized.
[0024] For water quality data with missing data or large deviations, multiple decision trees are constructed based on the characteristics of the existing data and combined; when dealing with missing data, other features in the existing data are used to predict the missing values and fill in the missing values;
[0025] For a given water quality data sequence x=(x1,x2,…,x n ), the maximum and minimum normalization processing, the processing formula is:
[0026]
[0027] Among them, max(x) and min(x) are the maximum and minimum values in the data, ε is a constant value added to prevent the model from falling into infinity, and the data is normalized to the [0,1] value range in the preprocessing stage.
[0028] Furthermore, the steps of extracting features from water quality data through a multi-scale feature extraction network and performing learning and training through a cascaded ConvLSTM network include:
[0029] Using multi-scale feature extraction network to extract water quality data x=(x1,x2,…,x n )’s characteristic information is effectively represented;
[0030] Through the fully connected layer and L-type function; and then through the cascade ConvLSTM network for learning and training, the update recursive formula of ConvLSTM is as follows:
[0031] i t =δ(w i *[h t-1 ,x t ]+b i );
[0032] f t =δ(w f *[h t-1 ,x t ]+b f );
[0033] c t =tanh(w c *[h t-1 ,x t ]+b c );
[0034] c t =f t ⊙c t-1 +i t ⊙c t ;
[0035] o t =δ(w o *[h t-1 ,x t ]+b o );
[0036] ht =o t ⊙tanh(c t );
[0037] It passes through the multi-head convolution sparse self-attention mechanism, the fully connected layer and the L-type function in sequence.
[0038] Furthermore, in the step of forming a TDS prediction network model through a multi-head convolutional sparse self-attention mechanism (MCSA):
[0039] The multi-head convolution sparse self-attention mechanism divides the input data into multiple heads, then performs independent attention calculations on each head, and finally merges the results of different heads together.
[0040] First, dilated causal convolution is performed on Q, K, and V (value vectors);
[0041] In the dilated causal convolution, given the kernel size k and the dilated basis b, when k ≥ b, the input length is l, the number of layers is n, and the following formula is satisfied:
[0042]
[0043] By multiplying Q and K after the dilated causal convolution and dividing by a scaling factor, an attention score is obtained to measure the relevance of each K and Q; then a logistic regression calculation is performed on the attention score to obtain the weight of each key vector;
[0044] For each vector q i Randomly sample a certain amount of K, and then calculate the attention M(q) of each Q by the following formula i ,K);
[0045]
[0046] The attention calculation formula is:
[0047]
[0048] in, It is a matrix of the same size as the q vector, which is composed of m valid sparse matrices q, where m is calculated as m=clnL Q .
[0049] Furthermore, in the step of optimizing the hyperparameters of the network model using the sparrow optimization algorithm (SSA) to obtain the final TDS prediction network model,
[0050] Initialize the parameters of the MF-MCSA-ConvLSTM model, use the hyperparameters of the network model such as the number of training times, the number of neurons, and the learning rate as optimization parameters, initialize the parameters of the SSA, and randomly initialize the positions of the sparrows in the group;
[0051] Calculate the fitness values of individual sparrows and sort them to determine the current best and worst positions, and update the positions of the discoverer and joiner according to the position update formula of the discoverer and joiner;
[0052] After sorting the fitness values of individual sparrows, find the best individual sparrow in the current iteration, and use its position to update the global optimal position;
[0053] Determine whether the error requirement is met or the maximum number of iterations is reached. If the conditions are met, set the current optimal hyperparameters as the new parameters of MF-MCSA-ConvLSTM;
[0054] MF-MCSA-ConvLSTM modeling is performed based on the optimal hyperparameters returned by the sparrow search algorithm, and the SSA-MF-MCSA-ConvLSTM model is trained for TDS prediction;
[0055] In the modeling, the sparrow population has n sparrows, which can be expressed as:
[0056]
[0057] Among them, d represents the dimension of the variable to be optimized; n represents the number of sparrows in the population; in the population, sparrows with higher individual fitness values have priority in finding food, and the finder is used to find abundant food; in the iterative process, the position of the finder is updated as follows:
[0058]
[0059] Among them, t represents the number of current iterations; iter max Represents the maximum number of iterations; represents the position information of the jth dimension where the ith sparrow is located; α∈(0,1]; R2 and ST represent the warning value and safety value respectively; Q is a random number that obeys the normal distribution; L is a 1×d matrix with all elements being 1. When the warning value is less than the safety value, it means it is safe and can forage; when the warning value is greater than or equal to the safety value, it means that a sparrow has discovered a predator, issued a warning, and the population has moved to a safe area to forage;
[0060] When the fitness value of the joiner is low, it will change its position to obtain more food. Its position update is shown in the following formula:
[0061]
[0062] in, Represents the worst position in the world at the tth iteration; represents the optimal position of the finder in the t+1th iteration; A is a 1×d matrix, and the elements in the matrix are randomly assigned 1 or -1, and the matrix satisfies A + =A T (AA T ) -1 .when When , it means that the i-th participant has not found food. In order to obtain energy, the participant will go to other places to forage;
[0063] In the population, sparrows that can identify danger and issue warnings account for 10% to 20% of the total population. The positions of these sparrows are randomly generated, and the generation formula is as follows:
[0064]
[0065] in, It represents the optimal position in the current global situation; K is a random number in the interval [-1,1]; β is the step size control parameter, which is a random number that obeys a random normal distribution; f i Represents the current sparrow's fitness value; f g Represents the optimal fitness value in the current global environment; f w represents the worst global fitness value; ε is a small constant. i >f g When , it means that the sparrows are at the edge of the population and are vulnerable to predators; when f i =f g When the sparrow is in the center of the population, it senses danger and needs to move closer to a safe location.
[0066] Furthermore, the training set data set is input into the TDS prediction network model for training; by minimizing the loss function of the network output result and the label, until the number of training times reaches a set threshold or the value of the loss function reaches a set range, the model parameters can be considered to have been trained, and in the step of saving the model parameters,
[0067] The loss function selected is the mean absolute error (MAE), mean absolute percentage error (MAPE) and root mean square error (RMSE) loss function, and the calculation formulas are:
[0068]
[0069] Among them, y t is the actual value, is the predicted value, and n is the total number of samples.
[0070] In order to solve the above technical problems, the present invention also proposes a total dissolved solids detection system based on the Internet of Things, comprising:
[0071] Data acquisition module: used to collect water quality data in real time through sensors installed on the detection equipment;
[0072] Data processing module: process the collected abnormal water quality data and unify the units;
[0073] Wireless communication module: The collected data is exchanged with the host computer and cloud platform through wireless transmission;
[0074] Cloud platform database module: save water quality data, description and data reorganization; and
[0075] Water quality prediction module: used to train the pre-processed water quality data, obtain the final TDS prediction model through iteration, and predict the TDS in the water.
[0076] In order to solve the above technical problems, the present invention also proposes a total dissolved solids detection device based on the Internet of Things, including a single-chip microcomputer device and a computer device connected to each other, wherein the single-chip microcomputer device is composed of a main control module and its peripheral circuits, a sensor module, an NB-IoT module and its peripheral circuits and a power module; the computer device is composed of a central processing unit (CPU), a graphics processing unit (GPU), a motherboard, a memory (RAM), a storage medium (hard disk / solid state drive) and a display device.
[0077] Compared with the prior art, the present invention has the following beneficial effects:
[0078] 1. The present invention utilizes the characteristics of embedded systems such as small size, low power consumption, low cost and easy deployment to deploy in areas where it is relatively difficult to collect water quality information. It utilizes NB-IoT narrowband Internet of Things technology to wirelessly transmit the collected data, and can perform long-distance wireless network communication. The low power consumption can ensure the working time of the equipment. At the same time, solar charging panels are used to power the battery. It is suitable for various scenarios and can measure a variety of water quality data, thereby improving the efficiency and accuracy of water quality detection and providing reliable technical support for protecting water resources and the environment.
[0079] 2. The present invention designs a TDS detection method based on deep learning. By analyzing the correlation between different water quality indicators, a TDS prediction model is established. The TDS prediction model is established using a multi-scale feature extraction network, a cascaded ConvLSTM network, and a multi-head convolution sparse self-attention mechanism, and the hyperparameters of the network model are optimized using a sparrow optimization algorithm, thereby improving the accuracy and robustness of the prediction. At the same time, using different water quality indicators to predict TDS can reduce the types and number of sensors used compared to traditional methods, further reducing power consumption and costs.
[0080] 3. The present invention can upload data to the cloud server through the NB-IoT module. The cloud server provides reliable data storage and management to ensure data security and reliability. The cloud server is also responsible for running the TDS prediction algorithm. Since the collection of water quality data is real-time, new data can be continuously used for training on the cloud server, and the parameters of the network can be continuously optimized, ensuring the generalization ability of the model and being able to flexibly respond to various complex environments. BRIEF DESCRIPTION OF THE DRAWINGS
[0081] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying creative work.
[0082] Figure 1 This is a schematic diagram of the structure of the total dissolved solids detection method based on the Internet of Things of the present invention;
[0083] Figure 2 This is the structural diagram of the ConvLSTM model of the present invention;
[0084] Figure 3 This is a structural diagram of the network model of the present invention;
[0085] Figure 4 A flowchart of optimizing the hyperparameters of the model by SSA of the present invention;
[0086] Figure 5 This is a flow chart of the total dissolved solids detection system based on the Internet of Things of the present invention;
[0087] Figure 6 This is a structural diagram of the total dissolved solids detection system based on the Internet of Things of the present invention;
[0088] Figure 7 It is a schematic diagram of a total dissolved solids detection device based on the Internet of Things of the present invention;
[0089] Figure 8It is a schematic diagram for comparing relevant indicators between the method of the present invention and the method of the prior art. DETAILED DESCRIPTION
[0090] The following will be combined with the drawings in the accompanying drawings of the present invention specification 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.
[0091] It should be noted that all directional indications in the embodiments of the present invention (such as up, down, left, right, front, back, etc.) are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0092] In addition, in the present invention, descriptions such as "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "several" or "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0093] In the present invention, unless otherwise clearly specified and limited, the terms "connection", "fixation", etc. should be understood in a broad sense. For example, "fixation" can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0094] In addition, the technical solutions between the various embodiments of the present invention can be combined with each other, but it must be based on the fact that ordinary technicians in the field can implement it. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0095] The present invention proposes a total dissolved solids detection method, system and device based on the Internet of Things, aiming to design a portable, efficient and highly accurate total dissolved solids detection method.
[0096] The total dissolved solids detection method based on the Internet of Things proposed by the present invention will be described in the following specific embodiments:
[0097] Embodiment 1:
[0098] like Figure 1 As shown, a total dissolved solids detection method based on the Internet of Things includes the following steps:
[0099] Step 1: Collect and process data:
[0100] Collect water quality information data of water areas and pre-process the data;
[0101] Understandably, by deploying detection equipment, water quality data such as water temperature, pH value, turbidity, dissolved oxygen and total dissolved solids (TDS) are collected.
[0102] Divide the preprocessed data into training set, validation set and test set;
[0103] Step 2: Build the network model:
[0104] The water quality data is feature extracted through a multi-scale feature extraction network, and learning and training are performed through a cascaded ConvLSTM network;
[0105] Through the multi-head convolutional sparse self-attention mechanism (MCSA), a TDS prediction network model is formed;
[0106] The sparrow optimization algorithm (SSA) is used to optimize the hyperparameters of the network model to obtain the final TDS prediction network model;
[0107] Step 3: Train the network model:
[0108] Input the training set data set into the TDS prediction network model for training; minimize the loss function between the network output result and the label until the number of training times reaches the set threshold or the value of the loss function reaches the set range, the model parameters are considered to have been trained and saved;
[0109] Step 4: Predict water quality data:
[0110] Input the water quality information data of the water area into the trained TDS prediction network model for prediction to obtain the final result;
[0111] The result data is transmitted to the cloud to expand the data set, and the weight parameters of the model are regularly updated based on the cloud data.
[0112] It is understandable that in addition to the collected data, we can also use the prediction data stored in the cloud as a reference to increase the size of the training set. This approach can enrich the data source, improve the generalization ability and robustness of the training model, and make it more representative and reliable.
[0113] This application uses wireless communication between embedded devices and cloud platforms to transmit water quality information data, establishes a total dissolved solids prediction model by analyzing the correlation between different water quality indicators, and then uses the sparrow optimization algorithm to optimize the hyperparameters of the network model, thereby providing a portable, efficient and accurate total dissolved solids detection solution.
[0114] Furthermore, the step of collecting water quality information data of the water area and preprocessing the data includes:
[0115] Collect water quality information data of water areas;
[0116] The preprocessing method for water quality data without abnormal points is data normalization;
[0117] For water quality data with missing data or large deviations, the random forest method is first used to process the abnormal data, and then data normalization is used.
[0118] Furthermore, for water quality data with missing data or large deviation, the random forest method is first used to process the abnormal data, and then the data is normalized.
[0119] For water quality data with missing data or large deviations, multiple decision trees are constructed based on the characteristics of the existing data and combined; when dealing with missing data, other features in the existing data are used to predict the missing values and fill in the missing values;
[0120] For a given water quality data sequence x=(x1,x2,…,x n ), the maximum and minimum normalization processing, the processing formula is:
[0121]
[0122] Among them, max(x) and min(x) are the maximum and minimum values in the data, ε is a constant value added to prevent the model from falling into infinity, and the data is normalized to the [0,1] value range in the preprocessing stage.
[0123] Furthermore, the steps of extracting features from water quality data through a multi-scale feature extraction network and performing learning and training through a cascaded ConvLSTM network include:
[0124] The structure diagram of the MF-MCSA-ConvLSTM model is as follows Figure 3 As shown in the figure, the water quality data x=(x1,x2,…,x n )’s characteristic information is effectively represented;
[0125] Through the fully connected layer and L-type function; and then through the cascade ConvLSTM network for learning and training, the update recursive formula of ConvLSTM is as follows:
[0126] i t =δ(w i *[h t-1 ,x t ]+b i );
[0127] f t =δ(w f *[h t-1 ,x t ]+b f );
[0128] c t =tanh(w c *[h t-1 ,x t ]+b c );
[0129] c t =f t ⊙c t-1 +i t ⊙c t ;
[0130] o t =δ(w o *[h t-1 ,x t ]+b o );
[0131] h t =o t ⊙tanh(c t );
[0132] It passes through the multi-head convolution sparse self-attention mechanism, the fully connected layer and the L-type function in sequence.
[0133] It can be understood that the multi-scale feature extraction network consists of three branches, each of which consists of a one-dimensional convolution layer, a fully connected layer and a T-type function. The sizes of the one-dimensional convolution kernels of the three branches are 1, 3, and 5 respectively. Among them, ConvLSTM is an optimization based on the fully connected LSTM model. It uses the convolution layer to extract features from the detection data while obtaining the temporal relationship, thereby obtaining the spatiotemporal information of water quality. The core essence is the same as LSTM. Its structure is as follows: Figure 2As shown. ConvLSTM also uses the output of the previous layer as the input of the next layer. The difference is that the convolution operation is introduced into the feedforward network of LSTM, that is, the dot product of w and h in the traditional network is replaced by the convolution operation. Feature extraction of water quality data through a multi-scale feature extraction network can effectively learn the nonlinear characteristics of the data; the cascaded ConvLSTM network can effectively process time series data and learn the long-term dependencies of the data through iterative calculations, further improving the accuracy and stability of TDS prediction; the multi-head convolution sparse self-attention mechanism only calculates data with large weight influence, so it can better distinguish key values, thereby reducing the calculation amount and memory usage of the model; the sparrow optimization algorithm has good convergence and global search capabilities, and can optimize hyperparameters such as the maximum number of iterations, the number of neurons, the initial learning rate, and the input batch in the network model.
[0134] Furthermore, in the step of forming a TDS prediction network model through a multi-head convolutional sparse self-attention mechanism (MCSA):
[0135] The multi-head convolutional sparse self-attention mechanism divides the input data into multiple heads, then performs independent attention calculations on each head, and finally merges the results of different heads together (each head can focus on different aspects of the input sequence, thereby capturing different information, improving the computational efficiency of the model, and reducing the training time of the model);
[0136] First, dilated causal convolution is performed on Q, K, and V (value vectors);
[0137] In the dilated causal convolution, given the kernel size k and the dilated basis b, when k ≥ b, the input length is l, the number of layers is n, and the following formula is satisfied:
[0138]
[0139] By multiplying Q and K after the dilated causal convolution and dividing by a scaling factor, an attention score is obtained to measure the relevance of each K and Q; then a logistic regression calculation is performed on the attention score to obtain the weight of each key vector;
[0140] For each vector q i Randomly sample a certain amount of K, and then calculate the attention M(q) of each Q by the following formula i ,K);
[0141]
[0142] The attention calculation formula is:
[0143]
[0144] in, It is a matrix of the same size as the q vector, which is composed of m valid sparse matrices q, where m is calculated as m=clnL Q .
[0145] Furthermore, in the step of optimizing the hyperparameters of the network model using the sparrow optimization algorithm (SSA) to obtain the final TDS prediction network model, as shown in FIG. Figure 4 As shown,
[0146] Initialize the parameters of the MF-MCSA-ConvLSTM model, use the hyperparameters of the network model such as the number of training times, the number of neurons, and the learning rate as optimization parameters, initialize the parameters of the SSA, and randomly initialize the positions of the sparrows in the group;
[0147] Calculate the fitness values of individual sparrows and sort them to determine the current best and worst positions, and update the positions of the discoverer and joiner according to the position update formula of the discoverer and joiner;
[0148] After sorting the fitness values of the sparrow individuals, find the best sparrow individual in the current iteration, and use its position to update the global optimal position (this position can reflect the optimal solution of the current iteration);
[0149] Determine whether the error requirement is met or the maximum number of iterations is reached. If the conditions are met, set the current optimal hyperparameters as the new parameters of MF-MCSA-ConvLSTM;
[0150] It should be noted that if the conditions are not met, the calculation will continue to return to the calculation of the fitness value.
[0151] MF-MCSA-ConvLSTM modeling is performed based on the optimal hyperparameters returned by the sparrow search algorithm, and the SSA-MF-MCSA-ConvLSTM model is trained for TDS prediction;
[0152] In the modeling, the sparrow population has n sparrows, which can be expressed as:
[0153]
[0154] Among them, d represents the dimension of the variable to be optimized; n represents the number of sparrows in the population; in the population, sparrows with higher individual fitness values have priority in finding food, and the finder is used to find abundant food; in the iterative process, the position of the finder is updated as follows:
[0155]
[0156] Among them, t represents the number of current iterations; iter max Represents the maximum number of iterations; represents the position information of the jth dimension where the ith sparrow is located; α∈(0,1]; R2 and ST represent the warning value and safety value respectively; Q is a random number that obeys the normal distribution; L is a 1×d matrix with all elements being 1. When the warning value is less than the safety value, it means it is safe and can forage; when the warning value is greater than or equal to the safety value, it means that a sparrow has discovered a predator, issued a warning, and the population has moved to a safe area to forage;
[0157] When the fitness value of the joiner is low, it will change its position to obtain more food. Its position update is shown in the following formula:
[0158]
[0159] in, Represents the worst position in the world at the tth iteration; represents the optimal position of the finder in the t+1th iteration; A is a 1×d matrix, and the elements in the matrix are randomly assigned 1 or -1, and the matrix satisfies A + =A T (AA T ) -1 .when When , it means that the i-th participant has not found food. In order to obtain energy, the participant will go to other places to forage.
[0160] In the population, sparrows that can identify danger and issue warnings account for 10% to 20% of the total population. The positions of these sparrows are randomly generated, and the generation formula is as follows:
[0161]
[0162] in, It represents the optimal position in the current global situation; K is a random number in the interval [-1,1]; β is the step size control parameter, which is a random number that obeys a random normal distribution; f i Represents the current sparrow's fitness value; f g Represents the optimal fitness value in the current global environment; f w represents the worst global fitness value; ε is a small constant. i >f g When , it means that the sparrows are at the edge of the population and are vulnerable to predators; when f i =f g When the sparrow is in the center of the population, it senses danger and needs to move closer to a safe location.
[0163] Furthermore, the training set data set is input into the TDS prediction network model for training; by minimizing the loss function of the network output result and the label, until the number of training times reaches a set threshold or the value of the loss function reaches a set range, the model parameters can be considered to have been trained, and in the step of saving the model parameters,
[0164] The loss function selected is the mean absolute error (MAE), mean absolute percentage error (MAPE) and root mean square error (RMSE) loss function, and the calculation formulas are:
[0165]
[0166] Among them, y t is the actual value, is the predicted value, and n is the total number of samples.
[0167] Understandably, MAE, MAPE and RMSE loss functions are used as evaluation indicators to verify the effectiveness of the model. The choice of loss function affects the quality of the model, can truly reflect the difference between the predicted value and the true value, and can correctly feedback the quality of the model. MAE is an evaluation indicator that reflects the absolute value of the deviation between the predicted water quality data and the actual sample data. The smaller the MAE value, the better the prediction effect of the model. The MAPE value represents the absolute value of the average difference between the actual sample data and the predicted sample. The smaller the MAPE value, the better the prediction effect of the model. If there is 0 data in the data sample, the formula cannot be used. The water quality data set used in this study has processed unreasonable data, and there is no water quality data of 0. The RMSE value represents the square root of the mean of the sum of the squares of the difference between the actual sample data and the predicted data. The smaller the RMSE value, the better the prediction effect of the model.
[0168] Embodiment 2: The present invention also proposes a total dissolved solids detection system based on the Internet of Things, such as Figure 5 As shown, including:
[0169] Data acquisition module: used to collect water quality data in real time through sensors installed on the detection equipment;
[0170] Data processing module: process the collected abnormal water quality data and unify the units;
[0171] Wireless communication module: The collected data is exchanged with the host computer and cloud platform through wireless transmission;
[0172] Cloud platform database module: save water quality data, description and data reorganization; and
[0173] Water quality prediction module: used to train the pre-processed water quality data, obtain the final TDS prediction model through iteration, and predict the TDS in the water.
[0174] Specifically, the sensors in the data acquisition module include various types, such as water temperature sensor, turbidity sensor, pH sensor and TDS sensor, etc., which are used to measure different water quality indicators. The data acquisition module is responsible for converting the analog signals collected by the sensor into digital format and transmitting them to the main control chip for subsequent processing.
[0175] When the collected water quality data is preprocessed in the data processing module, the preprocessing method for water quality data without abnormal points is data normalization. For water quality data with missing data or large deviations, the random forest method is first used to process the abnormal data, and then data normalization is used. This can effectively improve the quality and availability of the data and avoid the impact of different data units on the analysis and model.
[0176] The wireless communication module adopts the NB-IoT module, which has a very wide coverage range and does not require high efficiency of real-time network transmission. With the same resources, it has higher bandwidth utilization and lower power consumption.
[0177] The cloud platform database module uses the MySQL database, which is an open source database with excellent performance, simple structure, and strong applicability. It can efficiently process data of various sizes and occupies less server memory on the cloud platform.
[0178] The water quality prediction module trains the pre-processed water quality data by running and training the network model on the cloud server, and obtains the final TDS prediction model through iteration. Since different water quality indicators are correlated with each other, the TDS value can be predicted by water quality indicators such as temperature, pH value, turbidity, dissolved oxygen, etc. When verifying and predicting, the input water quality data is all water quality indicators except TDS, and then TDS is predicted by the prediction model.
[0179] The NB-IoT in the wireless communication module is a low-power wide area network communication technology based on cellular networks, which is an important branch of the Internet of Things field. It supports low-power devices to connect to data through a wide area network, so it is also called a low-power wide area network. NB-IoT technology is mainly aimed at application scenarios with small communication data volume, low transmission rate requirements, but high network coverage requirements, such as intelligent detection, agriculture, water conservancy and other fields.
[0180] After completing the configuration of the MySQL database in the cloud platform database module, including the database address and character set settings, a transmission connection is established between the cloud server and the MySQL database. In order to perform visual database management, the Navicat database management tool is used for configuration. Navicat is a tool suitable for various types of databases, which can facilitate users to create, manage and maintain databases.
[0181] The overall structure of the total dissolved solids detection system based on the Internet of Things is as follows Figure 6 As shown in the figure, the STM32 series microcontroller is used as the core of the lower computer. The lower computer collects water temperature, pH value, turbidity, dissolved oxygen and TDS parameters of the water body through sensors, and uses the NB-IoT module as the wireless communication module. The collected and processed water quality data is sent to the NB-IoT module by the lower computer. The data sent by the NB-IoT module is transmitted through the operator network and then gathered to the core network after being detected by nearby base stations, and then uploaded to the cloud server. The upper computer serves as the management platform of the system, including the cloud server and database. A database is established on the cloud server to store the water quality data uploaded by the lower computer, and the TDS prediction algorithm is run on the cloud server.
[0182] Embodiment 3: The present invention also proposes a total dissolved solids detection device based on the Internet of Things, including a single-chip device and a computer device connected to each other, wherein Figure 7 As shown, the single-chip microcomputer device is composed of a main control module and its peripheral circuit module, a sensor module, a wireless transmission module and a power module; the computer device is composed of a central processing unit (CPU), a graphics processing unit (GPU), a motherboard, a memory (RAM), a storage medium (hard disk / solid state drive) and a display device.
[0183] The single-chip microcomputer device is used as the lower computer, and the STM32F103C8T6 is used as the main control module. As the control core of the lower computer, it is responsible for collecting and processing the sensor data, and then sending the processed data to the wireless transmission module, namely the NB-IoT module, through the serial port of the single-chip microcomputer, and uploading the data to the computer device through the NB-IoT module. The main control module is the control core, and its peripheral circuits include reset circuit, clock crystal circuit, download interface circuit, and startup circuit. The sensor module includes water temperature sensor, turbidity sensor, pH sensor, TDS sensor, etc. The power module uses a solar power supply panel to charge the battery of the single-chip microcomputer to realize the power supply of the single-chip microcomputer. The peripheral circuits of the NB-IoT module include antenna circuit, SIM card circuit, reset circuit, etc.
[0184] The main control chip adopts the STM32F103C8T6 processor, which is packaged as LQFP-48. The processor is a microcontroller based on the ARMCortex-M core. The chip has an operating voltage range of 2V to 3.6V, a program storage capacity of 64KB, and an operating temperature range of -40°C to 85°C. The chip is a 32-bit processor, combining a high-performance RISC core with a high-speed embedded memory, and an operating frequency of up to 72MHz. The number of IO ports, timers, UART interfaces, ADC sampling channels, etc., which can meet the design requirements of the present invention.
[0185] The NB-IoT module uses the BC95 communication chip, which is a high-performance, low-power NB-IoT wireless communication chip. Its small size can reduce the size of the circuit board and optimize the cost when designing a water quality detection system. The BC95 chip has an operating voltage of 3.1V to 4.2V, a normal operating range of -35℃ to +75℃, and supports 1.8V / 3.0V external Class B USIM cards.
[0186] As a host computer, computer equipment can be used to build on the cloud platform, execute programs and perform data visualization. The CPU is responsible for executing the instructions of the computer program and is the brain of the computer. It includes a control unit and an arithmetic logic unit for performing various computing tasks. The GPU is mainly used to process graphics and image-related computing tasks, such as game rendering, image processing, video decoding, etc. It has parallel computing capabilities and can accelerate various graphics and general computing tasks. The motherboard is the main circuit board of the computer system, which integrates various core components, such as CPU slots, memory slots, expansion slots, various interfaces, etc., which are used to connect and control the communication between various hardware components. RAM is used to temporarily store computer programs and data and is a memory that can be directly accessed by the CPU. The size and speed of the memory directly affect the operating performance of the computer. Storage media are devices used to store data and programs for a long time, including mechanical hard disks (HDDs) and solid-state drives (SSDs). Storage media store operating systems, applications, and user data. The display device is used to display the graphical interface of the computer system.
[0187] The present invention constructs a total dissolved solids detection method, system and device based on the Internet of Things, and uses the correlation of water quality indicators to predict the TDS value through indicators such as water temperature, pH value, turbidity, dissolved oxygen, etc. in the water without going through other intermediate steps. Under the same conditions, the feasibility and superiority of this method are further verified by calculating the relevant indicators obtained with the existing method. Figure 8 shown.
[0188] from Figure 8It can be seen that the method proposed in the present invention has lower mean absolute error (MAE), mean absolute percentage error (MAPE) and root mean square error (RMSE) than the existing methods. These indicators also further illustrate that the method proposed in the present invention has better TDS prediction effect.
[0189] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A total dissolved solids detection method based on the Internet of Things, characterized in that: The following steps are involved: Collect and process data: Collect water quality information data of water areas and pre-process the data; Divide the preprocessed data into training set, validation set and test set; Build the network model: The water quality data is feature extracted through a multi-scale feature extraction network, and learning and training are performed through a cascaded ConvLSTM network; Through the multi-head convolution sparse self-attention mechanism, a TDS prediction network model is formed; The sparrow optimization algorithm is used to optimize the hyperparameters of the network model to obtain the final TDS prediction network model; Training network model: Input the training set data set into the TDS prediction network model for training; minimize the loss function between the network output result and the label until the number of training times reaches the set threshold or the value of the loss function reaches the set range, the model parameters are considered to have been trained and saved; Predicted water quality data: Input the water quality information data of the water area into the trained TDS prediction network model for prediction to obtain the final result; The result data is transmitted to the cloud to expand the data set, and the weight parameters of the model are regularly updated based on the cloud data; The steps of extracting features from water quality data through a multi-scale feature extraction network and performing learning and training through a cascaded ConvLSTM network include: Using multi-scale feature extraction network to extract water quality data x=(x1,x2,…,x n )’s characteristic information is effectively represented; Through the fully connected layer and L-type function; and then through the cascade ConvLSTM network for learning and training, the update recursive formula of ConvLSTM is as follows: i t =δ(w i *[h t-1 ,x t ]+b i ); f t =δ(w f *[h t-1 ,x t ]+b f ); c t =tanh(w c *[h t-1 ,x t ]+b c ); c t =f t ⊙c t-1 +i t ⊙c t ; about t =δ(w0*[h t-1 ,x t ]+b0); h t =o t ⊙tanh(c t ); It passes through the multi-head convolution sparse self-attention mechanism, the fully connected layer and the L-type function in sequence; In the step of forming a TDS prediction network model through a multi-head convolution sparse self-attention mechanism: The multi-head convolutional sparse self-attention mechanism divides the input data into multiple heads, then performs independent attention calculations on each head, and finally merges the results of different heads together; First, dilated causal convolution is performed on Q, K, and V; In the dilated causal convolution, given the kernel size k and the dilated basis b, when k ≥ b, the input length is l, the number of layers is n, and the following formula is satisfied: By multiplying Q and K after the dilated causal convolution and dividing by a scaling factor, an attention score is obtained to measure the relevance of each K and Q; then a logistic regression calculation is performed on the attention score to obtain the weight of each key vector; For each vector q i Randomly sample a certain amount of K, and then calculate the attention M(q) of each Q by the following formula i , K); The attention calculation formula is: in, It is a matrix of the same size as the q vector, which is composed of m valid sparse matrices q, where m is calculated as m=clnL Q .
2. The total dissolved solids detection method based on the Internet of Things according to claim 1, characterized in that: The step of collecting water quality information data of the water area and preprocessing the data comprises: Collect water quality information data of water areas; The preprocessing method for water quality data without abnormal points is data normalization; For water quality data with missing data or large deviations, the random forest method is first used to process the abnormal data, and then data normalization is used.
3. The total dissolved solids detection method based on the Internet of Things according to claim 2 is characterized in that, For water quality data with missing data or large deviation, the random forest method is first used to process the abnormal data, and then the data is normalized. For water quality data with missing data or large deviations, multiple decision trees are constructed based on the characteristics of the existing data and combined; when dealing with missing data, other features in the existing data are used to predict the missing values and fill in the missing values; For a given water quality data sequence x=(x1,x2,…,x n ), the maximum and minimum normalization processing, the processing formula is: Among them, max(x) and min(x) are the maximum and minimum values in the data, ε is a constant value added to prevent the model from falling into infinity, and the data is normalized to the [0,1] value range in the preprocessing stage.
4. The total dissolved solids detection method based on the Internet of Things according to claim 1, characterized in that: In the step of optimizing the hyperparameters of the network model using the sparrow optimization algorithm to obtain the final TDS prediction network model, Initialize the parameters of the MF-MCSA-ConvLSTM model, use the number of trainings, number of neurons, and learning rate hyperparameters of the network model as optimization parameters, initialize the parameters of the SSA, and randomly initialize the positions of the sparrows in the group; Calculate the fitness values of individual sparrows and sort them to determine the current best and worst positions, and update the positions of the discoverer and joiner according to the position update formula of the discoverer and joiner; After sorting the fitness values of individual sparrows, find the best individual sparrow in the current iteration, and use its position to update the global optimal position; Determine whether the error requirement is met or the maximum number of iterations is reached; if so, set the current optimal hyperparameters as the new parameters of MF-MCSA-ConvLSTM; MF-MCSA-ConvLSTM modeling is performed based on the optimal hyperparameters returned by the sparrow search algorithm, and the MF-MCSA-ConvLSTM model is trained to perform TDS prediction; In the modeling, the sparrow population has n sparrows, which can be expressed as: Among them, d represents the dimension of the variable to be optimized; n represents the number of sparrows in the population; in the population, sparrows with higher individual fitness values have priority in finding food, and the finder is used to find abundant food; in the iterative process, the position of the finder is updated as follows: Among them, t represents the number of current iterations; iter max Represents the maximum number of iterations; represents the position information of the jth dimension where the ith sparrow is located; α∈(0,1]; R2 and ST represent the warning value and safety value respectively; Q is a random number that obeys the normal distribution; L is a 1×d matrix with all elements being 1; when the warning value is less than the safety value, it means it is safe and can forage; when the warning value is greater than or equal to the safety value, it means that a sparrow has discovered a predator, issued a warning, and the population has moved to a safe area to forage; When the fitness value of the joiner is low, it will change its position to obtain more food. Its position update is shown in the following formula: in, Represents the worst position in the world at the tth iteration; represents the optimal position of the finder in the t+1th iteration; A is a 1×d matrix, and the elements in the matrix are randomly assigned 1 or -1, and the matrix satisfies A + =A T (AA T ) -1 ;when When , it means that the i-th participant has not found food. In order to obtain energy, the participant will go to other places to forage; In the population, sparrows that can identify danger and issue warnings account for 10% to 20% of the total population. The positions of these sparrows are randomly generated, and the generation formula is as follows: in, It represents the optimal position in the current global situation; K is a random number in the interval [-1, 1]; β is the step size control parameter, which is a random number that obeys a random normal distribution; f i Represents the current sparrow's fitness value; f g Represents the optimal fitness value in the current global environment; f w represents the worst global fitness value; ε is a small constant; when f i >f g When , it means that the sparrows are at the edge of the population and are vulnerable to predators; when f i =f g When the sparrow is in the center of the population, it senses danger and needs to move closer to a safe location.
5. The total dissolved solids detection method based on the Internet of Things according to claim 1 is characterized in that, The training set data set is input into the TDS prediction network model for training; by minimizing the loss function between the network output result and the label, until the number of training times reaches a set threshold or the value of the loss function reaches a set range, the model parameters can be considered to have been trained. In the step of saving the model parameters, The loss function selected is the mean absolute error, mean absolute percentage error, and root mean square error loss function, and the calculation formulas are: Among them, y t is the actual value, is the predicted value, and n is the total number of samples.
6. A total dissolved solids detection system based on the Internet of Things, used to implement the total dissolved solids detection method based on the Internet of Things as described in any one of claims 1 to 5, characterized in that: include: Data acquisition module: used to collect water quality data in real time through sensors installed on the detection equipment; Data processing module: process the collected abnormal water quality data and unify the units; Wireless communication module: The collected data is exchanged with the host computer and cloud platform through wireless transmission; Cloud platform database module: save water quality data, description and data reorganization; and Water quality prediction module: used to train the pre-processed water quality data, obtain the final TDS prediction model through iteration, and predict the TDS in the water.
7. A total dissolved solids detection device based on the Internet of Things, used to perform the total dissolved solids detection method based on the Internet of Things as described in any one of claims 1 to 5, characterized in that: It includes a single-chip microcomputer device and a computer device that are interconnected, wherein the single-chip microcomputer device is composed of a main control module and its peripheral circuit module, a sensor module, a wireless transmission module and a power module; the computer device is composed of a central processing unit, a graphics processing unit, a mainboard, a memory, a storage medium and a display device.
Citation Information
Patent Citations
Water quality detection method and device, electronic equipment and storage medium
CN117288696A
Sewage quality prediction method based on SSA-LSTM-AM
CN117035152A