Real-time detection method and device for influent water quality of sewage treatment plant
The MHA-LSTM model screens out redundant data and aligns and normalizes the time-delay and non-delay indicators of the sewage treatment plant, which solves the problem of low water quality detection accuracy, and realizes rapid and accurate detection of the incoming water quality of the sewage treatment plant, adapts to the trend of water fluctuations, reduces the hardware burden, and has the advantages of no secondary pollution, low cost and fast speed.
Patent Information
- Application Number
- CN202211130257.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-16
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2042-09-16
AI Technical Summary
The existing water quality detection methods have insufficient nonlinear mapping capabilities in sewage treatment plants and low efficiency in learning nonstable water quality data, resulting in poor detection accuracy, especially the extremely poor detection capabilities for events with sudden large fluctuations in water quality.
A multi-head attention mechanism long-term memory (MHA-LSTM) model is used, and the redundant data is screened out by screening out the redundant data by aligning and normalizing the time-delay and non-delay indicators of the sewage treatment plant, a fast and accurate water quality detection model is established, and the MHA-LSTM model is used for real-time detection.
It realizes rapid and accurate detection of the water quality inlet in sewage treatment plants, can respond to water quality changes in time, reduce hardware computing burden, has the advantages of no secondary pollution, low cost and fast speed, adapts to the trend of water quality fluctuations, and improves detection accuracy and response capabilities.
Smart Images

Figure CN115561416B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the technical fields of water quality detection traffic and intelligent tourism, and particularly to a method and device for real-time detection of the influent water quality of a sewage treatment plant. Background Art
[0002] As a basic municipal facility in the city, the sewage treatment plant shoulders the task of purifying the sewage from urban production and life, and its operation status directly affects the health of the urban water environment. However, with the advancement of urbanization and the rapid economic development, the scale of the city continues to expand, and the sewage volume and its composition complexity generated by various functional areas in the city (living areas, commercial areas, industrial areas) are increasing day by day, which poses extremely high challenges to urban sewage treatment plants. The sudden change of the chemical components of the influent water within a short period of time will cause the sewage treatment plant to bear impact loads, resulting in serious economic losses and even pollution accidents. The key indicators reflecting the sewage quality, such as total nitrogen, biochemical oxygen demand for five days, total phosphorus, and total organic carbon, all require a digestion process that consumes chemical reagents, which takes 15 - 40 minutes. The serious time lag of the above key water quality indicators leads to the lack of data support for the sewage treatment plant to judge the water quality at the current moment. Therefore, it is necessary to timely and accurately grasp the fluctuation of the time-lag indicators of the influent water of the sewage treatment plant so that the operators of the sewage treatment plant can take timely measures.
[0003] Compared with the traditional water quality detection methods based on chemical reactions, the soft detection methods based on water quality prediction models have the advantages of low cost, no secondary pollution, and fast speed. Attracted by the above advantages, researchers at home and abroad have developed a series of data-driven water quality soft detection models. However, there are still problems restricting the practical application of soft detection methods. For example, the non-linear mapping ability of traditional machine learning algorithms such as polynomial regression, support vector machine, and gradient boosting decision tree is not strong enough, and the efficiency of learning non-steady water quality data is low. The models established based on such algorithms have the problem of poor overall detection accuracy. Deep learning algorithms such as deep neural network, recurrent neural network, and gated recurrent neural network have stronger non-linear mapping ability, and even the ability to capture long-term dependencies in time series. The water quality models based on such algorithms have obtained higher overall detection accuracy. However, the training process of such modeling algorithms requires a large amount of data, and since the data reflecting abnormal water quality in the water quality data used to train the model is often less, this leads to the inability of such models to effectively learn the corresponding feature patterns, that is, the detection ability for sudden large fluctuations in water quality is extremely poor. Summary of the Invention
[0004] The embodiments of the present invention provide a method and device for real-time detection of the influent water quality of a sewage treatment plant, which are applicable to the rapid and accurate detection of the influent water quality of a sewage treatment plant, and provide data support for the sewage treatment plant to take feedback measures in a timely manner according to water quality changes.
[0005] In a first aspect, an embodiment of the present invention provides a method for real-time detection of the influent water quality of a sewage treatment plant, including:
[0006] Step S1: Obtain the time-delay index and non-time-delay index in the influent historical data of the sewage treatment plant. The non-time-delay index includes non-time-delay water quality indexes, water volume indexes, and meteorological indexes. The time-delay index includes time-delay water quality indexes.
[0007] Step S2: Align the water volume index, the meteorological index, and the non-time-delay water quality index based on the sampling frequency of the time-delay water quality index, and screen out non-time-delay indexes with a correlation greater than a preset condition; perform normalization processing on the time-delay index and the non-time-delay index.
[0008] Step S3: Use the non-time-delay index as the input and the time-delay index as the output to train a neural network model to obtain an influent water quality detection model for detecting the influent water quality, and detect the influent water quality of the sewage treatment plant based on the influent water quality prediction model.
[0009] Preferably, the sampling duration of the influent historical data is 12 months, and the sampling period is once per hour. The water volume index includes flow rate and liquid level; the meteorological index includes air temperature, relative humidity, air pressure, precipitation, and visibility; the time-delay water quality indexes include total nitrogen, five-day biochemical oxygen demand, total phosphorus, and total organic carbon; the non-time-delay water quality indexes include pH, conductivity, dissolved oxygen, turbidity, suspension, and water temperature.
[0010] Preferably, in step S2, screening out non-time-delay indexes with a correlation greater than a preset condition specifically includes:
[0011] Determine the maximum mutual information coefficient MIC of any two non-time-delay water quality indexes. If the MIC of any two non-time-delay water quality indexes is greater than the set MIC threshold, then screen out the non-time-delay water quality index with a larger average MIC with the remaining all non-time-delay water quality indexes among any two of the non-time-delay water quality indexes.
[0012] Preferably, the neural network model is an MHA-LSTM model, and each non-time-delay water quality index corresponds to one MHA-LSTM model.
[0013] The MHA-LSTM model includes an input layer, an LSTM neural network, a multi-head attention mechanism unit, and a multi-layer perceptron. The number of neurons in the input layer is the same as the number of non-time-delay indicators in the input. The time step of the LSTM neural network is the same as the daily sampling frequency of the influent historical data of the sewage treatment plant. The multi-head attention mechanism unit is used to: based on the outputs of the LSTM neural network at each time step and the query matrix Q, key matrix K, and value matrix V of the water quality anomaly standard, the query matrix Q, key matrix K, and value matrix V of the keywords are obtained through n different linear transformations to get n groups of Q i , V i , K i , where i = 1, 2,..., n, and n is the number of attention heads; for each group of Q i , V i , K i , the corresponding attention head head i is obtained through the scaled dot-product attention mechanism, all attention heads are concatenated into a high-dimensional vector, and then transmitted to the multi-layer perceptron;
[0014] The multi-layer perceptron includes an input layer, a fully connected layer, and an output layer. Among them, the number of neurons in the input layer of the multi-layer perceptron is the same as the number of attention heads of the multi-head attention mechanism unit. The fully connected layer includes 30 - 80 neurons and each neuron uses the ReLU activation function. The output layer includes 1 neuron.
[0015] Preferably, in step S3, using the non-time-delay indicators as the input and the time-delay indicators as the output, the neural network model is trained, specifically including:
[0016] At any time t, the non-time-delay indicators are arranged in the order of pH, conductivity, dissolved oxygen, turbidity, suspended solids, water temperature, flow rate, liquid level, air temperature, relative humidity, air pressure, precipitation, visibility to form a high-dimensional input I t ;
[0017] The high-dimensional input is input into the LSTM neural network in chronological order to establish a chronological mapping relationship between all non-time-delay indicators and a certain time-delay indicator;
[0018] The outputs of the LSTM neural network at each time step are integrated by the multi-head attention mechanism unit from different information perspectives, and the output data of the multi-head attention mechanism unit is transmitted to the multi-layer perceptron.
[0019] Preferably, before training the neural network model in step S3, it also includes;
[0020] The influent historical data is divided into a training set, a validation set, and a test set in a ratio of 8:1:1;
[0021] After training the neural network model, it further includes:
[0022] Intercept a training set of 7 - 90 days before the current date from the influent historical data to perform 30 - 250 loop iterations on the trained MHA - LSTM model, and the fine - tuning frequency of the MHA - LSTM model is 3 - 14 days per time.
[0023] Preferably, the loss function of the MHA - LSTM model is:
[0024]
[0025] In the above formula, T represents the time - series length, t represents the time order, is the predicted value at time t, is the measured value at time t.
[0026] In a second aspect, an embodiment of the present invention provides a real - time detection device for the influent water quality of a sewage treatment plant, including:
[0027] An index acquisition module, which acquires the time - lagged indexes and non - time - lagged indexes in the influent historical data of the sewage treatment plant. The non - time - lagged indexes include non - time - lagged water quality indexes, water volume indexes, and meteorological indexes, and the time - lagged indexes include time - lagged water quality indexes;
[0028] An index screening module, which aligns the water volume indexes, the meteorological indexes, and the non - time - lagged water quality indexes based on the sampling frequency of the time - lagged water quality indexes, and screens out non - time - lagged indexes with a correlation greater than a preset condition; performs normalization processing on the time - lagged indexes and the non - time - lagged indexes;
[0029] A detection module, which takes the non - time - lagged indexes as inputs and the time - lagged indexes as outputs, performs neural network model training to obtain an influent water quality detection model for detecting the influent water quality, and detects the influent water quality of the sewage treatment plant based on the influent water quality prediction model.
[0030] In a third aspect, an embodiment of the present invention provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the steps of the method for real - time detection of the influent water quality of a sewage treatment plant as described in the first - aspect embodiment of the present invention.
[0031] In a fourth aspect, an embodiment of the present invention provides a non - transitory computer - readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the steps of the method for real - time detection of the influent water quality of a sewage treatment plant as described in the first - aspect embodiment of the present invention.
[0032] A real-time detection method and system for the influent water quality of a sewage treatment plant provided by an embodiment of the present invention screens out redundant data based on the correlation analysis of the maximum mutual information coefficient, effectively reducing the computing burden of hardware devices and saving related costs; the cyclic architecture, gate structure, and multi-head attention mechanism of the MHA-LSTM model endow it with powerful non-linear mapping capabilities, long-term dependence capture capabilities, stronger multi-time scale data feature learning capabilities, and the ability to pay attention to different information perspectives; the fine-tuning method enables the proposed detection method to adapt to the water quality change trend at all times and can provide accurate real-time detection results in long-term water quality monitoring; the trained and fine-tuned MHA-LSTM model has high detection accuracy for normal water quality fluctuations and is also good at detecting sudden water quality abnormal fluctuations, providing strong data support for the sewage treatment plant to make timely feedback measures, establishing a mapping relationship between the quickly obtainable water quality, water volume, and meteorological indicators and the time-delayed water quality indicators that cannot be quickly obtained, realizing the real-time soft detection of time-delayed water quality indicators, and having the remarkable advantages of no secondary pollution, low cost, and fast speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0034] Figure 1 It is a flowchart of the real-time detection method for the influent water quality of a sewage treatment plant according to an embodiment of the present invention;
[0035] Figure 2 It is the overall framework of the real-time detection method for the influent water of a sewage treatment plant according to an embodiment of the present invention;
[0036] Figure 3 It is a structural diagram of the MHA-LSTM model according to an embodiment of the present invention;
[0037] Figure 4 It is a structural diagram of the LSTM neural network according to an embodiment of the present invention;
[0038] Figure 5 It is a diagram of the scaled dot product attention mechanism according to an embodiment of the present invention;
[0039] Figure 6 It is a learning curve graph of the MHA-LSTM model for the detection of total nitrogen (TN), biochemical oxygen demand (BOD5), total phosphorus (TP), and total organic carbon (TOC) respectively according to an embodiment of the present invention;
[0040] Figure 7The detection result diagram according to an embodiment of the present invention;
[0041] Figure 8 Schematic diagram of a data-driven real-time detection device for the influent of a sewage treatment plant according to an embodiment of the present invention. Specific embodiments
[0042] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Apparently, the described embodiments are some, but not all, of the embodiments of the present invention. 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.
[0043] In the embodiments of the present application, the term "and / or" merely describes an association relationship between associated objects and indicates that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone.
[0044] In the embodiments of the present application, the terms "first" and "second" are only used for descriptive purposes and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include at least one of such features. In the description of the present application, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a system, product, or device including a series of components or units is not limited to the listed components or units, but may optionally further include components or units not listed, or may optionally further include other components or units inherent to these products or devices. In the description of the present application, the meaning of "a plurality" is at least two, such as two, three, etc., unless otherwise specifically defined.
[0045] Referring to "embodiments" herein means that specific features, structures, or characteristics described in connection with the embodiments may be included in at least one embodiment of the present application. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein may be combined with other embodiments.
[0046] The water quality soft detection method has the advantages of low cost, no secondary pollution, fast speed, etc. However, there are still problems restricting the practical application of the soft detection method at present. For example, the non-linear mapping ability of traditional machine learning algorithms such as polynomial regression, support vector machine, and gradient boosting decision tree is not strong enough, and the efficiency of learning non-steady water quality data is low. The models established based on such algorithms have problems with poor overall detection accuracy. Deep learning algorithms such as deep neural network, recurrent neural network, and gated recurrent neural network have stronger non-linear mapping ability, and even the ability to capture long-term dependencies in time series. The water quality models based on such algorithms have obtained higher overall detection accuracy. However, the training process of such modeling algorithms requires a large amount of data, and since the data reflecting abnormal water quality in the water quality data used to train the model is often less, this results in the inability of such models to effectively learn the corresponding feature patterns, that is, the detection ability for sudden large fluctuations in water quality is extremely poor.
[0047] Therefore, the embodiments of the present invention provide a method and device for real-time detection of the influent water quality of a sewage treatment plant, which can establish a mapping relationship between the water quality, water volume, meteorological indicators that can be quickly obtained and the time-lagged water quality indicators that cannot be quickly obtained, and realize the real-time soft detection of the time-lagged water quality indicators, with the significant advantages of no secondary pollution, low cost, and fast speed. The method and device for real-time detection of the influent water quality of a sewage treatment plant are described below with reference to the accompanying drawings.
[0048] Figure 1 and Figure 2 According to an embodiment of the present invention, a method for real-time detection of the influent water quality of a sewage treatment plant is provided, including:
[0049] Step S1, obtaining the time-lagged indicators and non-time-lagged indicators in the historical influent data of the sewage treatment plant. The non-time-lagged indicators include non-time-lagged water quality indicators, water volume indicators, and meteorological indicators, and the time-lagged indicators include time-lagged water quality indicators; among them, the time-lagged water quality indicators (total nitrogen, biochemical oxygen demand in five days, total phosphorus, total organic carbon) are used as the output of the water quality soft detection model, and other indicators (that is, non-time-lagged indicators) are used as the input of the water quality soft detection model.
[0050] In this embodiment, the sampling duration of the historical influent data is 12 months, the sampling period is once per hour, the water volume indicators include flow rate and liquid level; the meteorological indicators include air temperature, relative humidity, air pressure, precipitation, and visibility; the time-lagged water quality indicators include total nitrogen, biochemical oxygen demand in five days, total phosphorus, and total organic carbon; the non-time-lagged water quality indicators include pH, conductivity, dissolved oxygen, turbidity, suspension, and water temperature.
[0051] Step S2: Align the water volume index, the meteorological index, and the non-time-lagged water quality index based on the sampling frequency of the time-lagged water quality index, and screen out non-time-lagged indexes with a correlation greater than a preset condition; perform normalization on the time-lagged indexes and non-time-lagged indexes.
[0052] In this embodiment, after obtaining the historical influent data, preprocessing needs to be performed on the collected historical influent data. The preprocessing includes frequency alignment, correlation analysis, and normalization.
[0053] Frequency alignment: The detection frequency of the time-lagged water quality index of this sewage treatment plant is once per hour. Based on this frequency, align the faster water quality (non-time-lagged water quality index and time-lagged water quality index), water volume index, and meteorological index with higher frequencies. After aligning the frequencies of each index, the historical influent data set has a total of 8760 data records and 148920 data points.
[0054] Correlation analysis: Determine the maximum mutual information coefficient (MIC) of any two non-time-lagged water quality indexes. If the MIC of any two non-time-lagged water quality indexes is greater than the set MIC threshold, then screen out the non-time-lagged water quality index with a larger average MIC with the remaining non-time-lagged water quality indexes among any two of them. In this embodiment, for two indexes with a maximum mutual information coefficient greater than 0.7, screen out the one with a larger average maximum mutual information coefficient with other non-time-lagged indexes between the two. In this example, no index is screened out because it meets the condition that the maximum mutual information coefficient is greater than 0.7.
[0055] Normalization: Perform min-max normalization on each index respectively. Among them, the method of min-max normalization is as follows. Assume that the time series of a certain index is x1, …, x t , and denote the maximum value and the minimum value as x max and x min respectively. Then the time series of this index after normalization is:
[0056]
[0057] Among them, x' t is the min-max normalization result of the value of the time series x at time t.
[0058] Step S3: Use the non-time-lagged indexes as inputs and the time-lagged indexes as outputs to train a neural network model to obtain an influent water quality detection model for detecting the influent water quality, and detect the influent water quality of the sewage treatment plant based on the influent water quality prediction model.
[0059] In this embodiment, the neural network model is a multi-head attention mechanism long short-term memory (MHA-LSTM) model. The MHA-LSTM model includes an input layer, an LSTM neural network, a multi-head attention mechanism unit, and a multi-layer perceptron. By calling libraries such as keras, pandas, numpy, matplotlib, and sklearn on the open-source TensorFlow platform and writing code based on the Python language, the MHA-LSTM model is implemented. Following the "many-to-one" architecture, there is one such MHA-LSTM model corresponding to each non-time-delay water quality indicator. Among them, the number of hidden layers of the LSTM neural network is 3-5, each layer contains 50-65 neurons, the number of neurons in the input layer is the same as the number of indicators used as inputs, and the number of neurons in the output layer is 1. The multi-layer perceptron consists of 1 input layer, 1-3 fully connected layers, and 1 output layer. The number of neurons in the input layer is the same as the number of heads of the multi-head attention mechanism, each fully connected layer has 30-80 neurons, and the output layer has 1 neuron. During the training process of the MHA-LSTM model, the symmetric mean absolute percentage error (SMAPE) is used as the loss function.
[0060] The normalized historical influent data is divided into a training set, a validation set, and a test set according to the ratio of 8:1:1. Using all non-time-delay indicators (pH, conductivity, dissolved oxygen, turbidity, suspended solids, water temperature, flow rate, liquid level, air temperature, relative humidity, air pressure, precipitation, visibility) as inputs and each time-delay indicator (total nitrogen, five-day biochemical oxygen demand, total phosphorus, total organic carbon) as outputs, they are respectively transmitted to 4 MHA-LSTM models, and the above 4 models are trained.
[0061] The structure of the MHA-LSTM model is as Figure 3 shown. At any moment t, the non-time-delay indicators are arranged in the order of pH, conductivity, dissolved oxygen, turbidity, suspended solids, water temperature, flow rate, liquid level, air temperature, relative humidity, air pressure, precipitation, visibility to form a high-dimensional input I t at any moment t, and the values of each non-time-delay indicator at time t ∈ I t ;
[0062] The high-dimensional input is input into the LSTM neural network in chronological order to establish a chronological mapping relationship between all non-time-delay indicators and a certain time-delay indicator.
[0063] The outputs of the LSTM neural network at each time step (including at least all time steps and the last time step), i.e., the outputs of the corresponding LSTM cells, are integrated by the multi-head attention mechanism unit from different information perspectives. Then, the output data of the multi-head attention mechanism unit is transmitted to a multi-layer perceptron. The output data of the multi-head attention mechanism is transmitted to a multi-layer perceptron and its output (Yt) is obtained. The MHA-LSTM model quantifies the deviation between Yt and the measured value of the non-delay index at time t based on the loss function. By backpropagating the deviation throughout the MHA-LSTM model and updating the model parameters in continuous iterations to minimize the deviation, accurate detection of the non-delay index can be achieved. In this embodiment, the symmetric mean absolute percentage error (SMAPE) is used as the loss function during the training process of the MHA-LSTM model. The formula of SMAPE is as follows:
[0064]
[0065] In the above formula, T represents the length of the time series, t represents the time order, is the predicted value at time t, is the measured value at time t.
[0066] The number of neurons in the input layer is consistent with the number of non-delay indexes of the input. The time step of the LSTM neural network is consistent with the daily sampling frequency of the influent historical data of the sewage treatment plant; the structure of the LSTM neural network is as Figure 4 shown, including an input gate, a forget gate, and an output gate. In the forget gate, the previous hidden state (H t-1 ) and the current input (x t ) are passed together to a neural network with a ReLU activation function to obtain the forget vector (f t ). In the input gate, H t-1 and x t are passed together to a neural network with a tanh activation function and a neural network with a ReLU activation function to obtain the input vector (i t ) and the candidate input vector (ci t ). Then, i t and ci t are multiplied element-wise to obtain the memory vector (m t ). The previous cell state (U t-1 ) is multiplied element-wise with f t , and then the result of their operation is added element-wise to m t to obtain the current cell state (U t ). In the output gate, H t-1 and x tPassed together to a neural network with a ReLU activation function to obtain an output vector (o t );U t After being transformed by the tanh function, multiply pointwise by o t to obtain the current hidden state (H t , which is the current output). The calculation formula of the LSTM neural network is as follows:
[0067] f t = ReLU(w fx x t + w fh H t-1 + b f )
[0068] i t = ReLU(w ix x t + w ih H t-1 + b i )
[0069] ci t = tanh(w cx x t + w ch H t-1 + b c )
[0070]
[0071]
[0072] o t = ReLU(w ox x t + w oh H t-1 + b o )
[0073]
[0074] Among them, ReLU and tanh represent the rectified linear unit and the tangent activation function respectively; represents the element-wise multiplication operation; w fx , w ix , w cx , w ox are the weight parameters of x t in the forget gate, input gate, candidate input, and output gate respectively; w fh , w ih , w ch , w oh are the weights of the forget gate, input gate, candidate input, and output gate for H t-1The corresponding weight parameter, b f , b i , b c , b o are the corresponding bias parameters.
[0075] In this embodiment, the number of hidden layers of the LSTM neural network is 3 - 5, and each layer contains 50 - 65 neurons; the number of neurons in the input layer is the same as the number of input metrics, and the number of neurons in the output layer is 1. The time step of the LSTM is set to 24 (consistent with the daily sampling frequency of the sample set), the batch size is 16 - 72, and the learning rate is adaptively adjusted by the Adam optimizer during the model training process.
[0076] The multi - head attention mechanism unit is used for: based on the outputs of the LSTM neural network at each time step (i.e., H1, H2,..., H t ), and the water quality anomaly standard setting query matrix Q, keyword matrix K, and numerical matrix V of keywords, the query matrix Q, keyword matrix K, and numerical matrix V of keywords are obtained through n different linear transformations to obtain n groups of Q i , V i , K i , where i = 1, 2,..., n, and n is the number of attention heads; then, for each group of Q i , V i , K i , the corresponding attention head head i is obtained through the scaled dot - product attention mechanism; finally, all attention heads are concatenated into a high - dimensional vector and fed into a multi - layer perceptron; where the scaled dot - product attention mechanism is as Figure 5 shown. Q and K are multiplied to obtain the correlation between the query vector and each corresponding key vector. After scaling, the attention scores are obtained. The masking operation is to clear some vectors filled with zeros in Q and K, and the attention scores are transmitted to the Softmax function. Then, the operation result of the Softmax function is multiplied by V to obtain the weighted sum, which is the output of the scaled dot - product attention mechanism. Its formula is as follows:
[0077]
[0078] where Q, K T is the transpose of K, d k and d v are the dimensions of K and V respectively.
[0079] The multi-layer perceptron includes an input layer, a fully connected layer (1 to 3 layers), and an output layer. Among them, the number of neurons in the input layer of the multi-layer perceptron is the same as the number of attention heads of the multi-head attention mechanism unit. The fully connected layer includes 30 - 80 neurons, and each neuron uses the ReLU activation function. The output layer includes 1 neuron.
[0080] Figure 6 Shown are the learning curves of the MHA-LSTM models for the detection of total nitrogen (TN), biochemical oxygen demand in five days (BOD5), total phosphorus (TP), and total organic carbon (TOC) in this embodiment. The results show that each MHA-LSTM model reaches convergence around 1500 iterations.
[0081] After training the MHA-LSTM model, it is also necessary to intercept the training set of the previous 7 - 90 days from the influent historical data to perform 30 - 250 cyclic iterations on the trained MHA-LSTM model. In this example, the fine-tuning period of the MHA-LSTM model is 3 - 14 days.
[0082] According to the above MHA-LSTM model, the detection results of each time-delay index are output. The non-time-delay index data at the current moment is input into the corresponding fine-tuned MHA-LSTM model to obtain the detection results of the time-delay indexes (i.e., total nitrogen, biochemical oxygen demand in five days, total phosphorus, total organic carbon) at the current moment.
[0083] Based on the detection results and the water quality abnormality standard, it is judged whether the water quality of the influent of the current sewage treatment plant is abnormal, and the sewage treatment plant is guided to execute feedback measures. The water quality abnormality standard is as follows:
[0084] 1) The concentration of the time-delay index is higher than the national or industry standard of this index;
[0085] 2) The concentration of the time-delay index is higher than or lower than 40% of the average concentration at the same moment in the previous 3 days of this index.
[0086] Use the data acquisition module to obtain the actual concentration of the time-delay index at the current moment based on the chemical reaction method, analyze the actual concentration and the model detection results, to 2 evaluate the overall accuracy of the MHA-LSTM model detection results, and evaluate the detection accuracy of the MHA-LSTM model for the influent events of the sewage treatment plant with precision and recall rate. 2 The calculation formulas for precision and recall rate are as follows:
[0087]
[0088]
[0089]
[0090] Among them, and respectively represent the measured value of y at time t and the average value of the measured values of y at all times, and respectively represent the soft-detection value of y at time t and the average value of the soft-detection values of y at all times.
[0091] The detection result of the detection method described in this embodiment is as Figure 7 shown. The fine-tuned MHA-LSTM model achieved R values of 0.9448, 0.9128, 0.8952, and 0.9043 for total nitrogen (TN), biochemical oxygen demand (BOD5), total phosphorus (TP), and total organic carbon (TOC) respectively on the test set of the influent historical dataset. 2 . For abnormal influent events, an accuracy of 89.31% and a recall rate of 91.57% were achieved. This result indicates that the described detection method and device can accurately detect the normal and abnormal fluctuations of the influent time-delay index of the sewage treatment plant.
[0092] This embodiment of the present invention also provides a real-time detection device for the influent water quality of a sewage treatment plant. Based on the real-time detection method for the influent water quality of the sewage treatment plant in the above embodiments, it includes:
[0093] An index acquisition module that acquires the time-delay index and non-time-delay index in the influent historical data of the sewage treatment plant. The non-time-delay index includes non-time-delay water quality indexes, water volume indexes, and meteorological indexes, and the time-delay index includes time-delay water quality indexes;
[0094] An index screening module that aligns the water volume index, the meteorological index, and the non-time-delay water quality index based on the sampling frequency of the time-delay water quality index, and screens out non-time-delay indexes with a correlation greater than a preset condition; performs normalization processing on the time-delay index and the non-time-delay index;
[0095] A detection module that uses the non-time-delay index as the input and the time-delay index as the output to train a neural network model to obtain an influent water quality detection model for detecting the influent water quality of the sewage treatment plant, and detects the influent water quality of the sewage treatment plant based on the influent water quality prediction model.
[0096] Based on the same concept, this embodiment of the present invention also provides Figure 8It is a schematic diagram of a real-time detection device for the influent water quality of a sewage treatment plant. The system of this detection device includes a memory 830, a processor 840, a first data acquisition module 810, and a second data acquisition module 820. The first data acquisition module 810 is set at the inlet of the sewage treatment plant and is used to collect the water quality and water volume data of the influent of the sewage treatment plant, and send the collected index data to the memory 830; the second data acquisition module 820 is set in the central area of the service area of the sewage treatment plant and is used to collect the meteorological data in the service area of the sewage treatment plant, and send the collected index data to the memory 830; the memory 830 and the processor 840 are located at the same place. The trained MHA-LSTM model (i.e., computer program 850) is built in the memory 830. The recently received index data is input into the trained MHA-LSTM model, and the MHA-LSTM model is fine-tuned on the processor 840. The index data at the current moment is input into the fine-tuned MHA-LSTM model, and then the detection result of the time-delay index of the influent of the sewage treatment plant at the current moment is obtained. Exemplarily, the first data acquisition module 810 and the second data acquisition module 820 transmit data to the memory 830 by wireless communication, and the memory 830 and the processor 840 interact data by wired communication.
[0097] Based on the same concept, an embodiment of the present invention further provides a non-transitory computer-readable storage medium. The computer-readable storage medium stores a computer program, and the computer program includes at least one segment of code. The at least one segment of code can be executed by a main control device to control the main control device to implement the steps of the method for real-time detection of the influent water quality of a sewage treatment plant as described in the above embodiments. For example, it includes:
[0098] Step S1: Obtain the time-delay index and non-time-delay index in the historical influent data of the sewage treatment plant. The non-time-delay index includes non-time-delay water quality indexes, water volume indexes, and meteorological indexes, and the time-delay index includes time-delay water quality indexes;
[0099] Step S2: Align the water volume index, the meteorological index, and the non-time-delay water quality index based on the sampling frequency of the time-delay water quality index, and screen out non-time-delay indexes with a correlation greater than a preset condition; perform normalization processing on the time-delay index and the non-time-delay index;
[0100] Step S3: Use the non-time-delay index as the input and the time-delay index as the output to train a neural network model to obtain an influent water quality detection model for detecting the influent water quality, and detect the influent water quality of the sewage treatment plant based on the influent water quality prediction model.
[0101] Based on the same inventive concept, an embodiment of the present application further provides a computer program which, when executed by a master control device, is used to implement the above method embodiment.
[0102] The program may be stored in whole or in part on a storage medium packaged together with the processor, or may be stored in whole or in part on a memory not packaged together with the processor.
[0103] Based on the same inventive concept, an embodiment of the present application further provides a processor which is used to implement the above method embodiment. The above processor may be a chip.
[0104] In summary, a real-time detection method and system for the influent water quality of a sewage treatment plant provided by an embodiment of the present invention screens out redundant data based on the correlation analysis of the maximum mutual information coefficient, effectively reducing the computing burden of hardware devices and saving related costs; the cyclic architecture, gate structure, and multi-head attention mechanism of the MHA-LSTM model endow it with powerful non-linear mapping capabilities, long-term dependence capture capabilities, stronger multi-time scale data feature learning capabilities, and the ability to pay attention to different information angles; the fine-tuning method enables the proposed detection method to adapt to the water quality change trend at all times and can provide accurate real-time detection results in long-term water quality monitoring; the trained and fine-tuned MHA-LSTM model has high detection accuracy for normal water quality fluctuations and is also good at detecting sudden water quality abnormal fluctuations, providing strong data support for the sewage treatment plant to take timely feedback measures, establishing a mapping relationship between the water quality, water volume, and meteorological indicators that can be quickly obtained and the time-delay water quality indicators that cannot be quickly obtained, realizing the real-time soft detection of time-delay water quality indicators, and having the significant advantages of no secondary pollution, low cost, and fast speed.
[0105] The various embodiments of the present invention can be combined arbitrarily to achieve different technical effects.
[0106] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in this application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line) or wirelessly (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid-state disk).
[0107] Those of ordinary skill in the art can understand that all or part of the processes in the above method embodiments can be completed by hardware instructed by a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above method embodiments. The aforementioned storage medium includes various media that can store program codes, such as ROM or random access memory RAM, magnetic disks, or optical discs.
[0108] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments or perform equivalent replacements for some of the technical features. These modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A real-time detection method for the influent water quality of a sewage treatment plant, characterized in that, Including: Step S1: Obtain the time-delay index and non-time-delay index in the historical influent data of the sewage treatment plant. The non-time-delay index includes non-time-delay water quality index, water volume index, and meteorological index. The time-delay index includes time-delay water quality index; Step S2: Align the water volume index, the meteorological index, and the non-time-delay water quality index based on the sampling frequency of the time-delay water quality index, and screen out the non-time-delay indexes with a correlation greater than a preset condition; perform normalization processing on the time-delay index and the non-time-delay index; the time-delay water quality index includes total nitrogen, biochemical oxygen demand in five days, total phosphorus, and total organic carbon; the non-time-delay water quality index includes pH, conductivity, dissolved oxygen, turbidity, suspension, and water temperature; Step S3: Use the non-time-delay index as the input and the time-delay index as the output to train a neural network model to obtain an influent water quality prediction model for detecting the influent water quality of the sewage treatment plant, and detect the influent water quality of the sewage treatment plant based on the influent water quality prediction model; wherein, the neural network model is an MHA-LSTM model, and each non-time-delay water quality index corresponds to one MHA-LSTM model.
2. The real-time detection method for the influent water quality of a sewage treatment plant according to claim 1, characterized in that The sampling duration of the historical influent data is 12 months, and the sampling period is once per hour. The water volume index includes flow rate and liquid level; the meteorological index includes air temperature, relative humidity, air pressure, precipitation, and visibility.
3. The real-time detection method for the influent water quality of a sewage treatment plant according to claim 1, characterized in that, In step S2, screening out the non-time-delay indexes with a correlation greater than a preset condition specifically includes: Determine the maximum mutual information coefficient MIC of any two non-time-delay water quality indexes. If the MIC of any two non-time-delay water quality indexes is greater than the set threshold, then screen out the non-time-delay water quality index with a larger average value of the MIC of the remaining non-time-delay water quality indexes among any two of the non-time-delay water quality indexes.
4. The real-time detection method for the influent water quality of a sewage treatment plant according to claim 1, characterized in that The MHA-LSTM model includes an input layer, an LSTM neural network, a multi-head attention mechanism unit, and a multi-layer perceptron; the number of neurons in the input layer is the same as the number of non-time-delay indicators in the input, and the time step of the LSTM neural network is the same as the daily sampling frequency of the influent historical data of the sewage treatment plant; the multi-head attention mechanism unit is used to: based on the outputs of the LSTM neural network at each time step and the query matrix Q, the key matrix K, and the value matrix V of the water quality anomaly standard, the query matrix Q, the key matrix K, and the value matrix V of the keyword are obtained through n different linear transformations to obtain n groups of Q i , V i , K i , where i = 1, 2,..., n, and n is the number of attention heads; for each group of Q i , V i , K i , the corresponding attention head head is obtained through the scaled dot-product attention mechanism i , all attention heads are concatenated into a high-dimensional vector and fed into the multi-layer perceptron; The multi-layer perceptron includes an input layer, a fully connected layer, and an output layer. Among them, the number of neurons in the input layer of the multi-layer perceptron is the same as the number of attention heads of the multi-head attention mechanism unit. The fully connected layer includes 30-80 neurons, and each neuron uses a ReLU activation function. The output layer includes 1 neuron.
5. The real-time detection method for the influent water quality of a sewage treatment plant according to claim 4, characterized in that, In step S3, using the non-time-delay index as the input and the time-delay index as the output to train a neural network model specifically includes: At any moment t, arrange the non-time-delay indicators in the order of pH, conductivity, dissolved oxygen, turbidity, suspended solids, water temperature, flow rate, liquid level, air temperature, relative humidity, air pressure, precipitation, and visibility to form the high-dimensional input I at any moment t t ; Input the high-dimensional input into the LSTM neural network in chronological order to establish a chronological mapping relationship between all non-time-delay indexes and a certain time-delay index; The output of the LSTM neural network at each time step is integrated by the multi-head attention mechanism unit from different information perspectives, and the output data of the multi-head attention mechanism unit is transmitted to the multi-layer perceptron.
6. The real-time detection method for the influent water quality of a sewage treatment plant according to claim 5, characterized in that, Before step S3, training the neural network model, it also includes; Divide the historical influent data into a training set, a validation set, and a test set according to a ratio of 8:1:1; After training the neural network model, it also includes: Intercept the training set of the previous 7-90 days before the current date from the historical influent data to perform 30-250 cyclic iterations on the trained MHA-LSTM model, and the fine-tuning frequency of the MHA-LSTM model is 3-14 days per time.
7. The real-time detection method for the influent water quality of a sewage treatment plant according to claim 4, wherein The loss function of the MHA-LSTM model is as follows: In the above formula, T represents the length of the time series, t represents the time order, and y t pre is the predicted value at time t, and y t mea is the measured value at time t.
8. A real-time detection system for the influent water quality of a sewage treatment plant, which is applied to the real-time detection method for the influent water quality of the sewage treatment plant according to any one of claims 1-7, is characterized in that, including: An index acquisition module that obtains the time-delay indexes and non-time-delay indexes in the historical inlet water data of the sewage treatment plant. The non-time-delay indexes include non-time-delay water quality indexes, water volume indexes, and meteorological indexes, and the time-delay indexes include time-delay water quality indexes; An index screening module that aligns the water volume index, the meteorological index, and the non-time-delay water quality index based on the sampling frequency of the time-delay water quality index, and screens out the non-time-delay indexes with a correlation greater than a preset condition; performs normalization processing on the time-delay indexes and the non-time-delay indexes; A detection module that uses the non-time-delay indexes as inputs and the time-delay indexes as outputs to train a neural network model to obtain an inlet water quality detection model for detecting the inlet water quality of the sewage treatment plant, and detects the inlet water quality of the sewage treatment plant based on the inlet water quality prediction model.
9. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method for real-time detection of the inlet water quality of the sewage treatment plant according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method for real-time detection of the inlet water quality of the sewage treatment plant according to any one of claims 1 to 7.
Citation Information
Patent Citations
Basin pollutant flux prediction method based on LSTM-BP space-time combination model
CN111639748A
Sewage quality prediction method based on optimized LSTM neural network
CN112884056A