[go: up one dir, main page]

CN118228766B - A method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism - Google Patents

A method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism Download PDF

Info

Publication number
CN118228766B
CN118228766B CN202410658265.4A CN202410658265A CN118228766B CN 118228766 B CN118228766 B CN 118228766B CN 202410658265 A CN202410658265 A CN 202410658265A CN 118228766 B CN118228766 B CN 118228766B
Authority
CN
China
Prior art keywords
function
ammonia nitrogen
nitrogen concentration
self
convolution
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202410658265.4A
Other languages
Chinese (zh)
Other versions
CN118228766A (en
Inventor
权利敏
张勇
穆国庆
赵景波
张民
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Qingdao University of Technology
Original Assignee
Qingdao University of Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Qingdao University of Technology filed Critical Qingdao University of Technology
Priority to CN202410658265.4A priority Critical patent/CN118228766B/en
Publication of CN118228766A publication Critical patent/CN118228766A/en
Application granted granted Critical
Publication of CN118228766B publication Critical patent/CN118228766B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/044Recurrent networks, e.g. Hopfield networks
    • G06N3/0442Recurrent networks, e.g. Hopfield networks characterised by memory or gating, e.g. long short-term memory [LSTM] or gated recurrent units [GRU]
    • GPHYSICS
    • G01MEASURING; TESTING
    • G01NINVESTIGATING OR ANALYSING MATERIALS BY DETERMINING THEIR CHEMICAL OR PHYSICAL PROPERTIES
    • G01N33/00Investigating or analysing materials by specific methods not covered by groups G01N1/00 - G01N31/00
    • G01N33/18Water
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/0464Convolutional networks [CNN, ConvNet]
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/048Activation functions
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • General Physics & Mathematics (AREA)
  • Evolutionary Computation (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • General Engineering & Computer Science (AREA)
  • Molecular Biology (AREA)
  • Artificial Intelligence (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Chemical & Material Sciences (AREA)
  • Food Science & Technology (AREA)
  • Pathology (AREA)
  • Biochemistry (AREA)
  • Immunology (AREA)
  • Medicinal Chemistry (AREA)
  • Analytical Chemistry (AREA)
  • Investigating Or Analyzing Non-Biological Materials By The Use Of Chemical Means (AREA)

Abstract

The invention relates to a method for measuring the ammonia nitrogen concentration of effluent water based on a convolution layer and a self-attention mechanism, which comprises the following steps: constructing a sample data set of the variable easy to measure; step 2: constructing a convolution layer, substituting the easily-measured variable into a convolution function to process, and applying a nonlinear activation function to output data of the convolution function by the convolution function; step 3: setting a self-attention mechanism function, and reducing noise on the data; step 4: constructing a long-term and short-term memory neural network model based on a convolution function and a self-attention mechanism function to obtain a measurement model; step 5: adjusting and optimizing model parameters of the measurement model through a self-adaptive Bayesian optimization strategy to obtain an optimal detection model; step 6: and obtaining the ammonia nitrogen concentration of the final effluent. Compared with the prior art, the method has the remarkable advantages in the aspects of cost, noise suppression, generalization capability, real-time response and detection precision, and provides a more efficient and reliable ammonia nitrogen concentration measuring method for the field of urban sewage treatment.

Description

一种基于卷积层和自注意力机制的出水氨氮浓度测量方法A method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism

技术领域Technical Field

本发明涉及城市污水处理检测技术领域,具体的涉及一种基于卷积层和自注意力机制的出水氨氮浓度测量方法。The present invention relates to the technical field of urban sewage treatment detection, and in particular to a method for measuring effluent ammonia nitrogen concentration based on a convolutional layer and a self-attention mechanism.

背景技术Background technique

城市水体富营养化问题,主要由氮磷污染物引起,这一问题已引起广泛关注。为了应对这一挑战,我国对城市污水处理中氮磷排放的要求日益严格,监管标准也在不断提高。城市污水处理设施不仅要清除有机污染物,还需有效降低氮磷排放,这对于防治水污染、改善城市水环境质量具有重要意义。在这种背景下,准确测量出水水质指标显得尤为重要,它是确保污水处理持续有效、出水水质达标的关键。The eutrophication of urban water bodies, mainly caused by nitrogen and phosphorus pollutants, has attracted widespread attention. In order to meet this challenge, my country has increasingly stringent requirements for nitrogen and phosphorus emissions in urban sewage treatment, and regulatory standards are also constantly improving. Urban sewage treatment facilities must not only remove organic pollutants, but also effectively reduce nitrogen and phosphorus emissions, which is of great significance for preventing and controlling water pollution and improving the quality of urban water environment. In this context, accurate measurement of effluent water quality indicators is particularly important, which is the key to ensuring that sewage treatment is continuously effective and that effluent water quality meets standards.

出水氨氮浓度是衡量城市污水处理效果的重要指标之一,实时精准检测出水氨氮浓度有助于提高污水处理过程的控制性能。传统的出水氨氮浓度测量方法主要包括化学分析法和在线监测仪器。化学分析法涉及将水样送至实验室,通过化学试剂处理和分光光度计等设备进行氨氮浓度的检测,能够提供准确结果,但存在时间延迟、成本高昂和操作复杂的问题。相比之下,在线监测仪器能够实时监测氨氮浓度,但维护成本高,易受干扰,且初始投资大。这些传统的测量方法在实际应用中面临诸多挑战,促使研究人员探索更高效、经济的替代方案。The concentration of ammonia nitrogen in effluent is one of the important indicators for measuring the effect of urban sewage treatment. Real-time and accurate detection of ammonia nitrogen concentration in effluent can help improve the control performance of the sewage treatment process. Traditional methods for measuring ammonia nitrogen concentration in effluent mainly include chemical analysis and online monitoring instruments. The chemical analysis method involves sending water samples to the laboratory, and detecting ammonia nitrogen concentration through chemical reagent treatment and equipment such as spectrophotometers. It can provide accurate results, but there are problems such as time delay, high cost and complex operation. In contrast, online monitoring instruments can monitor ammonia nitrogen concentration in real time, but they have high maintenance costs, are susceptible to interference, and have large initial investments. These traditional measurement methods face many challenges in practical applications, prompting researchers to explore more efficient and economical alternatives.

近年来,基于模型的检测方法被提出,这些方法旨在通过数学模型来检测出水氨氮浓度。然而,城市污水处理过程中进水流量和污染物成分的不断变化,以及复杂的生物化学反应,使得建立精确的数学模型变得困难重重。目前,基于模糊神经网络(FNN)、长短期记忆(LSTM)网络和极限学习机(ELM)等检测方法被提出,但这些方法在实际应用中普遍存在模型泛化能力不足和数据质量不佳的问题。尤其是在处理大规模城市污水处理数据时,这些方法在检测精度和时效性方面仍有待提高。此外,污水处理过程中的输入数据易受气候变化、季节性变动等因素影响,呈现出较大的波动性和不确定性,对模型泛化能力和稳定性提出了挑战。In recent years, model-based detection methods have been proposed, which aim to detect the effluent ammonia nitrogen concentration through mathematical models. However, the constant changes in influent flow and pollutant composition in the urban sewage treatment process, as well as complex biochemical reactions, make it difficult to establish an accurate mathematical model. At present, detection methods based on fuzzy neural networks (FNN), long short-term memory (LSTM) networks, and extreme learning machines (ELM) have been proposed, but these methods generally have problems with insufficient model generalization ability and poor data quality in practical applications. Especially when dealing with large-scale urban sewage treatment data, these methods still need to be improved in terms of detection accuracy and timeliness. In addition, the input data in the sewage treatment process is easily affected by factors such as climate change and seasonal changes, showing large volatility and uncertainty, which poses a challenge to the generalization ability and stability of the model.

因此,针对现有技术中针对解决城市污水处理领域中出水氨氮浓度测量所存在的模型成本高、数据噪声干扰、模型泛化能力差和实时响应性慢等问题,是本领域技术人员亟需解决的。Therefore, it is urgent for technical personnel in this field to solve the problems of high model cost, data noise interference, poor model generalization ability and slow real-time responsiveness in the existing technology for measuring effluent ammonia nitrogen concentration in the field of urban sewage treatment.

发明内容Summary of the invention

针对现有技术中存在的问题,本发明的目的在于:提供一种在经济性、准确度和时效性上均有提高,能够处理大规模城市污水处理数据,提高模型的泛化能力和数据质量的适应性,从而实时准确检测出水氨氮浓度的测量方法。In view of the problems existing in the prior art, the purpose of the present invention is to provide a measurement method that has improvements in economy, accuracy and timeliness, can process large-scale urban sewage treatment data, improve the generalization ability of the model and the adaptability of data quality, and thus accurately detect the ammonia nitrogen concentration in water in real time.

为实现上述目的,本发明提出了集成卷积层和自注意力机制(SE)的长短期记忆神经网络(简称CS-LSTM),利用易获取数据构建出水氨氮浓度检测模型,从而降低了检测成本。通过集成卷积层、SE以及LSTM,旨在解决时间序列数据中长期依赖性捕捉难的问题,有效地从复杂数据中提取特征,降低噪声,并进行精准测量。此外,改进的贝叶斯优化算法解决了模型参数最优化问题,提高了检测模型的稳定性和准确性。To achieve the above objectives, the present invention proposes a long short-term memory neural network (CS-LSTM for short) integrating convolutional layers and self-attention mechanism (SE), and uses easily accessible data to build a water ammonia nitrogen concentration detection model, thereby reducing the detection cost. By integrating convolutional layers, SE and LSTM, it aims to solve the problem of difficulty in capturing long-term dependencies in time series data, effectively extract features from complex data, reduce noise, and perform accurate measurements. In addition, the improved Bayesian optimization algorithm solves the problem of model parameter optimization and improves the stability and accuracy of the detection model.

具体的,本发明采取的技术方案是:一种基于卷积层和自注意力机制的出水氨氮浓度测量方法,包括以下步骤:Specifically, the technical solution adopted by the present invention is: a method for measuring effluent ammonia nitrogen concentration based on a convolutional layer and a self-attention mechanism, comprising the following steps:

步骤1:收集影响出水氨氮浓度的易测变量,构建易测变量样本数据集;Step 1: Collect the easily measurable variables that affect the effluent ammonia nitrogen concentration and construct a sample data set of easily measurable variables;

步骤2:引用卷积函数构建卷积层,将易测变量代入卷积函数进行处理,得到数据特征,卷积函数对其输出数据应用一个非线性激活函数;Step 2: Use the convolution function to construct a convolution layer, substitute the easily measurable variables into the convolution function for processing, and obtain data features. The convolution function applies a nonlinear activation function to its output data.

步骤3:设置自注意力机制函数,将卷积函数得到的数据特征输入到所述自注意力机制函数,自注意力机制函数通过学习不同通道之间的非线性关系对数据进行降噪;Step 3: Setting a self-attention mechanism function, inputting the data features obtained by the convolution function into the self-attention mechanism function, and the self-attention mechanism function denoises the data by learning the nonlinear relationship between different channels;

步骤4:构建基于卷积函数和自注意力机制函数的长短期记忆神经网络模型,对步骤1-3收集的影响的因素进行建模,得到出水氨氮浓度的测量模型Step 4: Construct a long short-term memory neural network model based on convolution function and self-attention mechanism function, model the influencing factors collected in steps 1-3, and obtain the measurement model of effluent ammonia nitrogen concentration ;

步骤5:通过自适应贝叶斯优化策略,对测量模型的模型参数进行调节和优化,设定目标函数,引入高斯过程作为起始的先验分布,依据观测数据,计算后验分布的均值与方差,并通过自适应采样函数来依据现有的观测数据动态调整,以确定下一步的观测点,获得最优检测模型Step 5: Use the adaptive Bayesian optimization strategy to optimize the measurement model The model parameters are adjusted and optimized, and the objective function is set , introduce the Gaussian process as the starting prior distribution, calculate the mean and variance of the posterior distribution based on the observed data, and dynamically adjust the existing observed data through the adaptive sampling function to determine the next observation point and obtain the optimal detection model ;

步骤6:将获得的影响出水氨氮浓度的变量,输入到最优检测模型中,可获取最终出水氨氮浓度Step 6: Input the variables that affect the effluent ammonia nitrogen concentration into the optimal detection model The final effluent ammonia nitrogen concentration can be obtained .

上述的基于卷积层和自注意力机制的出水氨氮浓度测量方法,在步骤1中,所述易测变量包括好氧末段溶解氧、好氧末端总固体悬浮物、出水ph值、出水氧化还原电位、出水硝态氮,所述样本数据集为,收集的出水氨氮浓度数据表示为为第i个出水氨氮浓度点,n表示易测变量的样本数量。In the above-mentioned method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism, in step 1, the easily measurable variables include dissolved oxygen at the end of aerobic phase, total suspended solids at the end of aerobic phase, effluent pH value, effluent redox potential, and effluent nitrate nitrogen. The sample data set is The collected effluent ammonia nitrogen concentration data is expressed as , is the i -th effluent ammonia nitrogen concentration point, and n represents the number of samples of easily measurable variables.

上述的基于卷积层和自注意力机制的出水氨氮浓度测量方法,在步骤2中,所述卷积函数为,其中,是第l个卷积层的输出特征在位置,(i,j)为i=0……H-1,j=0……W-1 的值,所有的构成了一组形状为H×W×c的特征图,其中HW分别代表通道的高度和宽度,c代表通道数,表示激活函数,是第l层的卷积核中位置u,v的权重,,MN分别是卷积核的高度和宽度,为卷积核对应元素覆盖输入矩阵部分,覆盖面积为是第层的偏置项。In the above-mentioned method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism, in step 2, the convolution function is ,in, is the output feature of the lth convolutional layer at position, ( i,j ) is the value of i = 0... H -1, j = 0... W -1, all A set of feature maps with a shape of H × W × c is formed, where H and W represent the height and width of the channel respectively, and c represents the number of channels. represents the activation function, is the weight of position u,v in the convolution kernel of layer l , , M and N are the height and width of the convolution kernel respectively, The corresponding element of the convolution kernel covers the part of the input matrix, and the coverage area is , It is The bias term of the layer.

上述的基于卷积层和自注意力机制的出水氨氮浓度测量方法,所述步骤3包括:In the above-mentioned method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism, step 3 comprises:

步骤3-1:压缩,使用全局平均池化生成一个通道描述符,用来强调全局分布的空间信息:,其中在位置(i,j)的第c个通道的值,是压缩后的特征向量的第c个元素;Step 3-1: Compression, using global average pooling to generate a channel descriptor , used to emphasize the spatial information of the global distribution: ,in yes The value of the cth channel at position ( i,j ), is the cth element of the compressed feature vector;

步骤3-2:激励,通过一个压缩比率r来减少参数量和计算复杂度,然后通过激活函数和另一个全连接层来增加非线性,最后使用sigmoid函数生成每个通道的权重;Step 3-2: Excitation, using a compression ratio r to reduce the number of parameters and computational complexity, then adding nonlinearity through an activation function and another fully connected layer, and finally using a sigmoid function to generate the weight of each channel;

步骤3-3:将激励后得到的权重应用到原始输入特征图上,以执行通道的重标定。Step 3-3: Apply the weights obtained after excitation to the original input feature map to perform channel recalibration.

上述的基于卷积层和自注意力机制的出水氨氮浓度测量方法,所述步骤3-2包括:设定M 1M 2分别是两个全连接层的权重,,激励的输出的权重s, 为:,其中,是sigmoid函数,z是压缩步骤的输出; In the above-mentioned method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism, step 3-2 includes: setting M1 and M2 as weights of two fully connected layers respectively, , , the output weight s of the stimulus, for: ,in, is the sigmoid function, z is the output of the compression step;

所述步骤3-3包括:通道的重标定输出的计算公式为:,其中,是通道c 的权重,是原始输入特征图的通道c是重标定后的输出。The step 3-3 includes: the calculation formula of the recalibrated output of the channel is: ,in, is the weight of channel c , is the channel c of the original input feature map, is the output after recalibration.

上述的基于卷积层和自注意力机制的出水氨氮浓度测量方法,所述步骤4中,所述测量模型,其中W表示t时刻下连接输入x到输出门的权重矩阵,h为前一时间步的隐藏状态,b是偏置项,具体包括:In the above-mentioned method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism, in step 4, the measurement model , where W represents the weight matrix connecting the input x to the output gate at time t , h is the hidden state of the previous time step, and b is the bias term, which includes:

步骤4-1:通过卷积层处理输入数据以提取关键的空间特征,其中包括使用不同卷积核在连续的卷积层中逐步捕获数据的基础特征与复杂特征;Step 4-1: Process the input data through the convolution layer to extract key spatial features, which includes using different convolution kernels to gradually capture the basic features and complex features of the data in consecutive convolution layers;

步骤4-2:引入自注意力机制进一步处理卷积层的输出,通过全局平均池化、激励和重标定步骤对特征通道进行动态调整,以突出重要特征并抑制不重要的特征,有效降噪并增强模型的特征表达能力;Step 4-2: Introduce the self-attention mechanism to further process the output of the convolution layer, dynamically adjust the feature channels through global average pooling, excitation, and recalibration steps to highlight important features and suppress unimportant features, effectively reduce noise and enhance the feature expression ability of the model;

步骤4-3:将处理过的特征输入到LSTM中,利用其门结构来捕捉时间序列数据中的长期依赖性,从而实现对出水氨氮浓度的精准测量。Step 4-3: Input the processed features into LSTM and use its gate structure to capture the long-term dependencies in time series data, thereby achieving accurate measurement of effluent ammonia nitrogen concentration.

上述的基于卷积层和自注意力机制的出水氨氮浓度测量方法,在步骤5中,所述模型参数包括:LSTM层中的权重矩阵W、偏置项b以及神经元数CIn the above-mentioned method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism, in step 5, the model parameters include: the weight matrix W in the LSTM layer, the bias term b , and the number of neurons C.

上述的基于卷积层和自注意力机制的出水氨氮浓度测量方法,在步骤5中:所述自适应采样函数为:,其中i=1,2,3,D nxIn the above-mentioned method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism, in step 5: the adaptive sampling function is: , where i=1, 2, 3, D nx .

上述的基于卷积层和自注意力机制的出水氨氮浓度测量方法,所述步骤5中的优化策略包括:In the above-mentioned method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism, the optimization strategy in step 5 includes:

步骤5-1:在优化的早期阶段,关于目标函数的信息相对较少,此时使用更加注重探索的上置信界函数,以快速覆盖广阔的参数空间寻找潜在的有利区域,,其中,是在点处的目标函数的预测均值,是在点处的预测标准差,f是控制探索与利用平衡的参数;Step 5-1: In the early stages of optimization, there is relatively little information about the objective function. At this time, an upper confidence bound function that focuses more on exploration is used to quickly cover a wide range of parameter space to find potential favorable areas. ,in, It's on point The predicted mean of the objective function at , It's on point The prediction standard deviation at , f is the parameter that controls the balance between exploration and exploitation;

步骤5-2:当已经有目标函数部分信息时,使用期望改进函数,在探索未知区域和利用已知良好区域之间保持平衡,,其中,是当前已知最优参数所对应的输入向量,E代表期望值;Step 5-2: When partial information about the objective function is available, use the expected improvement function to maintain a balance between exploring unknown areas and exploiting known good areas. ,in, is the input vector corresponding to the currently known optimal parameters, and E represents the expected value;

步骤5-3:接近优化过程的尾声时,使用概率改进函数,在已发现的有前途区域内细致搜索,以精细调整找到真正的最优解,,其中,P是概率度量,z是控制探索强度的非负参数。Step 5-3: Towards the end of the optimization process, use the probability improvement function to carefully search in the promising area that has been discovered to fine-tune the true optimal solution. , where P is the probability measure and z is a non-negative parameter that controls the intensity of exploration.

本发明一种基于卷积层和自注意力机制的出水氨氮浓度测量方法的有益效果是:The beneficial effects of the method for measuring effluent ammonia nitrogen concentration based on a convolutional layer and a self-attention mechanism of the present invention are:

成本效益:通过使用集成卷积层和注意力机制的长短期记忆神经网络,降低了数据处理和出水氨氮浓度的检测成本,提高了经济效益。Cost-effectiveness: By using a long short-term memory neural network with integrated convolutional layers and attention mechanism, the cost of data processing and detection of effluent ammonia nitrogen concentration is reduced, and the economic benefit is improved.

噪声抑制:该网络结构能够有效地从复杂数据中提取特征,降低数据中的噪声干扰,提高了测量结果的准确性和可靠性。Noise suppression: This network structure can effectively extract features from complex data, reduce noise interference in the data, and improve the accuracy and reliability of the measurement results.

泛化能力:CS-LSTM模型具有较强的泛化能力,能够适应不同条件下的大规模城市污水处理数据,提高了模型的适应性和灵活性。Generalization ability: The CS-LSTM model has strong generalization ability and can adapt to large-scale urban sewage treatment data under different conditions, which improves the adaptability and flexibility of the model.

实时响应:模型能够实时响应处理条件的变化,提高了出水氨氮浓度的实时检测能力。Real-time response: The model can respond to changes in treatment conditions in real time, improving the real-time detection capability of effluent ammonia nitrogen concentration.

测量精度:改进的贝叶斯优化算法提高了模型的稳定性和准确性,从而提高了出水氨氮浓度的检测精度。Measurement accuracy: The improved Bayesian optimization algorithm improves the stability and accuracy of the model, thereby improving the detection accuracy of effluent ammonia nitrogen concentration.

与现有技术相比,本发明在成本、噪声抑制、泛化能力、实时响应和检测精度方面具有显著优势,为城市污水处理领域提供了更为高效和可靠的氨氮浓度测量方法。Compared with the existing technology, the present invention has significant advantages in cost, noise suppression, generalization ability, real-time response and detection accuracy, and provides a more efficient and reliable ammonia nitrogen concentration measurement method for the field of urban sewage treatment.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

图1为本发明测量方法流程图;Fig. 1 is a flow chart of the measuring method of the present invention;

图2为本发明测量模型网络结构图;FIG2 is a network structure diagram of a measurement model of the present invention;

图3为本发明测量出水氨氮浓度测量效果图。FIG. 3 is a diagram showing the effect of measuring the ammonia nitrogen concentration in effluent water according to the present invention.

具体实施方式Detailed ways

为使本领域技术人员更好的理解本发明的技术方案,下面结合具体实施方式及附图对本发明的技术方案进行说明。In order to enable those skilled in the art to better understand the technical solution of the present invention, the technical solution of the present invention is described below in conjunction with specific implementation methods and drawings.

实施例Example

如图1-2所示,一种基于卷积层和自注意力机制的出水氨氮浓度测量方法,包括以下步骤:As shown in Figure 1-2, a method for measuring effluent ammonia nitrogen concentration based on a convolutional layer and a self-attention mechanism includes the following steps:

步骤1:收集影响出水氨氮浓度的易测变量,构建易测变量样本数据集,易测变量包括好氧末段溶解氧、好氧末端总固体悬浮物、出水ph值、出水氧化还原电位、出水硝态氮,所述样本数据集为x= [x 1,x 2,...,x n],收集的出水氨氮浓度数据表示为Y= [y 1,...,y n],y i为第i个出水氨氮浓度点,n表示易测变量的样本数量。Step 1: Collect easily measurable variables that affect the effluent ammonia nitrogen concentration and construct a sample data set of easily measurable variables. The easily measurable variables include dissolved oxygen at the end of aerobic stage, total suspended solids at the end of aerobic stage, effluent pH value, effluent redox potential, and effluent nitrate nitrogen. The sample data set is x = [ x1 , x2 , ..., xn ]. The collected effluent ammonia nitrogen concentration data is expressed as Y = [ y1 , ..., yn ], where yi is the i - th effluent ammonia nitrogen concentration point, and n represents the number of samples of easily measurable variables.

步骤2:引用卷积函数构建卷积层,卷积函数为,其中,是第l(l=1,2)个卷积层的输出特征在位置,(i,j) (i=0……H-1,j=0……W-1) 的值,所有的构成了一组形状为H×W×c的特征图,其中HW分别代表通道的高度和宽度,c代表通道数,表示激活函数,是第l层的卷积核中位置u,v的权重,,MN分别是卷积核的高度和宽度,为卷积核对应元素覆盖输入矩阵部分,覆盖面积为是第层的偏置项。Step 2: Construct a convolution layer by referencing the convolution function. The convolution function is ,in, is the value of the output feature of the lth ( l = 1, 2) convolutional layer at position ( i, j ) ( i = 0... H -1, j = 0... W -1), all A set of feature maps with a shape of H × W × c is formed, where H and W represent the height and width of the channel respectively, and c represents the number of channels. represents the activation function, is the weight of position u,v in the convolution kernel of layer l , , M and N are the height and width of the convolution kernel respectively, The corresponding element of the convolution kernel covers the part of the input matrix, and the coverage area is , It is The bias term of the layer.

将易测变量代入卷积函数进行处理,得到数据特征,卷积函数对其输出数据应用一个非线性激活函数。Substitute the easily measurable variables into the convolution function for processing to obtain data features, and the convolution function applies a nonlinear activation function to its output data.

步骤3:设置自注意力机制函数,将卷积函数得到的数据特征输入到所述自注意力机制函数,自注意力机制函数通过学习不同通道之间的非线性关系对数据进行降噪,步骤3包括:Step 3: Setting a self-attention mechanism function, inputting the data features obtained by the convolution function into the self-attention mechanism function, and the self-attention mechanism function denoises the data by learning the nonlinear relationship between different channels. Step 3 includes:

步骤3-1:压缩,使用全局平均池化生成一个通道描述符z c,用来强调全局分布的空间信息:,其中x在位置(i,j)的第c个通道的值z c 是压缩后的特征向量的第c个元素。Step 3-1: Compression, use global average pooling to generate a channel descriptor z c to emphasize the spatial information of global distribution: ,in is the value of the cth channel of x at position ( i,j ) and z c is the cth element of the compressed feature vector.

步骤3-2:激励,通过一个压缩比率r来减少参数量和计算复杂度,然后通过激活函数和另一个全连接层来增加非线性,设定M 1M 2分别是两个全连接层的权重,M 1∈Rc×c/rM 2∈Rc/r×c,激励的输出的权重s,s∈Rc×1为:,其中,σ是sigmoid函数,z是压缩步骤的输出,最后使用sigmoid函数生成每个通道的权重。Step 3-2 : Excitation, reduce the number of parameters and computational complexity through a compression ratio r , and then increase nonlinearity through an activation function and another fully connected layer. Set M1 and M2 to be the weights of the two fully connected layers, M1∈Rc×c/r, M2∈Rc / r × c , and the weights s, s∈Rc ×1 of the output of the excitation are: , where σ is the sigmoid function, z is the output of the compression step, and finally the sigmoid function is used to generate the weights of each channel.

步骤3-3:将激励后得到的权重应用到原始输入特征图上,以执行通道的重标定,通道的重标定输出的计算公式为:,其中,s c 是通道c 的权重,x c 是原始输入特征图的通道c是重标定后的输出。Step 3-3: Apply the weights obtained after excitation to the original input feature map to perform channel recalibration. The calculation formula for the channel recalibration output is: , where s c is the weight of channel c , x c is the channel c of the original input feature map, is the output after recalibration.

步骤4:构建基于卷积函数和自注意力机制函数的长短期记忆神经网络模型,对步骤1-3收集的影响的因素进行建模,得到出水氨氮浓度的测量模型F(x),测量模型,其中W表示t时刻下连接输入x到输出门的权重矩阵,h为前一时间步的隐藏状态,b是偏置项,包括:Step 4: Construct a long short-term memory neural network model based on convolution function and self-attention mechanism function, model the influencing factors collected in steps 1-3, and obtain the measurement model F ( x ) of effluent ammonia nitrogen concentration. , where W represents the weight matrix connecting the input x to the output gate at time t , h is the hidden state of the previous time step, and b is the bias term, including:

步骤4-1:通过卷积层处理输入数据以提取关键的空间特征,其中包括使用不同卷积核在连续的卷积层中逐步捕获数据的基础特征和复杂特征。Step 4-1: Process the input data through the convolution layer to extract key spatial features, which includes using different convolution kernels to gradually capture the basic features and complex features of the data in consecutive convolution layers.

步骤4-2:引入自注意力机制进一步处理卷积层的输出,通过全局平均池化、激励和重标定步骤对特征通道进行动态调整,以突出重要特征并抑制不重要的特征,有效降噪并增强模型的特征表达能力。Step 4-2: Introduce the self-attention mechanism to further process the output of the convolutional layer, and dynamically adjust the feature channels through global average pooling, excitation, and recalibration steps to highlight important features and suppress unimportant features, effectively reduce noise and enhance the feature expression ability of the model.

步骤4-3:将处理过的特征输入到LSTM中,利用其专门设计的门结构来捕捉时间序列数据中的长期依赖性,从而实现对出水氨氮浓度的精准测量。Step 4-3: Input the processed features into LSTM, and use its specially designed gate structure to capture the long-term dependencies in time series data, thereby achieving accurate measurement of effluent ammonia nitrogen concentration.

步骤5:通过自适应贝叶斯优化策略,对测量模型F(x)的模型参数进行调节和优化,模型参数包括:LSTM层中的权重矩阵W、偏置项b以及神经元数CStep 5: Through the adaptive Bayesian optimization strategy, the model parameters of the measurement model F ( x ) are adjusted and optimized. The model parameters include: the weight matrix W in the LSTM layer, the bias term b , and the number of neurons C.

设定目标函数f(Θ p ),引入高斯过程作为起始的先验分布,依据观测数据,计算后验分布的均值与方差,并通过自适应采样函数来依据现有的观测数据动态调整,以确定下一步的观测点,获得最优检测模型Set the objective function f ( Θ p ), introduce the Gaussian process as the starting prior distribution, calculate the mean and variance of the posterior distribution based on the observed data, and dynamically adjust the existing observed data through the adaptive sampling function to determine the next observation point and obtain the optimal detection model .

自适应采样函数为:,其中i=1,2,3,D nxThe adaptive sampling function is: , where i=1, 2, 3, D nx .

优化策略包括:Optimization strategies include:

步骤5-1:在优化的早期阶段,关于目标函数的信息相对较少,此时使用更加注重探索的上置信界函数,以快速覆盖广阔的参数空间寻找潜在的有利区域,,其中,μ(Θ P )是在点Θ P 处的目标函数的预测均值,v(Θ P )是在点Θ P 处的预测标准差,f是控制探索与利用平衡的参数;Step 5-1: In the early stages of optimization, there is relatively little information about the objective function. At this time, an upper confidence bound function that focuses more on exploration is used to quickly cover a wide range of parameter space to find potential favorable areas. , where μ ( Θ P ) is the predicted mean of the objective function at point Θ P , v ( Θ P ) is the predicted standard deviation at point Θ P , and f is a parameter that controls the balance between exploration and exploitation;

步骤5-2:当已经有一定的目标函数信息时,使用期望改进函数,在探索未知区域和利用已知良好区域之间保持平衡,,其中,Θ P +是当前已知最优参数所对应的输入向量,E代表期望值;Step 5-2: When there is already some information about the objective function, use the expected improvement function to maintain a balance between exploring unknown areas and utilizing known good areas. , where Θ P + is the input vector corresponding to the currently known optimal parameters, and E represents the expected value;

步骤5-3:接近优化过程的尾声时,使用概率改进函数,在已发现的有前途区域内细致搜索,以精细调整找到真正的最优解,,其中,P是概率度量,z是控制探索强度的非负参数。Step 5-3: Towards the end of the optimization process, use the probability improvement function to carefully search in the promising area that has been discovered to fine-tune the true optimal solution. , where P is the probability measure and z is a non-negative parameter that controls the intensity of exploration.

步骤6:将获得的影响出水氨氮浓度的变量,输入到最优检测模型中,可获取最终出水氨氮浓度Step 6: Input the variables that affect the effluent ammonia nitrogen concentration into the optimal detection model The final effluent ammonia nitrogen concentration can be obtained .

实施例2Example 2

如图1-3所示,一种基于卷积层和自注意力机制的出水氨氮浓度测量方法,包括以下步骤。As shown in Figure 1-3, a method for measuring effluent ammonia nitrogen concentration based on convolutional layers and self-attention mechanism includes the following steps.

步骤1:收集影响出水氨氮浓度的易测变量(好氧末段溶解氧(DO) 、好氧末端总固体悬浮物(TSS) 、出水(pH) 、出水氧化还原电位(ORP)以及出水硝态氮(NO3-N)),将收集到的n个样本数据集用x= [x 1,x 2,...,x n]表示;同时,收集的出水氨氮浓度数据表示为Y=[y 1,...,y n],y i为第i个出水氨氮浓度点。Step 1: Collect easily measurable variables that affect the effluent ammonia nitrogen concentration (aerobic terminal dissolved oxygen (DO), aerobic terminal total suspended solids (TSS), effluent (pH), effluent oxidation-reduction potential (ORP), and effluent nitrate nitrogen (NO3-N)), and represent the collected n sample data sets as x = [ x1 , x2 , ..., xn ]; at the same time, the collected effluent ammonia nitrogen concentration data is represented as Y = [ y1 , ..., yn ] , where yi is the i -th effluent ammonia nitrogen concentration point.

步骤2:在引用卷积函数来构建卷积层后,收集到的数据首先通过第一卷积层进行处理,这一层利用多个卷积核捕捉数据的基本特征。随后,数据被传递到第二卷积层,这一层基于第一层提取的特征,进一步使用不同的卷积核来提取更加复杂的数据特征。在这一过程中,每个卷积层都会对其输出数据应用一个非线性激活函数,引入非线性以学习和表征更复杂的数据特征,从而有效提取对后续分析和检测至关重要的特征信息。Step 2: After referencing the convolution function to construct the convolution layer, the collected data is first processed by the first convolution layer, which uses multiple convolution kernels to capture the basic features of the data. Subsequently, the data is passed to the second convolution layer, which further uses different convolution kernels to extract more complex data features based on the features extracted by the first layer. In this process, each convolution layer applies a nonlinear activation function to its output data, introducing nonlinearity to learn and represent more complex data features, thereby effectively extracting feature information that is critical to subsequent analysis and detection.

本发明使用的两层卷积函数如下:The two-layer convolution function used in the present invention is as follows:

(1); (1);

其中,是第l(l=1,2)个卷积层的输出特征在位置 (i,j) (i=0……H-1,j=0……W-1) 的值,所有的构成了一组形状为H×W×c的特征图,其中HW分别代表通道的高度和宽度,c代表通道数。δ是RELU激活函数,具体表述为 ,用于将输入信号转换为输出信号,以便在网络中引入非线性特性,使得网络能够学习复杂的特征。是第l层的卷积核中位置u,v的权重,,MN分别是卷积核的高度和宽度,为卷积核对应元素覆盖输入矩阵部分,覆盖面积为是第层的偏置项,增加了网络的灵活性。in, is the value of the output feature of the lth ( l = 1, 2) convolutional layer at position ( i, j ) ( i = 0... H -1, j = 0... W -1), all It forms a set of feature maps with a shape of H × W × c , where H and W represent the height and width of the channel respectively, and c represents the number of channels. δ is the RELU activation function, which is specifically expressed as , which is used to convert the input signal into the output signal in order to introduce nonlinear characteristics into the network so that the network can learn complex features. is the weight of position u,v in the convolution kernel of layer l , , M and N are the height and width of the convolution kernel respectively, The corresponding element of the convolution kernel covers the part of the input matrix, and the coverage area is , It is The bias term of the layer increases the flexibility of the network.

步骤3:在接收到卷积层的输入后,本发明使用SE层对数据进行降噪。SE层通过学习不同通道之间的非线性关系,能够有效增强模型对于重要特征的表达能力,同时抑制不重要的特征,提高模型的准确性和泛化能力。Step 3: After receiving the input of the convolutional layer, the present invention uses the SE layer to reduce noise on the data. The SE layer can effectively enhance the model's ability to express important features by learning the nonlinear relationship between different channels, while suppressing unimportant features, thereby improving the accuracy and generalization ability of the model.

具体来说,首先进行压缩,使用全局平均池化生成一个通道描述符z c,用来强调全局分布的空间信息:Specifically, compression is first performed, and a channel descriptor z c is generated using global average pooling to emphasize the spatial information of global distribution:

(2); (2);

其中 x 在位置 (i,j) 的第c 个通道的值,z c 是压缩后的特征向量的第c个元素。in is the value of the cth channel of x at position ( i,j ), and z c is the cth element of the compressed feature vector.

然后进行激励,通过一个压缩比率r来减少参数量和计算复杂度,然后通过ReLU激活函数和另一个全连接层来增加非线性,最后使用sigmoid函数生成每个通道的权重。假设M 1M 2分别是两个全连接层的权重(M 1∈Rc×c/rM 2∈Rc/r×c),那么激励的输出s(s∈Rc×1)为:Then the excitation is performed, and the number of parameters and computational complexity are reduced by a compression ratio r , and then the nonlinearity is increased by the ReLU activation function and another fully connected layer, and finally the sigmoid function is used to generate the weight of each channel. Assuming that M1 and M2 are the weights of the two fully connected layers ( M1∈Rc ×c/r , M2∈Rc /r×c ), the output s ( s∈Rc ×1 ) of the excitation is:

(3); (3);

其中,σ是sigmoid函数,z是压缩步骤的输出。Here, σ is the sigmoid function and z is the output of the compression step.

最后,将激励后得到的权重s 应用到原始输入特征图 上,以执行通道的重标定。对于每个通道,其重标定的输出 可以通过以下公式计算:Finally, the weight s obtained after excitation is applied to the original input feature map to perform channel recalibration. For each channel, its recalibrated output can be calculated by the following formula:

(4); (4);

其中,s c 是通道c 的权重,x c 是原始输入特征图的通道c是重标定后的输出。Among them, s c is the weight of channel c , x c is the channel c of the original input feature map, is the output after recalibration.

经过上述步骤处理后的数据,能够有效降噪从而提高模型精度,并为后续LSTM层的检测提供了更为精确的数据。The data processed by the above steps can effectively reduce noise to improve the accuracy of the model and provide more accurate data for the subsequent LSTM layer detection.

再对输入数据进行特征提取处理后,通过SE层对卷积层提取的特征进行降噪。此过程首先应用全局平均池化以生成通道描述符,概括每个通道的全局分布信息。随后,通过一个压缩比率r减少参数量,再通过ReLU激活函数和全连接层引入非线性,最终使用sigmoid函数为每个通道生成调整权重。这些权重被应用于原始特征图,实现对特征通道的动态调整,优先处理更为重要的特征,从而提升了模型对数据的理解和处理能力,尤其在处理复杂或噪声较多的数据集时,能够有效提高模型的准确性和泛化性能。After feature extraction of the input data, the features extracted by the convolutional layer are denoised through the SE layer. This process first applies global average pooling to generate channel descriptors to summarize the global distribution information of each channel. Subsequently, the number of parameters is reduced through a compression ratio r , and nonlinearity is introduced through the ReLU activation function and the fully connected layer. Finally, the sigmoid function is used to generate adjustment weights for each channel. These weights are applied to the original feature map to achieve dynamic adjustment of feature channels and prioritize more important features, thereby improving the model's understanding and processing capabilities of the data, especially when processing complex or noisy data sets, which can effectively improve the accuracy and generalization performance of the model.

步骤4:采用基于CS-LSTM方法对步骤1-3收集的影响出水氨氮浓度的变量数据进行建模,得到出水氨氮浓度的测量模型,其中W表示t时刻下连接输入x到输出门的权重矩阵,h为前一时间步的隐藏状态,b是偏置项;具体为:Step 4: Use the CS-LSTM method to model the variable data affecting the effluent ammonia nitrogen concentration collected in steps 1-3 to obtain the measurement model of the effluent ammonia nitrogen concentration. , where W represents the weight matrix connecting the input x to the output gate at time t , h is the hidden state of the previous time step, and b is the bias term; specifically:

首先,通过卷积层处理输入数据以提取关键的空间特征,其中包括使用不同卷积核在连续的卷积层中逐步捕获数据的基础特征和复杂特征,基础特征用数据的基本关联性表示,复杂特征用数据的线性关系表示,基本关联性代表变量间的依赖性或相互作用程度,数据的线性关系表示变量之间的直接比例关系,数据的基本关联性和数据的线性关系为现有技术。First, the input data is processed through a convolutional layer to extract key spatial features, which includes using different convolution kernels to gradually capture the basic features and complex features of the data in consecutive convolutional layers. The basic features are represented by the basic correlation of the data, and the complex features are represented by the linear relationship of the data. The basic correlation represents the degree of dependence or interaction between variables, and the linear relationship of the data represents the direct proportional relationship between variables. The basic correlation of the data and the linear relationship of the data are existing technologies.

接着,引入SE注意力机制进一步处理卷积层的输出,通过全局平均池化、激励和重标定步骤对特征通道进行动态调整,以突出重要特征并抑制不重要的特征,有效降噪并增强模型的特征表达能力。Next, the SE attention mechanism is introduced to further process the output of the convolutional layer. The feature channels are dynamically adjusted through global average pooling, excitation, and recalibration steps to highlight important features and suppress unimportant features, effectively reducing noise and enhancing the feature expression ability of the model.

最后,将处理过的特征输入到LSTM中,利用其专门设计的门结构来捕捉时间序列数据中的长期依赖性,从而实现对出水氨氮浓度的精准测量。Finally, the processed features are input into LSTM, and its specially designed gate structure is used to capture the long-term dependencies in time series data, thereby achieving accurate measurement of effluent ammonia nitrogen concentration.

步骤5:通过自适应贝叶斯优化策略,实现对模型参数的精确调节和优化,涉及LSTM层中的权重矩阵W、偏置项b以及神经元数C。初始步骤包括目标函数f(Θ p )的设定,随后引入高斯过程(GP)作为起始的先验分布,这一过程涵盖了均值函数和核函数的定义,用于描绘不同参数设置之间的相关性。依据观测数据,计算后验分布的均值与方差,并通过如下自适应采样函数来依据现有的观测数据动态调整,以确定下一步的观测点,采集函数根据优化阶段的不同可采用上置信界(UCB)、期望改进(EI)或概率改进(PI)等策略。Step 5: Through the adaptive Bayesian optimization strategy, the model parameters are precisely adjusted and optimized, involving the weight matrix W , the bias term b , and the number of neurons C in the LSTM layer. The initial step includes the setting of the objective function f ( Θ p ), followed by the introduction of the Gaussian process (GP) as the starting prior distribution. This process covers the definition of the mean function and the kernel function to depict the correlation between different parameter settings. Based on the observed data, the mean and variance of the posterior distribution are calculated, and the following adaptive sampling function is used to dynamically adjust the existing observed data to determine the next observation point. The sampling function can adopt strategies such as upper confidence bound (UCB), expected improvement (EI) or probability improvement (PI) according to the different optimization stages.

迭代过程,不断更新后验分布,并确定能最大化采集函数值的参数点,直到满足终止条件。The iterative process continuously updates the posterior distribution and determines the parameter point that maximizes the acquisition function value until the termination condition is met.

自适应采集函数如下:The adaptive acquisition function is as follows:

(6); (6);

其中i=1,2,3。D nx,具体优化策略如下:Where i = 1, 2, 3. D nx , the specific optimization strategy is as follows:

(1) 在优化的早期阶段,关于目标函数的信息相对较少,此时使用更加注重探索的上置信界(UCB)函数,以快速覆盖广阔的参数空间寻找潜在的有利区域。(1) In the early stages of optimization, there is relatively little information about the objective function. At this time, an upper confidence bound (UCB) function that focuses more on exploration is used to quickly cover a wide range of parameter space to find potential favorable areas.

(7); (7);

其中,μ(Θ P )是在点Θ P 处的目标函数的预测均值,v(Θ P )是在点Θ P 处的预测标准差,f是控制探索与利用平衡的参数(为常数)。Where μ ( ΘP ) is the predicted mean of the objective function at point ΘP , v ( ΘP ) is the predicted standard deviation at point ΘP , and f is a parameter (a constant) that controls the balance between exploration and exploitation.

(2) 当已经有一定的目标函数信息时,使用期望改进函数,期望改进函数能够较好地在探索未知区域和利用已知良好区域之间平衡。(2) When there is certain objective function information, the expected improvement function is used. The expected improvement function can better balance between exploring unknown areas and utilizing known good areas.

(8); (8);

其中,Θ P +是当前已知最优参数所对应的输入向量。Among them, Θ P + is the input vector corresponding to the currently known optimal parameters.

(3) 接近优化过程的尾声时,使用概率改进函数,在已发现的有前途区域内细致搜索,以精细调整找到真正的最优解。(3) Towards the end of the optimization process, a probability improvement function is used to conduct a detailed search in the discovered promising regions to fine-tune the true optimal solution.

(9); (9);

其中,P是概率度量,z是控制探索强度的非负参数。Where P is the probability measure and z is a non-negative parameter that controls the intensity of exploration.

在迭代过程中,持续更新后验分布,寻找最大化采样函数值的参数点,直到达到预定的终止标准。此种算法通过对模型参数进行细致的调整,显著增强了模型的效能,从而实现模型性能的最大化,获得最优检测模型In the iterative process, the posterior distribution is continuously updated to find the parameter point that maximizes the sampling function value until the predetermined termination criterion is reached. This algorithm significantly enhances the effectiveness of the model by carefully adjusting the model parameters, thereby maximizing the model performance and obtaining the optimal detection model. .

具体的,如图2所示本项发明构建了一个CS-LSTM模型,用于检测出水氨氮浓度。初始阶段,利用卷积层对输入数据进行处理,提取出数据的空间维度特征。通过卷积核,卷积层逐步提取了数据中从基础到复杂的特征。随后,通过融入SE机制对卷积层的输出进行深入处理。该机制经由全局平均池化、激活及再标定等步骤,动态地调节特征通道的权重,强化关键特征而抑制次要特征,从而有效地降低噪声并提升了模型对特征的解读能力。最终,将经过筛选和优化的特征传递至LSTM网络,该网络借助其独有的门控机制,抓取时间序列数据中的长期依赖关系,实现对出水氨氮浓度的精确检测。在图2中,①为lstm遗忘门公式,具体表述为,②为lstm输入门公式,具体表述为,③为lstm更新细胞状态,具体表述为,④为lstm输出门公式,具体表述为,⑤和⑥均为卷积函数公式,具体表述为,Ⅰ是SE层折叠后的输出为x t,Ⅱ是,Ⅲ是c t-1,Ⅳ是c t,Ⅴ是h t, Ⅵ、Ⅶ、Ⅸ分别为f t、 i t、 o t, Ⅷ为g t,其中,x t 是一个二维向量,(x t∈Rm×1)为t时刻的输入;是一个二维向量,为前一时间步的隐藏状态;c t-1是一个二维向量,为t-1时刻细胞状态;c t是一个二维向量,为t时刻细胞状态;h t 是一个二维向量,(h t ∈Rm×1)为t时刻的隐藏状态;f t、 i t 、 o t 分别为遗忘门、输入门以及输出门在t时刻的输出;g tt时刻细胞状态的候选值;W f W OW i W C (W∈Rm×m)分别表示t时刻下连接输入x t 到不同门的权重矩阵,b f b i b C b O (b∈Rm×1)为偏置项,σ为sigmoid激活函数。激活函数的作用均为引入非线性。Specifically, as shown in FIG2, the present invention constructs a CS-LSTM model for detecting the ammonia nitrogen concentration in effluent water. In the initial stage, the convolution layer is used to process the input data to extract the spatial dimension characteristics of the data. Through the convolution kernel, the convolution layer gradually extracts the basic to complex features in the data. Subsequently, the output of the convolution layer is deeply processed by integrating the SE mechanism. This mechanism dynamically adjusts the weights of feature channels through steps such as global average pooling, activation, and recalibration, strengthens key features and suppresses secondary features, thereby effectively reducing noise and improving the model's ability to interpret features. Finally, the screened and optimized features are passed to the LSTM network, which uses its unique gating mechanism to capture long-term dependencies in time series data and achieve accurate detection of effluent ammonia nitrogen concentrations. In FIG2, ① is the LSTM forget gate formula, which is specifically expressed as ,② is the LSTM input gate formula, specifically expressed as , ③ is the lstm updating cell state, which is specifically expressed as , ④ is the LSTM output gate formula, which is specifically expressed as , ⑤ and ⑥ are convolution function formulas, specifically expressed as , Ⅰ is the output of SE layer after folding, which is x t, Ⅱ is , III is c t-1, IV is c t, V is h t, VI, VII, IX are f t, i t, o t respectively, VIII is g t, where x t is a two-dimensional vector, ( x t ∈R m×1 ) is the input at time t; is a two-dimensional vector, which is the hidden state of the previous time step; c t-1 is a two-dimensional vector, which is the cell state at time t -1; c t is a two-dimensional vector, which is the cell state at time t ; h t is a two-dimensional vector, ( h t ∈R m×1 ) is the hidden state at time t; f t, i t, o t are the outputs of the forget gate, input gate and output gate at time t respectively; g t is the candidate value of the cell state at time t ; W f , W O , W i , W C ( W ∈R m×m ) respectively represent the weight matrices connecting the input x t to different gates at time t , b f , bi , b C , b O ( b ∈R m×1 ) are bias terms, and σ is the sigmoid activation function. The role of the activation function is to introduce nonlinearity.

步骤6:将获得的影响出水氨氮浓度的变量,输入到确定的检测模型中,可获取出水氨氮浓度Step 6: Input the variables that affect the effluent ammonia nitrogen concentration into the determined detection model to obtain the effluent ammonia nitrogen concentration. .

为了评估本发明模型的性能,这里采用均方根误差(RMSE)和相关系数(R2)作为评价指标,计算公式分别为:In order to evaluate the performance of the model of the present invention, the root mean square error (RMSE) and the correlation coefficient (R 2 ) are used as evaluation indicators, and the calculation formulas are:

(10); (10);

(11); (11);

其中为y i为测试集中第i个样本真实测量值,为测试集样本的检测值,是检测样本的均值。Where yi is the true measurement value of the i -th sample in the test set, is the detection value of the test set sample, is the mean of the test samples.

表一:不同算法对比结果表Table 1: Comparison results of different algorithms

.

表一为不同算法对比结果表,在对比多种模型的性能,包括FNN、LSTM和ELM模型后,通过深入分析RMSE和R2这两个关键的统计指标,本发明展现出显著的优势。具体来说,本发明在RMSE上远低于其他模型,说明我们的检测结果与真实数据之间的差异较小,检测精度高。同时,该模型的R2接近1,指出模型能够精准挖掘数据间的内在关系,拟合程度高。这些指标表明,我们的方法不仅能提提高测量精度,还能把握数据的复杂动态,本发明对提高出水氨氮浓度检测的准确性具有重要的意义。Table 1 is a table of comparison results of different algorithms. After comparing the performance of multiple models, including FNN, LSTM and ELM models, the present invention shows significant advantages through in-depth analysis of the two key statistical indicators of RMSE and R 2. Specifically, the RMSE of the present invention is much lower than that of other models, indicating that the difference between our test results and the real data is small and the detection accuracy is high. At the same time, the R 2 of the model is close to 1, indicating that the model can accurately mine the intrinsic relationship between the data and has a high degree of fit. These indicators show that our method can not only improve the measurement accuracy, but also grasp the complex dynamics of the data. The present invention is of great significance to improving the accuracy of effluent ammonia nitrogen concentration detection.

上述实施例只是为了说明本发明的发明构思和特点,其目的在于让本领域内的普通技术人员能够了解本发明的内容并据以实施,并不能以此限定本发明的保护范围。凡是根据本发明内容的实质所做出的等效变化或修饰,都应该涵盖在本发明的保护范围之内。The above embodiments are only for illustrating the inventive concept and features of the present invention, and their purpose is to enable those skilled in the art to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the protection scope of the present invention. Any equivalent changes or modifications made based on the essence of the content of the present invention should be included in the protection scope of the present invention.

Claims (9)

1. The method for measuring the ammonia nitrogen concentration of the effluent based on the convolution layer and the self-attention mechanism is characterized by comprising the following steps of:
Step 1: collecting easily-measured variables influencing the ammonia nitrogen concentration of the effluent, and constructing an easily-measured variable sample data set;
Step 2: constructing a convolution layer by referring to the convolution function, substituting the easily-measured variable into the convolution function for processing to obtain data characteristics, and applying a nonlinear activation function to output data of the convolution function by the convolution function;
Step 3: setting a self-attention mechanism function, inputting the data characteristics obtained by the convolution function into the self-attention mechanism function, and carrying out noise reduction on the data by the self-attention mechanism function through learning nonlinear relations among different channels;
Step 4: constructing a long-term and short-term memory neural network model based on a convolution function and a self-attention mechanism function, modeling the factors of the influence collected in the steps 1-3, and obtaining a measurement model of the ammonia nitrogen concentration of the effluent
Step 5: by self-adaptive Bayesian optimization strategy, the measurement model is subjected toModel parameters of (a) are adjusted, optimized and an objective function is setIntroducing Gaussian process as initial prior distribution, calculating average value and variance of posterior distribution according to observed data, dynamically adjusting according to existing observed data by self-adaptive sampling function to determine next observation point, and obtaining optimal detection model
Step 6: inputting the obtained variable influencing the ammonia nitrogen concentration of the effluent into an optimal detection modelIn the process, the ammonia nitrogen concentration of the final effluent can be obtained
2. The method for measuring the ammonia nitrogen concentration of effluent based on a convolution layer and a self-attention mechanism according to claim 1, wherein the method comprises the following steps: in the step1, the easily-measured variables comprise aerobic end dissolved oxygen, aerobic end total solid suspended matters, effluent pH value, effluent oxidation-reduction potential and effluent nitrate nitrogen, and the sample data set isThe collected effluent ammonia nitrogen concentration data is expressed asAnd n represents the sample number of the easily-measured variable for the ith effluent ammonia nitrogen concentration point.
3. The method for measuring the ammonia nitrogen concentration of effluent based on a convolution layer and a self-attention mechanism according to claim 2, wherein the method comprises the following steps: in step 2, the convolution function isWherein, the method comprises the steps of, wherein,Is the output characteristic of the first convolutional layer at position, (i, j) is a value of i= … … H-1, j= … … W-1, allA set of feature maps of the shape H x W x c is constructed, where H and W represent the height and width of the channel, respectively, c represents the number of channels,The activation function is represented as a function of the activation,Is the weight of the position u, v in the convolution kernel of the first layer,M and N are the height and width of the convolution kernel, respectively,Covering the input matrix part for the corresponding elements of the convolution kernel with a coverage area ofIs the firstBias terms of the layers.
4. The method for measuring ammonia nitrogen concentration in effluent based on a convolution layer and a self-attention mechanism according to claim 3, wherein said step 3 comprises:
Step 3-1: compression, generating a channel descriptor using global averaging pooling Spatial information used to emphasize global distribution: Wherein Is thatThe value of the c-th channel at position (i, j),Is the c-th element of the compressed feature vector;
Step 3-2: excitation, reducing the parameter quantity and the calculation complexity through a compression ratio r, then increasing nonlinearity through an activation function and another full-connection layer, and finally generating the weight of each channel by using a sigmoid function;
Step 3-3: the weights obtained after excitation are applied to the original input feature map to perform channel recalibration.
5. The method for measuring ammonia nitrogen concentration of effluent based on a convolution layer and a self-attention mechanism according to claim 4, wherein said step 3-2 comprises: setting M 1 and M 2 as weights of two fully connected layers respectively,The weight s of the output of the stimulus,The method comprises the following steps: Wherein, the method comprises the steps of, wherein, Is a sigmoid function, z is the output of the compression step;
the step 3-3 comprises the following steps: the calculation formula of the recalibration output of the channel is as follows: Wherein, the method comprises the steps of, wherein, Is the weight of the channel c and,Is the channel c of the original input feature map,Is output after recalibration.
6. The method for measuring ammonia nitrogen concentration in effluent based on a convolution layer and self-attention mechanism as set forth in claim 5, wherein in said step 4, said measuring modelWherein W represents a weight matrix connecting an input x to an output gate at a time t, h is a hidden state of a previous time step, and b is a bias term, and the method specifically includes:
Step 4-1: processing the input data through the convolution layers to extract key spatial features, including progressively capturing basic and complex features of the data in successive convolution layers using different convolution kernels;
Step 4-2: introducing a self-attention mechanism to further process the output of the convolution layer, dynamically adjusting the characteristic channel through the steps of global average pooling, excitation and recalibration to highlight important characteristics and inhibit unimportant characteristics, effectively reducing noise and enhancing the characteristic expression capability of the model;
step 4-3: the processed characteristics are input into the LSTM, and the gate structure is utilized to capture the long-term dependence in the time series data, so that the accurate measurement of the ammonia nitrogen concentration of the effluent is realized.
7. The method for measuring ammonia nitrogen concentration in effluent based on a convolution layer and self-attention mechanism according to claim 6, wherein in step 5, the model parameters include: the weight matrix W, bias term b and neuron number C in LSTM layer.
8. The method for measuring the ammonia nitrogen concentration of effluent based on a convolution layer and a self-attention mechanism according to claim 7, wherein in step 5: the adaptive sampling function is: Where i=1, 2,3, d n e x.
9. The method for measuring ammonia nitrogen concentration in effluent based on a convolution layer and self-attention mechanism according to claim 8, wherein the optimizing strategy in step 5 comprises:
Step 5-1: at an early stage of the optimization, relatively little information is available about the objective function, at which time the upper confidence function that is more focused on exploration is used, to quickly cover a wide parameter space to find potentially advantageous regions, Wherein, the method comprises the steps of, wherein,Is at the point ofThe predicted mean value of the objective function at that point,Is at the point ofThe prediction standard deviation of the position, f, is a parameter for controlling exploration and utilization balance;
step 5-2: when there is already partial information of the objective function, a balance is maintained between exploring unknown regions and utilizing known good regions using the desired improvement function, Wherein, the method comprises the steps of, wherein,Is the input vector corresponding to the current known optimal parameter, E represents the expected value;
step 5-3: near the end of the optimization process, a probability improvement function is used to search carefully within the found promising areas, to fine tune to find the true optimal solution, Where P is a probability metric and z is a non-negative parameter that controls the strength of the exploration.
CN202410658265.4A 2024-05-27 2024-05-27 A method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism Active CN118228766B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410658265.4A CN118228766B (en) 2024-05-27 2024-05-27 A method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410658265.4A CN118228766B (en) 2024-05-27 2024-05-27 A method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism

Publications (2)

Publication Number Publication Date
CN118228766A CN118228766A (en) 2024-06-21
CN118228766B true CN118228766B (en) 2024-07-23

Family

ID=91506358

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410658265.4A Active CN118228766B (en) 2024-05-27 2024-05-27 A method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism

Country Status (1)

Country Link
CN (1) CN118228766B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119400288A (en) * 2025-01-06 2025-02-07 江西师范大学 Total nitrogen prediction method for sewage treatment based on convolutional temporal self-attention mechanism
CN120144969B (en) * 2025-05-14 2025-07-18 青岛理工大学 A method for measuring effluent ammonia nitrogen concentration based on neural network and Bayesian optimization

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113029993A (en) * 2021-03-24 2021-06-25 中南大学 Ultraviolet spectrum rapid total nitrogen online detection method based on attention mechanism
CN116579233A (en) * 2023-04-14 2023-08-11 太原科技大学 Method for predicting residual life of mechanical equipment

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8135653B2 (en) * 2007-11-20 2012-03-13 Hitachi, Ltd. Power plant control device which uses a model, a learning signal, a correction signal, and a manipulation signal
US20230162023A1 (en) * 2021-11-25 2023-05-25 Mitsubishi Electric Research Laboratories, Inc. System and Method for Automated Transfer Learning with Domain Disentanglement

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113029993A (en) * 2021-03-24 2021-06-25 中南大学 Ultraviolet spectrum rapid total nitrogen online detection method based on attention mechanism
CN116579233A (en) * 2023-04-14 2023-08-11 太原科技大学 Method for predicting residual life of mechanical equipment

Also Published As

Publication number Publication date
CN118228766A (en) 2024-06-21

Similar Documents

Publication Publication Date Title
CN118228766B (en) A method for measuring effluent ammonia nitrogen concentration based on convolutional layer and self-attention mechanism
US10570024B2 (en) Method for effluent total nitrogen-based on a recurrent self-organizing RBF neural network
CN111291937A (en) Method for predicting quality of treated sewage based on combination of support vector classification and GRU neural network
CN112183719A (en) Intelligent detection method for total nitrogen in effluent based on multi-objective optimization-fuzzy neural network
CN108898215A (en) A kind of sludge bulking INTELLIGENT IDENTIFICATION method based on two type fuzzy neural networks
CN105510546A (en) Intelligent biochemical oxygen demand (BOD) detection method based on self-organizing recursion radial basis function (RBF) neural network
CN113077039B (en) Soft measurement method for total nitrogen TN of effluent based on task-driven RBF neural network
CN110542748B (en) A knowledge-based robust effluent ammonia nitrogen soft-sensing method
CN112819087B (en) Method for detecting abnormality of BOD sensor of outlet water based on modularized neural network
CN112989704B (en) IRFM-CMNN effluent BOD concentration prediction method based on DE algorithm
CN108595892A (en) Soft-measuring modeling method based on time difference model
CN114580266A (en) Land-source pollutant intelligent comprehensive evaluation method and system
CN119644755B (en) Inverse fuzzy dynamic optimal self-adaptive aeration control method based on sewage treatment
CN116306803A (en) Method for predicting BOD concentration of outlet water of ILSTM (biological information collection flow) neural network based on WSFA-AFE
CN116307255A (en) Water body eutrophication prediction method based on improved MIMO depth double 3Q learning
CN112765902A (en) RBF neural network soft measurement modeling method based on TentFWA-GD and application thereof
CN109408896A (en) A kind of anerobic sowage processing gas production multi-element intelligent method for real-time monitoring
CN117493803A (en) Sewage treatment process effluent quality prediction method based on recursive RBF neural network
CN115951025B (en) Inversion method for total phosphorus concentration of water body
Li et al. Modular stochastic configuration network with attention mechanism for soft measurement of water quality parameters in wastewater treatment processes
CN114565143A (en) Effluent BOD concentration prediction method based on PSLSTM neural network
CN120144969B (en) A method for measuring effluent ammonia nitrogen concentration based on neural network and Bayesian optimization
CN120745711A (en) Flue Gas Desulfurization System State Prediction Method Based on Adaptive Radial Basis Function Neural Network
CN120736670A (en) Intelligent fecal sewage treatment system and method
CN120430518A (en) A method for online monitoring of product quality in solid waste resource utilization process

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant