Soft measurement method for sewage effluent index BOD5 based on Transform and long-short-term memory network

By combining the Transformer network and the long short-term memory network, the LSTM-former model solves the accuracy problem of nonlinear and time dimension data processing in BOD5 soft measurement, achieving higher model accuracy and accurate capture of the weight relationship of auxiliary variables.

CN118824409AActive Publication Date: 2024-10-22BEIJING UNIV OF TECH

Patent Information

Application Number
CN202410812536.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-22
Publication Date
2024-10-22
Estimated Expiration
2044-06-22

AI Technical Summary

Technical Problem

When the existing BOD5 soft measurement method handles data in nonlinear and time dimensions, it cannot accurately assign the weight relationship between auxiliary variables and key variables, resulting in low model accuracy.

Method used

The LSTM-former model that combines the Transformer network and the long short-term memory network is used. By adding LSTM to the multi-head attention layer of the Transformer, the data information is processed to capture the key features in the BOD5 concentration time series and maintain long-term dependencies.

Benefits of technology

It improves the model's soft measurement accuracy of BOD5 concentration, enhances its ability to analyze historical information of auxiliary variables, accurately captures data characteristics, and solves the problem of traditional Transformer's insufficient attention to single variable historical information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118824409A_ABST
    Figure CN118824409A_ABST
Patent Text Reader

Abstract

The invention discloses a BOD5 index soft measurement method based on a Transform and a long and short term memory network. According to the method, a complete air quality data set which can be used for prediction is constructed by utilizing water outlet index parameters which are easy to measure in sewage treatment and continuous time data of water outlet index parameters which influence BOD5 (Biochemical Oxygen Demand 5). Then performing proportion division based on the preprocessed data set, and constructing a training set and a test set; and carrying out parameter optimization on the LSTM-former model by using the training set data, wherein the parameters comprise the number of attention head layers, the model dimension, the dimensions of Q, K and V in an attention mechanism, the number of neurons, the random inactivation rate, the initial learning rate, the number of iterations, the batch size and the like. Then, an LSTM-former model which can be used for soft measurement of BOD5 concentration and is subjected to parameter optimization is constructed, an optimization algorithm is determined, and an activation function is selected; and predicting based on the trained LSTM-former soft measurement model to obtain a concentration prediction value of BOD5. According to the method, the model precision is improved, and the generalization ability is enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of time series prediction of sewage effluent index BOD5, and in particular to a soft measurement technology for nonlinear and complex data of BOD5 concentration. The present invention is a specific application of a method based on combining a transformer network with a long short-term memory network based on an efficient multi-head attention structure in the field of BOD5 soft measurement of sewage treatment. The present invention improves the soft measurement accuracy in sewage treatment and retains the time series correlation hidden in the time series. Background Art

[0002] Water is an important part of the ecosystem and human health. In order to ensure the sustainable use of water resources and environmental protection, the sewage treatment process is particularly important. Whether the sewage treatment meets the standards directly affects the ecological environment and human health. The quality of sewage treatment is often measured by some key effluent indicators, such as the five-day biochemical oxygen demand (BOD5), which is a key indicator for evaluating the concentration of organic pollutants in water bodies. This parameter is defined as the amount of dissolved oxygen required for aerobic organisms to decompose organic matter in water at a specific temperature within a specific time (usually 5 days). It is used to measure the amount of oxygen required for the decomposition of organic matter in water bodies.

[0003] In reality, the monitoring of effluent indicators in sewage treatment is often measured by instruments. However, some important indicators are usually difficult to measure directly, which involves time-consuming and expensive laboratory tests, and the accuracy of the measuring instruments is unstable, which makes the monitoring of effluent indicators lagging and unstable. Therefore, in order to improve the monitoring ability of sewage treatment effluent indicators, an indirect measurement soft measurement method can be used: using easily measurable auxiliary variables to estimate key variables. In sewage treatment systems, soft measurement technology is used to monitor key variables in product production to control product quality and reduce the cost of traditional hardware measurement.

[0004] At present, the BOD5 soft sensor modeling methods mainly include mechanism modeling, empirical model modeling and data-driven modeling. The mechanism modeling method is a white box model. Its idea is to express all the reactions occurring in the modeling object using formulas and equations, and to show the relationship between variables through these expressions, and to calculate based on the relationship between easy-to-measure variables and difficult-to-measure variables. The mechanism model needs to know the chemical and physical relationship between the parameters, more chemical and physical formulas, and operation data, so it is highly complex, has a large amount of calculation, requires high knowledge of researchers, and has low model accuracy. The empirical model only needs to focus on the relationship formula between the input and output variables to represent the system behavior, but the model only focuses on the description of the steady state, and it is difficult to handle complex and non-steady situations well. The use conditions are limited and the model accuracy is low. The data-driven modeling method is a black box model. It does not need to know the internal mechanism between the parameters. It is a method that describes the relationship between the input and output variables and constructs the output variable after learning this relationship. Its input usually selects variables that are easy to measure, low in acquisition cost, and can be obtained in large quantities, while the output variable is a variable that has the characteristics of difficult measurement and expensive acquisition cost, so it is very suitable for sewage treatment related work.

[0005] Data-driven modeling methods mainly include multivariate statistics and artificial neural network methods. The BOD5 concentration in sewage treatment is affected by many factors and has strong nonlinear characteristics. As a nonlinear science, neural networks are suitable for studying objects with multi-factor, uncertainty, randomness, and nonlinear characteristics. However, due to the characteristics of the serial calculation mechanism of the neural network used, the current method can only process data step by step, and it is impossible to simultaneously connect all the historical information of all auxiliary variables with the key variables. Therefore, it cannot accurately reflect the weight relationship between the auxiliary variables and the key variables, resulting in unsatisfactory model soft measurement results. Summary of the invention

[0006] In order to solve the problem of inaccurate soft measurement results caused by the nonlinearity of BOD5 soft measurement process data and the dependence in the time dimension, the present invention provides a model (LSTM-former) combining a Transformer network and a long short-term memory network for soft measurement of sewage treatment effluent index BOD5. LSTM-former is used to add the long short-term memory network to the operation of Q, K, and V in the multi-head attention layer of Transformer. By processing the data information successively through LSTM and multi-head attention mechanism, the problem of inability to accurately allocate weight relationship in the soft measurement of sewage index BOD5 is further solved. Compared with other neural network models, the uniqueness of our method is that this model can use the multi-head attention mechanism of Transformer to better pay attention to the weight relationship between auxiliary variables and BOD5, capture the key features in the BOD5 concentration time series data, and use LSTM to keep attention to the long-term dependency relationship in each auxiliary variable time series data, making up for the problem that the traditional Transformer model does not pay enough attention to the historical information of a single variable.

[0007] The present invention adopts the following technical solutions and implementation steps:

[0008] S1: Obtain the continuous time data of multiple easily measurable effluent index parameters and effluent index parameters that affect BOD5 after a sewage treatment plant treats sewage, and construct the original sewage index data set.

[0009] S2: Preprocess the constructed initial sewage index data set, correct the outliers, use interpolation method to fill the data gaps, and construct a complete sewage index data set that can be used for soft measurement.

[0010] S3: Proportionally divide the preprocessed data set to construct training and test sets. Use the training set data to tune the parameters of the LSTM-former model, including the number of attention head layers, model dimension, the dimensions of Q, K, and V in the attention mechanism, the number of neurons, random inactivation rate, initial learning rate, number of iterations, and batch size.

[0011] S4: Construct a parameter-tuned LSTM-former model that can be used for soft measurement of BOD5 concentration, determine the optimization algorithm, select the activation function, and ensure the dynamic consistency between the training sequence and the original true sequence.

[0012] S5: Based on the trained LSTM-former soft sensor model, the test set is predicted to obtain the concentration prediction value of BOD5. The performance of the model is evaluated based on the predicted value and the true value.

[0013] Specifically, affected by different weather environments and precipitation, as the weather becomes more severe, the complexity of BOD5 concentration also increases. Therefore, this experiment selects the sewage effluent index data set during stormy weather to perform soft measurement of BOD5 concentration under the corresponding weather. The data set contains the target variable BOD5 concentration data every fifteen minutes and other related variables such as soluble non-degradable organic matter, soluble rapidly biodegradable organic matter, insoluble particulate non-degradable organic matter, insoluble slowly degradable organic matter, biomass of active heterotrophic bacteria, biomass of active autotrophic bacteria, inert substances produced by the decay of biological solids, dissolved oxygen, nitrate nitrogen, ammonia nitrogen, soluble biodegradable organic nitrogen, particulate degradable organic nitrogen, alkalinity and total suspended solids.

[0014] Furthermore, outliers and missing values ​​are first checked, then outliers are deleted, and the missing values ​​of the data set are filled using the median interpolation method.

[0015] Preferably, 85% of the data set is divided into a training set, and the remaining 15% is divided into a test set. The number of attention head layers is 4, the model dimension is 512, the dimensions of Q, K, and V in the attention mechanism are 64, the number of neurons is 64, the random inactivation rate is 0.1, the learning rate is 0.001, the number of iterations is 200, and the batch size is 128.

[0016] Further, the model includes a basic LSTM framework, a new Transformer framework of a multi-head attention operation mechanism, a coding and decoding input and output strategy, and a fully connected layer. The gate structure inside the LSTM cell unit is composed of three parts: a forget gate, an input gate, and an output gate, and these gate structures are responsible for updating the cell state and the hidden layer state. The multi-head attention layer adopts a brand-new operation mechanism. The three variables Q, K, and V output after the input sequence is decoded are respectively operated by LSTM to form new Q, K, and V, and then the original dot product calculation, normalization, and other related operations of the multi-head attention mechanism are used to form the final attention head output. On the basis of the Transformer cause operation mechanism, Q, K, and V are first processed as LSTM inputs, so that the model first analyzes the long-term dependency relationship in the historical data information of each auxiliary variable from a local perspective, and then considers the weight relationship between the auxiliary variable and the target variable globally through the original attention mechanism, thereby improving the modeling ability of the system dynamics. The coding and decoding input and output structure realizes the input and output of the model to the target sequence. The fully connected layer is responsible for the final result output of the soft measurement model of the present invention.

[0017] Preferably, the loss function in the soft sensor model adopts the standard normalized MSE, the activation function adopts the ReLU function, and during the training process of S4, learning is performed through the Adam function.

[0018] Compared with the prior art, the present invention has the following beneficial effects:

[0019] (1) The long short-term memory network is integrated into the operation of the multi-head attention layer of the Transformer network, which enhances the ability to analyze the historical information of each auxiliary variable during model training and solves the problem that the traditional Transformer does not pay enough attention to the historical information of a single auxiliary variable.

[0020] (2) The sophisticated and unique LSTM-former structure design enables the model to use the parallel computing capability of the Transformer to globally consider the impact of auxiliary variables on key variables, and to use LSTM to focus on the long-term dependencies in the sequence of each auxiliary variable, thereby more accurately capturing the data characteristics of BOD5 and improving the accuracy of the model in soft measurement of data with long-term dependency characteristics. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 The overall structure diagram of the soft sensor network proposed by the method of the present invention;

[0022] Figure 2 This is a diagram of the LSTM-former network structure proposed by the method of the present invention;

[0023] Figure 3 The flowchart of the operation in the new multi-head attention layer proposed by the method of the present invention;

[0024] Figure 4 Schematic diagram for comparing soft measurement results of the method of the present invention. DETAILED DESCRIPTION

[0025] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0026] Based on the above problems, the present invention proposes a new soft measurement framework LSTM-former for soft measurement of multivariate time series. The core idea of ​​LSTM-former is: the information is processed by LSTM and multi-head attention mechanism in sequence, while realizing the specific analysis of the historical information of each auxiliary variable, it can also consider all positions in the input sequence from a global perspective, make full use of the information in the entire sequence, and improve the model's ability to capture the key features in the BOD5 concentration time series data, so as to accurately assign the weight relationship between the auxiliary variables and BOD5. Finally, by constructing a fully connected layer network to output the BOD5 concentration value, accurate soft measurement of BOD5 concentration can be achieved.

[0027] As the present invention Figure 1 As shown in the overall flow chart of soft measurement of BOD5 concentration, it is mainly divided into the following steps: S1: Obtain the continuous time data of multiple easy-to-measure effluent index parameters and effluent index parameters that affect BOD5 after a sewage treatment plant treats sewage, and construct the original sewage index data set. S2: Preprocess the constructed sewage index initial data set, correct the outliers, use interpolation to fill the data gaps, and construct a complete sewage index data set that can be used for soft measurement. S3: Proportionally divide the preprocessed data set to construct a training set and a test set. The training set data is used to tune the parameters of the LSTM-former model, including the number of attention head layers, model dimensions, dimensions of Q, K, and V in the attention mechanism, the number of neurons, random inactivation rate, initial learning rate, number of iterations, and batch size. S4: Construct a parameter-tuned LSTM-former model that can be used for soft measurement of BOD5 concentration, determine the optimization algorithm, select the activation function, and ensure the dynamic consistency between the training sequence and the original true sequence. S5: Predict the test set based on the trained LSTM-former soft measurement model to obtain the predicted value of BOD5 concentration. The performance of the model is evaluated based on the predicted values ​​and the true values.

[0028] S1: Affected by different weather environments and precipitation, with the increase of severe weather conditions, such as sunny days, rainy days, and rainstorms, the complexity of BOD5 concentration also increases. This experiment selects the sewage effluent indicator data set during stormy weather with the highest data complexity and performs soft measurement of BOD5 concentration under the corresponding weather. The data set collected by a sewage treatment plant in Beijing after sewage treatment was collected, which contains the target variable BOD5 concentration data every fifteen minutes and other related auxiliary variables such as soluble non-degradable organic matter, soluble rapidly biodegradable organic matter, insoluble particulate non-degradable organic matter, insoluble slowly degradable organic matter, biomass of active heterotrophic bacteria, biomass of active autotrophic bacteria, inert substances produced by the decay of biological solids, dissolved oxygen, nitrate nitrogen, ammonia nitrogen, soluble biodegradable organic nitrogen, particulate degradable organic nitrogen, alkalinity and total suspended solids.

[0029] These effluent indicators are stipulated by the international standards (ISO 14001 Environmental Management System and IS0 55001 Asset Management Standard) formulated by the International Organization for Standardization (ISO), and the relevant standards formulated by the Pollutant Discharge Standard for Urban Wastewater Treatment Plants in China (GB18918-2002) and the Comprehensive Wastewater Discharge Standard (GB8978-1996). Except for BOD5, these variables are effluent indicators directly measured by hardware sensors in the actual sewage treatment process, but they cannot be used as key variables to judge the quality of sewage treatment. The specific contents are shown in Table 1 below:

[0030] Table 1 Variables used in soft measurement of BOD5 concentration in the present invention

[0031]

[0032]

[0033] S2: Due to the uncertainty of data acquisition equipment failure, there will always be some missing values ​​and outliers in the collected data, and the existence of these values ​​will affect the accuracy of the model. Our invention method proposes a median interpolation method for data preprocessing. First, the outliers are removed, and then all the existing missing values ​​are found. These values ​​need to be processed. Our method uses the sliding window principle combined with the context data of the vacancy to fill the missing data with the median. This step will start from the first missing data sampling point and continue to the last missing data sampling point. After that, we construct an M*N (M>0, N>0) dimensional initial data set based on the data scale collected in S1, where M is the sum of the auxiliary variables and the target variables in S1, which is 14, and N is the total number of samples of the acquired data. In the present invention, N is 1344. The input data can be represented by the following formula:

[0034]

[0035] The specific form is

[0036]

[0037]

[0038] The input at time t is: X t =[x 2t , x 2t …x 14t ] T

[0039] S3: Divide the dataset created in S2 into a training set and a test set, with the training set accounting for 85% and the rest for the test set. The former is used to build the model, and the latter is used to evaluate the generalization ability of the model when predicting unknown samples. 2 Below 80% is the standard), we need to adjust the network's hyperparameters. The specific operations are as follows:

[0040] STEP 1: Let the neuron input be Z, each dimension be Zi, corresponding to the weight v that can enhance or weaken the input signal i , to achieve nonlinear mapping to [0,1] or [-1,1]. The specific number of neurons will be adjusted according to the actual feedback of the model. To avoid the overall complexity of the model, the number of neurons should be less than 100, with 2 n The number of neurons with the highest model accuracy is selected according to the regular changes. In this example, the number of neurons is determined to be 64. Increasing the number of neurons generally improves the accuracy of the model, but if the number of neurons is increased too much, the model will be overfitted.

[0041] STEP2: Dropout is a regularization method for neural network models. During the training process, the generalization ability of the model is enhanced by randomly ignoring some neurons. In the training of deep networks, a part of the neuron nodes are randomly "temporarily discarded" with a certain probability. If the dropout is 0.1, 10% of the nodes will be discarded. Specifically, dropout acts on each small batch of training data. Due to its mechanism of randomly discarding some neurons, it is equivalent to training a neural network with a different structure in each iteration. In this example, in order to prevent the model from overfitting but avoid discarding too many neuron nodes, dropout is set to 0.1.

[0042] STEP3: Select the learning rate scheme. As an important hyperparameter in supervised learning and deep learning, the learning rate determines whether the objective function can converge to the local minimum and when it converges to the minimum. A suitable learning rate can make the objective function converge to the local minimum in a suitable time. In order to avoid the problem that the loss function of the model changes too slowly and falls into the local minimum or the loss function cannot converge, we have developed a fractional variable learning rate slowdown scheme, setting the initial learning rate α0 to 0.001, and the learning rate decreases according to the following formula:

[0043] α=α0 / (1+kt)

[0044] k is a hyperparameter used to control the learning rate slowdown. Each change of α is above 90% of the previous one, so k is set to 0.1 in this example. t is the number of training rounds, which is set to 200 in line with epoch.

[0045] STEP4: Set an appropriate number of iterations, epochs. When a complete data set passes through the neural network once and returns once, this process is called an epoch. The main purpose of setting epochs is to divide the entire training process of the model into several segments, so that we can better observe and adjust the training of the model. By iteratively comparing the network accuracy by increasing the epoch by 10 each time, when the epoch is increased after reaching 200, the network accuracy is not significantly improved. To avoid the network training taking too long, set the epoch to 200, which also guarantees the prediction accuracy of the model.

[0046] STEP5: Set a suitable batch size. Before using Batch Size, it means that when the network is trained, all data is input into the network at once, and then their gradients are calculated for back propagation. Batch size is set to 2 m (m>0), increase Batchsize until the model accuracy does not change significantly. In order to ensure model accuracy and increase training speed, the batch size is set to 128.

[0047] S4: The main neural network of the soft sensor model constructed in the present invention is LSTM-former, such as Figure 2LSTM (Long Short-Term Memory) is a time-recurring network, which is often used in the field of time series prediction in deep learning. The core concept of LSTM is the cell state. Through training, the gate structure can control which information needs to be retained and which information needs to be forgotten. The selected information is added to the cell state through calculation, and as the cell state is cyclically transmitted between moments, the information from the earlier time step can also be used for the later time step, thus realizing the long-term memory function. The corresponding cell update process formula is as follows:

[0048] f t =σ(W f ·[x t ,h t-1 ]+b f )

[0049] where f t is the forget gate, σ is the sigmoid activation function, W f f t The weight matrix, x t is the input at time t, h t-1 The memory at time t-1 is the hidden layer state, b f f t The bias term.

[0050] i t =σ(W i ·[x t ,h t-1 ]+b i )

[0051] where i t is the input gate, σ is the sigmoid activation function, W i for i t The weight matrix, x t is the input at time t, b i for i t The bias term.

[0052]

[0053] Input x to the forget gate t and the hidden layer state h t-1 To go through a tanh layer, get a new candidate value W c and b c

[0054] Represent the weight and bias of the candidate layer respectively; C t Indicates the output after the cell state is updated; C t-1Indicates the cell state at the previous moment, and * is the matrix element mapping multiplication operation.

[0055] o t =σ(W o ·[x t ,h t-1 ]+b o )

[0056] Among them t is the output gate, W o for o t The weight matrix, b o for o t The bias term.

[0057] h t =o t *tanh(C t )

[0058] tanh is the hyperbolic tangent function, * is the matrix element mapping multiplication operation, h t Represents the final output.

[0059] The Transformer neural network is a deep learning model with powerful modeling capabilities, which has been proven to achieve good results in natural language processing, computer vision and other fields. The most notable feature of the Transformer is that it uses the self-attention mechanism, which allows the model to consider information at all positions in the input sequence at the same time, thereby better capturing the dependencies between inputs. The self-attention mechanism in the Transformer is extended to a multi-head attention mechanism. In this mechanism, the model divides the input sequence into multiple heads and applies a separate self-attention mechanism to each head. Ultimately, the outputs produced by each head are concatenated and passed to the next layer.

[0060] The following is a detailed introduction to Transformer's attention mechanism:

[0061] For a given input sequence X = {x1, x2, ..., x n}, where each element x i (i is any number from 1 to n) is a vector with a total of n elements. We take each input vector x i Transformed into a query vector, a key vector, and a value vector. These vectors can be calculated through matrix multiplication and bias vector:

[0062] Query vector Q i =W Q ·x i

[0063] Key vector K i =W K ·x i

[0064] Value vector V i =W V ·x i

[0065] Where W Q , W K , W V are learnable weight matrices, and the dimensions of these vectors are the model dimensions.

[0066] Next, we transform each query vector Q i (i is any number from 1 to n) and all key vectors K j (j is 1, 2, 3, 4...n) Calculate the dot product, each Q i Get j attention scores, which are calculated as follows:

[0067]

[0068] where d k is the vector dimension. The purpose of the attention score is to measure the relevance between the query vector and the key vector. The dot product is divided by to balance the order of magnitude of the scores. These scores are called attention weights and can be normalized by the Softmax function so that they represent the attention allocation when the sum is 1. The following is their normalization formula, which is obtained for the input x i The j attention weights are:

[0069]

[0070] Finally, we will transform each value vector V j The weighted sum is performed with the corresponding attention weight to obtain the i-th input x i The self-attention output of:

[0071] Attention(Q i ,V)=Σj AttnWeights(Q i ,K j )V j

[0072] The above process is the core of the self-attention mechanism, which allows the model to extract useful information from all input positions and consider the dependencies between inputs when representing sequences. To improve computational efficiency, the above self-attention process is generally expressed in matrices for parallel computation in actual operations, so the output of the entire process can be summarized as the following formula:

[0073]

[0074] In the multi-head attention mechanism, this process is applied to each attention head O of the input matrix X. i (Assuming there are h attention heads in total, i is 1 to h): We put all word vectors into a matrix X, and then add them to the three weight matrices Multiply them and we get Q i , K i , V i Matrix. Each row in the matrix X represents the word vector of each word. i , K i , V i Each row in the matrix represents a Query vector, a Key vector, and a Value vector, and the vector dimension is d k Then apply the above formula, and finally concatenate the attention results of h heads to get the final multi-head attention result O, the formula is as follows:

[0075]

[0076] O i =Attention(Q i ,K i ,V i )i=1......h

[0077] O=Concat(O1,O2,...,O h )W O

[0078] Among them, i is the output of the i-th attention head in the multi-head attention layer, O is the final multi-head attention output, and the Concat function concatenates multiple vectors according to the specified dimension. O is the final output weight matrix.

[0079] like Figure 3 As shown in the figure, the LSTM mechanism is integrated into the Transformer multi-head attention operation. Q, K, and V are processed by LSTM before the self-attention mechanism is operated. They are used as x in the formula t Input into LSTM and output the new Q* , K * 、V * , in subsequent operations.

[0080] After building the core network LSTM-former, we need some optimization methods to ensure the dynamic consistency between the training sequence and the original real sequence. The specific operations are as follows:

[0081] STEP 1: Select an optimization algorithm. The current mainstream optimization algorithms include gradient descent method and Nesterov gradient acceleration method. This invention uses the Adam algorithm to address the large-scale and non-steady-state characteristics of BOD5 data. The specific steps are as follows:

[0082] (1) Initialize and determine the parameters (step size), (moment estimation of exponential decay rate, between [0, 1)) and random objective function.

[0083] (2) Initialize parameter vector, first-order moment vector, second-order moment vector and time step;

[0084] (3) Loop. When the parameters have not converged, the loop iteratively updates each part. That is, the time step is increased by 1, the gradient of the objective function with respect to the parameters at the time step is updated, the first-order moment estimate and the second-order original moment estimate of the deviation are updated, and then the first-order moment estimate and the second-order moment estimate of the deviation correction are calculated, and then the initial parameters of the model are updated with the above calculated values;

[0085] (4) When the parameters converge, the model parameters are returned.

[0086] STEP2: Determine the activation function. The neurons in the hidden layer and the output layer convert the weighted sum of the input end into the neuron output value through the activation function. In order to adapt to the nonlinearity of BOD5 data and improve the robustness of the network, the present invention adopts the ReLU activation function, and its formula is as follows:

[0087] ReLU(x) = max(0,x)

[0088] S5: Based on the trained LSTM-former soft sensor model, the test set is predicted to obtain the predicted value of PM2.5 concentration. Figure 4 The soft measurement value and the true value are compared. Then the performance of the model is evaluated based on the soft measurement value and the true value. The evaluation formula used in the present invention is as follows:

[0089]

[0090] Where MAE is the mean absolute error and RMSE is the root mean square error. and iRepresent the predicted value and the true value respectively. The lower the MAE and RMSE, the better the effect of the model. Table 2 is an evaluation example of the soft measurement of BOD5, an indicator of sewage treatment effluent under heavy rain weather selected by the present invention. In order to reduce the impact of randomness on the experiment, the experiment was repeated 10 times, and the average values ​​of the two indicators were compared. The LSTM-former network adopted by the present invention shows very good accuracy for the soft measurement of BOD5. The LSTM mechanism and multi-head attention mechanism of the model ensure its generalization ability.

[0091] Table 2: LSTM-former soft sensor performance evaluation of ten experiments

[0092]

[0093] The core technical difficulty of the present invention lies in the innovation of the common linear combination of LSTM and Transformer models into a fusion algorithm. First, the present invention makes the LSTM algorithm process not the initial input data set, but the three matrix variables Q, K, and V in the operation process of the Transformer multi-head attention mechanism. Compared with directly converting the data in the data set into a common matrix form, these three variables express the data set in a more refined word matrix form and are used for subsequent multi-head attention calculations. Secondly, due to the powerful parallel computing mechanism of Transformer, the LSTM algorithm is integrated into the operation of the multi-head attention mechanism, retaining the characteristics of the overall model processing input information in parallel from beginning to end, avoiding the error influence caused by the need for LSTM to serially process input data in the linear combination of the model, and improving the operation efficiency.

[0094] Disclosed above are only a few specific embodiments of the present invention; however, the embodiments of the present invention are not limited thereto, and any modification, replacement and improvement made within the spirit and principle of the above-mentioned implementation methods shall be included in the protection scope of the technical solution.

Claims

1. A soft measurement method for sewage effluent index BOD5 based on Transformer and long short-term memory network, characterized in that: The following steps are involved: S1: Obtain the continuous time data of multiple easily measurable effluent index parameters and effluent index parameters affecting BOD5 after a sewage treatment plant treats sewage, and construct the original sewage index data set; S2: Preprocess the constructed initial data set of sewage effluent indicators, correct the outliers, fill the data gaps with interpolation, and construct a complete sewage effluent indicator data set Z that can be used for soft measurement; where M is the sum of the auxiliary variable and the target variable, and N is the total number of samples of the acquired data; M is 14; The specific form is The input at time t is: X t =[x 2t ,x 2t …x 14t ] T S3: Proportionally divide the preprocessed data set to construct training and test sets; use the training set data to tune the parameters of the LSTM-former model, including the number of neurons, random inactivation rate, learning rate α, initial learning rate α0, number of iterations, and batch size; α=α0 / (1+kt) Where k is a hyperparameter used to control the slowdown of the learning rate α, which is set to 0.1, and each change of α is above 90% of the previous one; t is the number of training rounds, which is set to 200 in line with epoch; S4: Construct a parameter-tuned LSTM-former model that can be used for soft measurement of BOD5 concentration. According to the model training performance, determine the optimization algorithm and select the activation function ReLU to ensure the dynamic consistency between the training sequence and the original true sequence. The formula for BOD5 soft measurement is as follows: First, the calculation formula of LSTM: f t =σ(W f ·[x t ,h t-1 ]+b f ) i t =σ(W i ·[x t ,h t-1 ]+b i ) the t =σ(W o ·[x t ,h t-1 ]+b o ) h t =o t *tanh(C t ) The subscript t represents the time, f t represents the input gate, i t represents the forget gate, o t represents the output gate; σ represents the Sigmoid function; W f and b f They represent the forget gate f t The weights and biases, W i and b i Represents the input gate i t The weights and biases, W o and b o Represent the input gate o t The weights and biases of t-1 represents the hidden layer state, x t Represents the input at the current time t, which passes through a tanh layer in the forget gate to obtain a new candidate value W c and b c Represent the candidate layers The weights and biases of C t Indicates the output after the cell state is updated; C t-1 Indicates the cell state at the previous moment, h t Represents the final output; The second is the calculation formula of Transformer multi-head attention mechanism: Q i =X·W i Q K i =X·W i K V i =X·W i V O i =Attention(Q i ,K i ,V i ) i=1......h O=Concat(O1,O2,...,O h )W O Where Q i , K i 、V i The three matrices obtained by transforming the input matrix X through matrix operations and multiplying it by the training weight matrix (W i Q , W i K , W i V ) The query matrix, key matrix and value matrix converted from k is the vector dimension, O i is the output of the i-th attention head in the multi-head attention layer. The Concat function concatenates multiple vectors according to the specified dimension. O is the final output weight matrix, O is the final multi-head attention output; finally, the LSTM mechanism is integrated into the Transformer multi-head attention operation. Before Q, K, and V are operated by the self-attention mechanism, they are processed by LSTM and used as x in the formula. t Input into LSTM and output the new Q * , K * 、V * , in subsequent operations; S5: Based on the trained LSTM-former soft measurement model, soft measurement is performed on the test set to obtain the soft measurement value of BOD5 concentration; and the performance of the model is evaluated based on the soft measurement value and the true value.

2. The soft measurement method for sewage effluent index BOD5 based on Transformer and long short-term memory network as claimed in claim 1 is characterized in that Assign null values ​​to outliers, detect the number of missing values, and then use median interpolation to fill in all missing values. Median interpolation is to fill in missing values ​​by finding the value closest to the middle of the data set.

3. The soft measurement method for sewage effluent index BOD5 based on Transformer and long short-term memory network as claimed in claim 1 is characterized in that: The initial value of the learning rate in the fractional variable learning rate mitigation scheme is set to 0.001, and the mitigation amplitude is 0.

95.

4. The soft measurement method for sewage effluent index BOD5 based on Transformer and long short-term memory network as claimed in claim 1 is characterized in that: Select Adam as the optimization algorithm and ReLU as the activation function.

Citation Information

Patent Citations

  • Air quality PM2.5 prediction method based on ordered neuron long-short-term memory network

    CN116432836A

  • Target detection method based on LSTM-Transform

    CN116630774A

  • Dynamic soft measurement modeling method based on enhanced local perception self-attention

    CN116882299A

  • Deep-learning-based method for predicting residual life of aero-engine

    WO2024045377A1

Cited By

  • Method and device for realizing settlement prediction based on ground surface settlement data of intelligent recovery

    CN119149928A

  • Method for predicting drifting trajectory of personnel falling into water at sea

    CN119538755A

  • TCN-LSTM water quality prediction method based on variational mode decomposition and attention mechanism

    CN119624217A

  • A TCN-LSTM water quality prediction method based on variational mode decomposition and attention mechanism

    CN119624217B

  • Sewage outlet AI intelligent real-time monitoring method based on multi-modal data processing

    CN119720079A