Real-time feedback and adaptive learning method for natural gas infrared spectrum measurement

By employing real-time feedback and adaptive learning methods, a dynamic analysis model is constructed, which solves the adaptability problem of natural gas infrared spectroscopy measurement in complex environments, achieving high-precision and fast-response natural gas detection, applicable to scenarios with various gas sources and component ratios.

CN121011285APending Publication Date: 2025-11-25SOUTHWEST PETROLEUM UNIV
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202511131428.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-13
Publication Date
2025-11-25

AI Technical Summary

Technical Problem

Existing infrared spectroscopy measurement methods for natural gas lack dynamic response capabilities in complex environments and cannot autonomously adjust model parameters, resulting in large errors and decreased accuracy. They are particularly unsuitable for dynamic monitoring of natural gas pipeline leaks and gas stations.

Method used

Employing a real-time feedback and adaptive learning approach, this method acquires spectral information using an infrared spectrometer, constructs a historical sample set, combines an extreme gradient boosting model and Bayesian optimization to build a decision-making process, sets a similarity measurement threshold, constructs local and global dynamic analysis models, and introduces a real-time feedback module to dynamically adjust model parameters, thereby achieving adaptive learning.

Benefits of technology

It achieves high-precision natural gas detection in complex environments, meets the requirements for rapid response, reduces human intervention, is applicable to different gas sources and component ratios, and improves the system's stability and anti-interference capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121011285A_ABST
    Figure CN121011285A_ABST
Patent Text Reader

Abstract

The invention relates to the field of gas concentration detection, and particularly discloses a real-time feedback and adaptive learning method for natural gas infrared spectrum measurement, which comprises the following steps: S1, acquiring infrared spectrum information of a natural gas body by using an infrared spectrometer, and constructing a historical sample set; s2, preprocessing the spectral data of the historical sample set; s3, selecting an optimal algorithm and a hyper-parameter by adopting XGBoost and Bayesian optimization; s4, constructing a qualitative model to identify gas types and match data; s5, calculating the similarity between a field sample and a historical sample through a Siamese network, and setting a threshold value to screen local data; s6, improving the KNN to construct a local dynamic quantitative model to predict the concentration; s7, processing low-similarity abnormal data by the global dynamic model, and improving the reliability by combining moving average and abnormal calibration; and S8, introducing reinforcement learning and online gradient descent to adjust parameters in real time to optimize the precision. According to the technical scheme, high-accuracy natural gas detection can be carried out in a complex environment.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of gas concentration detection, in particular to a real-time feedback and adaptive learning method for natural gas infrared spectrum measurement. BACKGROUND

[0002] Natural gas, as an important low-carbon and clean energy, plays a key role in energy structure transformation and sustainable economic development. The accurate measurement of its composition and concentration is a core link for safety and efficiency guarantee in the whole process of production, transportation and use. Currently, natural gas detection technologies mainly include traditional laboratory analysis methods and on-site rapid detection technologies, but both have significant limitations in practical applications.

[0003] Gas chromatography, as the mainstream method of traditional laboratory analysis, can achieve high-precision component analysis, but requires regular maintenance of equipment, complex operation process, long analysis period and high cost, which makes it difficult to meet the needs of real-time monitoring and rapid response scenarios, especially in on-site applications such as natural gas pipeline leakage and gas station dynamic monitoring.

[0004] Infrared spectroscopy technology, with its ability to accurately identify specific infrared absorption characteristics of gas molecules, has become an important technical direction for on-site rapid detection. However, traditional infrared spectrum measurement methods rely on pre-set fixed models and lack dynamic response capability to complex environmental changes such as temperature fluctuations, pressure changes and interference gas mixing. When the measurement conditions deviate from the model training scenario, significant errors may occur, and the model parameters cannot be adjusted autonomously to compensate for environmental influences.

[0005] In particular, static models trained offline are unable to dynamically update model parameters or optimize algorithm configurations based on real-time data. When encountering new data with significant differences from historical samples (such as new mixed gases or abnormal concentration samples), the model's generalization ability is insufficient, leading to misjudgments or decreased accuracy.

[0006] Therefore, there is an urgent need for a real-time feedback and adaptive learning method for natural gas infrared spectrum measurement with high accuracy in complex environments. SUMMARY

[0007] The present application provides a real-time feedback and adaptive learning method for natural gas infrared spectrum measurement, which can still have high accuracy in complex environments to complete the detection of natural gas.

[0008] To solve the above technical problems, the present application provides the following technical solutions: The real-time feedback and adaptive learning method for natural gas infrared spectrum measurement comprises the following steps: Step S1: Use an infrared spectrometer to obtain infrared spectrum information of natural gas, and construct a historical sample set; Step S2: Preprocessing the spectral data of the historical sample set; Step S3: Building a decision-making process through an extreme gradient boosting model and Bayesian optimization to select the optimal algorithm and corresponding hyperparameter configuration from a defined set of algorithms to minimize the loss function; Step S4: Based on the preprocessed spectral data of step S2 and the optimal qualitative analysis algorithm and hyperparameters determined in step S3, a qualitative analysis model is constructed to identify the type of natural gas, and a data set matching the identification result is selected from the historical sample set; Step S5: Setting a critical value for similarity measurement according to the requirements of dynamic modeling, and comparing the on-site collected data with the historical sample data obtained in step S4 to measure the similarity; Step S6: Based on the local similar samples obtained in step S5, a local dynamic quantitative analysis model is constructed using an improved K-nearest neighbor algorithm to predict the concentration of natural gas in the on-site sample to be tested; Step S7: A global dynamic analysis model is constructed to preliminarily predict the concentration of natural gas in the on-site sample to be tested using the global average concentration of the historical data set, and to determine whether it is an abnormal sample by calculating the difference between the predicted value and the historical data concentration and calibrating it, and outputting the calibrated concentration value as the final prediction result; Step S8: Introducing a real-time feedback and adaptive learning module to continuously collect spectral data and store them as time series data, real-time monitor data quality and model prediction performance, and dynamically adjust model parameters and hyperparameters through deep reinforcement learning and online gradient descent algorithm when data quality is below a threshold or model performance decreases, to optimize prediction performance.

[0009] The basic scheme principle and beneficial effects are as follows: The method realizes accurate measurement of natural gas infrared spectrum in complex environment by constructing a closed-loop system of data acquisition, preprocessing, model optimization, dynamic prediction, and real-time feedback. The infrared spectrum information of natural gas is collected by an infrared spectrometer, and a historical sample set containing single-component, multi-component mixed gas, and corresponding labels is constructed to provide data basis for subsequent model training and dynamic matching. The original spectral data is preprocessed to eliminate noise, outliers, and other interference, ensuring the data quality of the input model and providing reliable input for subsequent analysis. The strong learning ability of the extreme gradient boosting (XGBoost) model and the efficient optimization characteristics of the Bayesian optimization are combined to automatically select the optimal algorithm and hyperparameters from the algorithm set that adapt to the current scene, avoiding the subjectivity and limitations of manual selection and ensuring the optimal initial performance of the model.

[0010] The qualitative analysis model identifies the type of gas on site, filters the same gas data from the historical sample set, reduces irrelevant data interference, and improves the relevance of subsequent analysis. By setting a similarity threshold, comparing the on-site data with the filtered historical data, and accurately positioning the high-similarity samples, a higher-adaptability training data is provided for the local model. For high-similarity samples, an improved K-nearest neighbor algorithm is used to construct a local dynamic model, and the weighted features of similar samples are used to achieve fine-grained prediction of concentration, which is suitable for conventional and stable measurement scenarios.

[0011] For on-site data with low similarity or abnormality to historical data, the global model uses statistical features of historical data (such as global average concentration) for preliminary prediction, and calibrates abnormal values to ensure the rationality of prediction in extreme or unknown scenarios. Through the real-time feedback module, the data quality and model performance are monitored, and the model parameters and hyperparameters are dynamically adjusted by combining deep reinforcement learning and online gradient descent algorithm, so that the system can adapt to environmental changes (such as temperature fluctuations and gas component mutations) autonomously, forming a closed loop of monitoring, feedback, and optimization.

[0012] This method effectively eliminates the influence of noise, interfering gases, and environmental fluctuations through multi-level data purification (preprocessing), directional data filtering (qualitative analysis and similarity matching), and dual-model collaborative prediction (local and global). Even in scenarios with complex natural gas components (multi-component mixing) and unstable measurement conditions (such as instrument drift), the method can still maintain high accuracy in concentration prediction, solving the problem of poor generalization of traditional fixed models.

[0013] With the efficient optimization mechanism of Bayesian optimization, the selection time of algorithms and hyperparameters is significantly shortened; the prediction path of the local model for similar samples is more concise, and the global model serves as a fallback solution for abnormal scenarios. The overall process does not require human intervention and can achieve millisecond-level response, meeting the rapid response requirements of real-time monitoring and leakage warning of natural gas pipelines.

[0014] The real-time feedback and adaptive learning module (step S8) enables the system to evolve autonomously. When the data quality decreases (such as a decrease in signal-to-noise ratio) or the model performance deteriorates, the system adjusts the strategy (such as switching algorithms) through deep reinforcement learning and fine-tunes the parameters in real time using online gradient descent, without the need to retrain the entire model to adapt to the new environment, significantly improving the stability and anti-interference ability of the system in long-term operation.

[0015] From algorithm selection, model optimization to abnormal handling, the entire process is highly automated, reducing the workload of manual calibration and parameter tuning. For example, there is no need for professionals to manually select adaptive algorithms or correct abnormal values, reducing the operation threshold and maintenance cost, especially suitable for remote gas fields, unattended sites, and other scenarios.

[0016] The local model is adapted to a regular stable scene, and the global model covers an abnormal or unknown scene. In combination with an adaptive learning mechanism, the method can be applicable to different gas sources (such as shale gas and conventional natural gas), different component proportions (single component to multi-component), and different measurement environments (such as high temperature, high humidity, and containing interfering gases), and breaks through the dependence of traditional methods on specific scenes.

[0017] The historical sample set continuously participates in model optimization through dynamic matching (step S5) and incremental learning (step S8), and new data acquisition continuously enriches the sample library, so that the recognition ability of the system for rare gas components and new mixed proportions is gradually improved, and long-term data value mining is realized.

[0018] In summary, through the cooperative mechanism of precise modeling, dynamic adaptation, and autonomous optimization, the method realizes high precision, high stability, and high adaptability of natural gas infrared spectrum measurement in a complex environment, and provides an efficient and reliable technical solution for the field of energy monitoring and safety warning.

[0019] Further, the infrared spectrum information of the natural gas is obtained by using an experimental device in the step S1, and the obtained spectrum data is regarded as a historical sample set; the historical sample set includes: single-component natural gas, multi-component mixed natural gas, category label and concentration label.

[0020] Further, the preprocessing includes noise reduction processing by using a segmented multivariate scatter correction method, and abnormal value elimination by using a Mahalanobis distance method, wherein the Mahalanobis distance method calculates the Mahalanobis distance of the sample based on the feature vector of the sample point, the mean vector and the covariance matrix of the data set, and determines whether it is an abnormal sample according to a threshold value based on the chi-square distribution.

[0021] Further, the data preprocessing mode in the S2 is a segmented multivariate scatter correction and abnormal data elimination, and a gas infrared absorption spectrum preprocessing mode; including the following steps: The infrared spectrum data set of the natural gas of the experiment is divided into a spectrum data training set and a spectrum data test set according to a certain proportion, and the original spectrum data is subjected to noise reduction processing by using a segmented scatter correction method; and for the possible abnormal data in the data set, the Mahalanobis distance method is used to detect abnormal samples after the noise reduction; the process is based on the formula , x is the feature vector of the sample point, and μ is the mean vector of the data set. After calculating the Mahalanobis distance of each sample, a threshold value based on the chi-square distribution is set. If the Mahalanobis distance of the sample point exceeds the threshold value, it is considered to be an abnormal sample and is eliminated.

[0022] Further, the decision-making process in the S3 utilizes an extreme gradient boosting model and a Bayesian optimization technique to find the optimal strategy, including the following steps: Define an algorithm set where element A ( i ) represents an algorithm and its corresponding hyperparameter space. The optimal combination of algorithm and hyperparameters is sought to minimize the loss function ; Combining the XGBoost model and the Bayesian optimization algorithm, the decision-making process first uses the XGBoost model to preliminarily evaluate each algorithm in the algorithm set, and then uses the Bayesian optimization algorithm to find the optimal configuration in the hyperparameter space of these algorithms. In each iteration, the prediction results of the XGBoost model are used to update the surrogate model of Bayesian optimization, and the acquisition function EI is used to determine the next evaluation point, where the acquisition function is used to balance exploration and utilization, guiding the search for the optimal parameters. In this way, the search range can be effectively reduced, and the best algorithm and hyperparameter combination can be quickly found, thus realizing the optimal strategy in the qualitative analysis and quantitative analysis stages; The optimization objective of the XGBoost model can be represented as:

[0023] where is the model prediction value, is the true value, is the regularization term, is the prediction function of the k th decision tree, is the corresponding hyperparameter; The key to Bayesian optimization is to build an accurate surrogate model and an effective acquisition function; the surrogate model is usually a Gaussian process, whose mean and variance are determined by historical data points:

[0024] where f ( x ) is the predicted mean of the surrogate model, k ( x , x ) is the kernel function, k ( x ) is the kernel function vector, K is the kernel matrix, is the noise variance; The acquisition function EI is used to determine the next evaluation point, which measures the improvement that the new point may bring under the current best value x :

[0025] To calculate EI, the posterior distribution of needs to be sampled, and by maximizing EI, the next evaluation point is determinedx The point is expected to provide the maximum improvement; the process is iterated until a stop condition is met, which is a maximum number of iterations or a time limit.

[0026] Further, the S4 establishes a qualitative analysis model for identifying natural gas species, which can identify specific natural gas from the sample and select historical data sets matching the qualitative analysis results according to the identification results; the qualitative analysis process includes the following steps: Using the natural gas experimental data preprocessed in S2 step and the optimal qualitative analysis algorithm and hyperparameter setting determined in S3 step, a model for qualitative analysis of natural gas is constructed; The trained qualitative analysis model is applied to process the collected measurement data to obtain the qualitative classification results of natural gas; According to the qualitative analysis results, the gas category historical data set matching the results is selected from the data set arranged in S2 step.

[0027] Further, the S5 sets the similarity measure threshold according to the requirements of dynamic modeling, and measures the similarity between the data measured on site and the historical sample data obtained in S4 step according to the comparison principle, which includes the following steps: Construct a Siamese network, which consists of two identical subnetworks that share the same parameters, and each subnetwork receives a sample as input and outputs the feature representation of the sample. Define a contrastive loss function to optimize network parameters, so that the feature representations of similar samples are closer, and the feature representations of dissimilar samples are farther apart; train the Siamese network using a large number of paired samples, including positive sample pairs and negative sample pairs, positive sample pairs from the same category, and negative sample pairs from different categories; For the samples to be measured on site and in the historical sample set, calculate their feature representations through the trained Siamese network, and calculate the Euclidean distance between the two feature representations; Set a similarity threshold to judge the similarity between the to-be-measured sample and the historical sample according to the size of the Euclidean distance; if the Euclidean distance is less than the similarity threshold, the to-be-measured sample is considered similar to the historical sample; From the historical sample set, select samples similar to the to-be-measured sample for subsequent construction of a local dynamic analysis model.

[0028] Further, the S6 constructs a local dynamic quantitative analysis model, which combines an improved K-nearest neighbor algorithm to predict the concentration of natural gas in the to-be-measured sample on site, which includes the following steps: The local similar sample data set screened out in the S5 step is taken as input, and the samples have high similarity with the on-site to-be-tested samples in spectral characteristics; the local similar sample data set is divided into a training set and a validation set; the training set is used for model training, and the validation set is used for evaluating the performance of the model; For each historical sample in the training set , the similarity between it and the on-site to-be-tested sample is calculated by the Euclidean distance method. According to the similarity, a weight is assigned to each sample; According to the calculated weight, the K samples with the largest weight are selected as the nearest neighbor samples; the value of K can be dynamically adjusted according to the performance on the validation set to achieve the best prediction effect; the gas concentration of the on-site to-be-tested sample is predicted by weighted average using the selected K nearest neighbor samples and their weights; subsequently, the performance of the model is evaluated on the validation set, and the mean square error and the coefficient of determination on the validation set are calculated; according to the performance on the validation set, the value of K and the parameters in the weight calculation formula are dynamically adjusted to optimize the prediction accuracy; In the local dynamic modeling stage, according to the above process, the optimal algorithm and hyperparameters obtained in step S3 are used to construct a local dynamic analysis model to obtain the gas concentration of the to-be-tested sample.

[0029] Further, the S7 global dynamic analysis model is constructed to predict the concentration of natural gas, and to process the on-site to-be-tested data that is not suitable for analysis by the local model due to low similarity with historical samples or being considered as abnormal, in addition, the process also includes combining an abnormal detection mechanism to calibrate suspected abnormal samples to improve the accuracy of subsequent analysis and verification, and the global dynamic modeling analysis process includes the following steps: The preprocessed and screened historical data set obtained from steps S1-S6 includes natural gas spectral data and its corresponding concentration label, and a global average concentration value is obtained by performing simple moving average calculation on the concentration label in the historical data set. The similarity of the on-site to-be-tested data is evaluated to determine its similarity with the historical data; if the similarity of the on-site to-be-tested data with the historical data is lower than a set threshold, it is considered that the data is not suitable for analysis by the local model, and enters the global dynamic analysis process; The concentration of the on-site to-be-tested data is preliminarily predicted, assuming that its concentration is the global average concentration , the difference between the concentration prediction value of the on-site to-be-tested data and the concentration of the historical data is calculated, and the calculation formula is:

[0030] If Δ yIf the concentration value exceeds the set abnormal threshold, the sample is considered to be a suspected abnormal sample. The suspected abnormal sample is calibrated: according to the concentration distribution range of the historical data, the concentration prediction value of the abnormal sample is adjusted to a reasonable range; For on-site data to be measured similar to the historical samples or abnormal, directly use the calibrated concentration value as the final prediction result. For other data, still use the global average concentration As the prediction value.

[0031] Further, the real-time feedback and adaptive learning module is introduced in the step S8, the data quality and the prediction performance of the model are detected in real time, the reinforcement learning algorithm is combined, the parameters are automatically adjusted according to the real-time feedback, and the prediction performance is optimized. Real-time feedback and adaptive learning include the following steps: The natural gas infrared spectrum data on site is continuously collected and compared with the historical data, the quality of the collected data is evaluated in real time, including signal-to-noise ratio, data integrity, and abnormal value proportion index, and the prediction performance of the model is monitored, to ensure the accuracy and stability of the model on real-time data; When the data quality is lower than the preset threshold or the model performance decreases significantly, an alarm is triggered, the data collection is automatically suspended, and manual intervention or re-collection is waited for; In the adaptive learning process, first, the reinforcement learning algorithm is used to automatically adjust the model parameters according to the real-time feedback to optimize the prediction performance, at the same time, the online learning algorithm is used to enable the model to learn new data features in real time without retraining the entire model; in combination with the incremental learning algorithm, the historical data set is dynamically updated to ensure the timeliness and accuracy of the data; in this process, the hyperparameters are dynamically adjusted according to the real-time feedback to adapt to different environmental conditions and data changes. BRIEF DESCRIPTION OF DRAWINGS

[0032] Figure 1 The logic block diagram of the real-time feedback and adaptive learning method for natural gas infrared spectrum measurement. DETAILED DESCRIPTION

[0033] The following is further described in detail through specific embodiments: The real-time feedback and adaptive learning method for natural gas infrared spectrum measurement (as shown in Figure 1 includes the following steps: Step S1: using an infrared spectrometer to obtain infrared spectrum information of natural gas, and constructing a historical sample set; Step S2: preprocessing the spectrum data of the historical sample set; Step S3: constructing a decision-making process through an extreme gradient boosting model and a Bayesian optimization to select the optimal algorithm and the corresponding hyperparameter configuration from a defined algorithm set to minimize the loss function; Step S4: Based on the pre-processed spectral data in step S2 and the optimal qualitative analysis algorithm and hyperparameters determined in step S3, a qualitative analysis model is constructed, which is used to identify the type of natural gas, and the data set matching the identification result is screened out from the historical sample set; Step S5: According to the requirement of dynamic modeling, the critical value of similarity measurement is set, and the similarity between the on-site collected data and the historical sample data obtained in step S4 is measured by comparison principle; Step S6: According to the local similar samples obtained in step S5, a local dynamic quantitative analysis model is constructed by combining the improved K-nearest neighbor algorithm, which is used to predict the concentration of natural gas in the on-site sample to be measured; Step S7: A global dynamic analysis model is constructed, which is used to preliminarily predict the on-site data with low similarity or abnormality to the historical samples by using the global average concentration of the historical data set, to judge whether it is an abnormal sample by calculating the difference between the predicted value and the historical data concentration, and to output the calibrated concentration value as the final prediction result; Step S8: Introduce real-time feedback and adaptive learning module, continuously collect spectral data and store as time series data, real-time monitor data quality and model prediction performance, when data quality is lower than threshold or model performance is decreased, dynamically adjust model parameters and hyperparameters through deep reinforcement learning and online gradient descent algorithm, optimize prediction performance.

[0034] In step S1, the infrared spectrum information of natural gas is obtained by using experimental equipment, and the obtained spectral data is regarded as a historical sample set; the historical sample set includes: single-component natural gas, multi-component mixed natural gas, category label and concentration label.

[0035] In specific use, different concentrations of gas are configured by using Environics Series 4000 high-precision gas mixing system, spectral data is collected by using Bruker ALPHA II Fourier transform infrared spectrometer, and an experimental data set is established. The data set includes single-component gases such as methane, ethane, propane, n-butane and isobutane and their mixed gases. Among them, the mixed gas includes 10 kinds of mixed gas of 2 components, 3 components, 4 components and 5 components, a total of 15 types of gas. The sampling interval of spectral data is about 1 cm-1, and each spectral data collected has 4000 sampling points, corresponding to the spectral absorption intensity value of beam point. The spectral data of each sample includes category label (gas type) and concentration label (gas concentration).

[0036] The preprocessing includes noise reduction processing by using piecewise multivariate scatter correction method, and removing outliers by using Mahalanobis distance method, wherein the Mahalanobis distance method calculates the Mahalanobis distance of the sample based on a feature vector of the sample point, a mean vector and a covariance matrix of the data set, and determines whether it is an abnormal sample according to a threshold value determined based on chi-square distribution.

[0037] The data preprocessing mode in S2 is piecewise multivariate scatter correction and outlier removal, and the gas infrared absorption spectrum preprocessing mode; including the following steps: The natural gas infrared spectrum data set of the experiment is divided into a spectrum data training set and a spectrum data test set according to a certain proportion, and the original spectrum data is subjected to noise reduction processing by using piecewise scatter correction method; and for the possible abnormal data in the data set, the Mahalanobis distance method is used to detect abnormal samples after the noise reduction of the data; the process is based on the formula , x is the feature vector of the sample point, and μ is the mean vector of the data set. After calculating the Mahalanobis distance of each sample, a threshold value determined based on chi-square distribution is set. If the Mahalanobis distance of the sample point exceeds the threshold value, it is considered to be an abnormal sample and is removed.

[0038] In specific use: the natural gas infrared spectrum data set of the experiment is divided into a spectrum data training set and a spectrum data test set according to a certain proportion, and the original spectrum data is subjected to noise reduction processing by using piecewise scatter correction method: The original spectrum data is subjected to piecewise processing, and each piece of spectrum data is corrected separately, and the correction process is as follows: For each piece of spectrum data, the average spectrum is calculated as the reference spectrum, and the average of all sample spectrum data in the training set is obtained as the reference spectrum, and the calculation formula of the average spectrum is:

[0039] Among them, is the spectrum data of the i-th sample, N is the number of samples in the training set, is the average spectrum.

[0040] After the average spectrum is calculated, linear regression fitting is performed with each sample spectrum data The form of the linear regression model is:

[0041] Among them, is the regression coefficient, indicating the proportional relationship between the sample spectrum and the average spectrum, is the intercept, indicating the baseline offset of the sample spectrum, is the residual error, indicating the fitting error. As for the regression coefficient and the intercept in the model, the partial least squares method is used to solve, and the least squares method is used to solve and To minimize the sum of squared residuals, the formula for the sum of squared residuals using least squares is as follows:

[0042] in, It is the first i The sample at the th j Absorption intensity at each wavelength is the absorption intensity of the average spectrum at the j-th wavelength, and m is the number of wavelengths.

[0043] Solving for the regression coefficients and intercept, i.e., finding and To minimize S, for each S with respect to... and Find the derivative and set it to zero, that is... and Next, the partial derivative equations are rearranged into normal equations, and finally the normal equations are solved. ,in Matrix A and vector B are respectively:

[0044]

[0045] After obtaining and Spectral correction is performed on the spectral data of each sample using the following formula:

[0046] in, It is the raw spectral data. This is the corrected spectral data. Through correction, baseline drift and scattering effects in the spectral data are eliminated, while retaining effective spectral information.

[0047] After denoising the original spectral data, anomaly detection is performed on the denoised data using the Mahalanobis distance method. The Mahalanobis distance formula is as follows:

[0048] in, x Here, is the feature vector of the sample point, and μ is the mean vector of the dataset. After calculating the Mahalanobis distance for each sample, a threshold determined based on the chi-square distribution is set. If the Mahalanobis distance of a sample point exceeds the threshold, it is considered an outlier and is removed.

[0049] The decision-making process in S3 utilizes extreme gradient boosting models and Bayesian optimization techniques to find the optimal strategy, including the following steps: Definition of algorithm set , where element A ( i ) represents an algorithm and its corresponding hyperparameter space. The optimal combination of algorithm and hyperparameters is sought to minimize the loss function ; Combining the XGBoost model and the Bayesian optimization algorithm, the decision-making process first uses the XGBoost model to preliminarily evaluate each algorithm in the algorithm set, and then uses the Bayesian optimization algorithm to find the optimal configuration in the hyperparameter space of these algorithms. In each iteration, the prediction results of the XGBoost model are used to update the surrogate model of Bayesian optimization, and the acquisition function EI is used to determine the next evaluation point, where the acquisition function is used to balance exploration and utilization, guiding the search for optimal parameters. In this way, the search range can be effectively reduced, and the best algorithm and hyperparameter combination can be quickly found, thus realizing the optimal strategy in the qualitative analysis and quantitative analysis stages; The optimization objective of the XGBoost model can be represented as:

[0050] where is the model prediction value, yi is the true value, is the regularization term, fk is the prediction function of the k th decision tree, γk is the corresponding hyperparameter; The key to Bayesian optimization lies in building an accurate surrogate model and an effective acquisition function; the surrogate model is usually a Gaussian process, whose mean and variance are determined by historical data points:

[0051] where f ( x ) is the predicted mean of the surrogate model, k ( x , x ) is the kernel function, k ( x ) is the kernel function vector, K is the kernel matrix, is the noise variance; The acquisition function EI is used to determine the next evaluation point, which measures the improvement that the new point f may bring under the current best value x ( x ):

[0052] To calculate EI, it is necessary to calculate f ​x ) to determine the next evaluation point by maximizing the expected improvement (EI) x , which is expected to provide the most improvement; the process iterates until a stopping condition is met, which is either a maximum number of iterations or a time limit.

[0053] In specific use, define a set of algorithms , where element A( i ) represents an algorithm and its corresponding hyperparameter space i The goal is to find the optimal combination of algorithm and hyperparameters to minimize the loss function . During this process, the XGBoost model and Bayesian optimization algorithm will work together to improve search efficiency and accuracy.

[0054] Combining the XGBoost model and Bayesian optimization algorithm, the decision-making process first uses the XGBoost model to perform preliminary evaluation on each algorithm in the algorithm set. In the preliminary evaluation stage, the XGBoost model will train and validate each algorithm in the algorithm set.

[0055] First, select an algorithm A( n ) from the algorithm set and set its initial hyperparameter configuration θ i . Then, perform XGBoost model training.

[0056] The XGBoost model is trained by building multiple decision trees. Each decision tree attempts to correct the prediction error of the previous tree, and the final prediction result is obtained by weighted sum of the prediction results of all trees.

[0057] During training, the XGBoost model minimizes the loss function , where is the true value, is the model prediction value.

[0058] To prevent overfitting, the XGBoost model introduces a regularization term that limits the complexity of the model to improve its generalization ability. During training, the XGBoost model will gradually optimize the model parameters through the gradient boosting algorithm until it reaches the predetermined number of iterations or the loss function converges.

[0059] After the model training is completed, the model is evaluated using the validation set. The validation set is a part of the historical sample set that does not participate in training, used to evaluate the model's performance on unseen data. The model's performance is evaluated by calculating the loss function value f(x) on the validation set. The smaller the loss function value, the better the model's prediction effect.

[0060] To evaluate the performance of a model more accurately, cross-validation is usually used. Cross-validation divides the dataset into K subsets, and each subset is used as the validation set in turn while the remaining subsets are used as the training set. The average of K validation results is taken as the performance indicator of the model.

[0061] Bayesian optimization algorithm is used to find the optimal configuration in the hyperparameter space of these algorithms. Before starting the Bayesian optimization, some initial sampling is performed in the hyperparameter space to obtain some initial hyperparameter combinations and their corresponding performance evaluation results.

[0062] Bayesian optimization uses Gaussian process as a surrogate model to approximate the loss function. Gaussian process can predict the function value of the unknown region according to the existing sampling points and provide the uncertainty of the prediction.

[0063] In each iteration, the Bayesian optimization algorithm updates the Gaussian process surrogate model according to the existing sampling points. The mean and variance of the surrogate model are determined by the historical data points, and the formula is:

[0064] where, μ ( x ) is the mean function, k ( x , x ’) is the kernel function, which measures the similarity between different points.

[0065] Then the Bayesian optimization uses the acquisition function EI to select the next evaluation point. EI measures the improvement that the new point f ( x ) can bring under the current best value x . The calculation formula of EI is:

[0066] where, f ( x ) is the current best observation, f ( x ) is the predicted function value of the surrogate model.

[0067] By maximizing the acquisition function, the Bayesian optimization algorithm selects the next most promising hyperparameter combination for evaluation. This point is usually an area with both high predicted value and high uncertainty. After selecting the next hyperparameter combination, the model is trained using this combination, and its performance is evaluated on the validation set. This evaluation result is added to the historical data for updating the surrogate model.

[0068] The Bayesian optimization process will be iterated until a maximum number of iterations is met, an improvement in the loss function is less than a certain threshold, and the computation time or resource is exhausted.

[0069] Finally, after the optimization process is completed, the Bayesian optimization algorithm outputs the optimal configuration found in the hyperparameter space. In this way, the search range can be effectively narrowed down, and the best algorithm and hyperparameter combination can be quickly found, thereby achieving the optimal strategy in the qualitative analysis and quantitative analysis stages.

[0070] In the specific implementation of S4, the natural gas experimental data preprocessed in S2 and the optimal qualitative analysis algorithm and hyperparameter setting determined in S3 are used to construct a model for qualitative analysis of natural gas. The model is used to identify specific natural gas from the sample and select historical data sets matching the qualitative analysis results according to the identification results. The trained qualitative analysis model is applied to process the collected measurement data to obtain the qualitative classification results of the natural gas. According to the qualitative analysis results, the gas category historical data set matching the results is selected from the data set arranged in S2.

[0071] In S5, the threshold of similarity measurement is set according to the requirements of dynamic modeling, and the similarity measurement is performed on the data measured on site and the historical sample data obtained in S4 according to the comparison principle. The process includes the following steps: A Siamese network is constructed, which consists of two identical sub-networks that share the same parameters. Each sub-network receives a sample as input and outputs a feature representation of the sample. A contrastive loss function is defined to optimize the network parameters so that the feature representations of similar samples are closer and the feature representations of dissimilar samples are farther apart. A large number of paired samples, including positive sample pairs and negative sample pairs, are used to train the Siamese network, where the positive sample pairs are from the same category and the negative sample pairs are from different categories; For the sample to be measured on site and the samples in the historical sample set, the feature representations of the two samples are calculated by the trained Siamese network, and the Euclidean distance between the two feature representations is calculated; A similarity threshold is set, and the similarity between the sample to be measured and the historical sample is determined according to the size of the Euclidean distance. If the Euclidean distance is less than the similarity threshold, the sample to be measured is considered similar to the historical sample; Similar samples are selected from the historical sample set for subsequent construction of the local dynamic analysis model.

[0072] In specific use, the threshold of similarity measurement is set according to the requirements of dynamic modeling, and the similarity measurement is performed on the data measured on site and the historical sample data obtained in S4 according to the comparison principle.

[0073] A Siamese network architecture is constructed, which includes two identical subnetworks that share the same network parameters. The structure of each subnetwork is as follows: Input layer: receives pre-processed natural gas infrared spectrum data, with a data dimension of n where n is the number of wavelength points of the spectrum data.

[0074] Convolutional layer: extracts local features of the input data. Each convolutional layer contains multiple convolutional kernels with a kernel size of k , a stride of s , and a padding mode of "same" to maintain the consistency of the output size and the input size. The activation function of the convolutional layer uses the ReLU function.

[0075] Pooling layer: after each convolutional layer, a max-pooling layer is used to reduce the feature dimension, with a pooling window size of p and a stride of p .

[0076] Fully connected layer: at least one fully connected layer is used to map the extracted features to a low-dimensional feature space. The output dimension of the fully connected layer is d , and the activation function uses the ReLU function.

[0077] where d is the dimension of the feature space.

[0078] Output layer: outputs the feature representation of the sample, with a dimension of d .

[0079] The Siamese network receives two input samples x 1 and x 2, and calculates their feature representations f ( x 1) and f ( x 2) through two subnetworks, respectively.

[0080] The two subnetworks share the same parameters, ensuring the same feature extraction operation on the two input samples.

[0081] Define a contrastive loss function to optimize the parameters of the Siamese network, so that the feature representations of similar samples are closer, and the feature representations of dissimilar samples are farther apart. The contrastive loss function is defined as:

[0082] where y is the label of whether the two samples are similar, y =1 indicates similarity, y =0 indicates dissimilarity.

[0083] d is the Euclidean distance between two feature representations, and the calculation formula is:

[0084] wherein, m is a preset positive threshold value representing the minimum distance between dissimilar samples.

[0085] Prepare a large number of paired sample data, each pair of samples including two samples x1 and x2 , and their similarity label y .

[0086] wherein, positive sample pair: sample pair from the same category, label y =1. Negative sample pair: sample pair from different categories, label y =0.

[0087] Train the Siamese network using Adam.

[0088] In each iteration, a batch of paired samples is randomly extracted from the training data set, and the contrast loss function L is calculated.

[0089] Update the network parameters through the backpropagation algorithm to minimize the loss function L.

[0090] Repeat the above process until the network converges or reaches the preset number of training rounds.

[0091] For the on-site collected sample to be tested and the sample in the historical sample set , calculate their feature representations and respectively through the trained Siamese network.

[0092] Calculate the Euclidean distance between the two feature representations d , and the calculation formula is:

[0093] Set the similarity threshold θ, if d <θ, then the sample to be tested is considered similar to the historical sample; otherwise, they are considered dissimilar.

[0094] Filter out the similar samples from the historical sample set to the sample to be tested, which are used for the construction of the subsequent local dynamic quantitative analysis model.

[0095] In S6, a local dynamic quantitative analysis model is constructed, combined with the improved K-nearest neighbor algorithm, which is used to predict the natural gas concentration of the on-site sample to be tested. The process includes the following steps: The local similar sample dataset screened in step S5 is taken as input, and the samples have high similarity with the on-site sample to be measured in spectral characteristics; the local similar sample dataset is divided into a training set and a validation set; the training set is used for model training, and the validation set is used for evaluating model performance; For each historical sample in the training set , the similarity between it and the on-site sample to be measured xtest is calculated by the Euclidean distance method. Each sample is assigned a weight according to the similarity; According to the calculated weight, the K samples with the largest weight are selected as the nearest neighbor samples; the value of K can be dynamically adjusted according to the performance on the validation set to achieve the best prediction effect; the gas concentration of the on-site sample to be measured is predicted by weighted average using the selected K nearest neighbor samples and their weights; then, the model performance is evaluated on the validation set, and the mean square error and the coefficient of determination on the validation set are calculated; according to the performance on the validation set, the value of K and the parameters in the weight calculation formula are dynamically adjusted to optimize the prediction accuracy; In the local dynamic modeling stage, according to the above process, the local dynamic analysis model for obtaining the gas concentration of the sample to be measured is constructed based on the optimal algorithm and hyperparameters obtained in step S3.

[0096] In specific use, a local dynamic quantitative analysis model for real-time measurement of natural gas concentration is constructed, which is used to predict the natural gas concentration of the on-site sample to be measured by combining the improved K nearest neighbor algorithm.

[0097] The local similar sample dataset screened in step S5 is taken as input, and the local similar sample dataset is divided into a training set and a validation set. The training set is used for model training, and the validation set is used for evaluating model performance.

[0098] For each historical sample in the training set , the similarity between it and the on-site sample to be measured is calculated by the Euclidean distance method. Each sample is assigned a weight according to the similarity;

[0099] wherein, xi,j and xtest,j are the values of the i-th historical sample and the sample to be measured at the j-th spectral feature point, i is the feature dimension of the spectral data. j n Each sample is assigned a weight according to the similarity, and the calculation formula is as follows:

[0100]

[0101] ​​where e is a small constant to avoid division by zero.

[0102] According to the calculated weights wi , the K samples with the largest weights are selected as the nearest neighbor samples. The value of K can be dynamically adjusted according to the performance on the validation set to achieve the best prediction effect.

[0103] Using the selected K nearest neighbor samples and their weights, the gas concentration of the on-site sample to be tested is weighted and averaged to predict. The calculation formula is as follows:

[0104] where, yi is the concentration label of the i th nearest neighbor sample, is the predicted concentration of the sample to be tested.

[0105] Evaluate the model performance on the validation set, calculate the mean square error (MSE) and the coefficient of determination (R2) on the validation set According to the performance on the validation set, dynamically adjust the value of K and the parameter e in the weight calculation formula to optimize the prediction accuracy.

[0106] According to the above process, based on the optimal algorithm and hyperparameters obtained in step S3, a local dynamic analysis model is constructed to obtain the gas concentration of the sample to be tested.

[0107] In S7, a global dynamic analysis model is constructed to predict the concentration of natural gas, and to process on-site test data that is not suitable for analysis by the local model due to low similarity to historical samples or is considered abnormal. In addition, this process also includes combining an anomaly detection mechanism to calibrate suspected abnormal samples to improve the accuracy of subsequent analysis and verification. The global dynamic modeling and analysis process includes the following steps: From steps S1-S6, obtain the preprocessed and screened historical data set, including natural gas spectrum data and its corresponding concentration label. Calculate the simple moving average of the concentration label in the historical data set to obtain a global average concentration value . Evaluate the similarity of the on-site test data to the historical data to determine its similarity. If the similarity of the on-site test data to the historical data is lower than the set threshold, it is considered that the data is not suitable for analysis by the local model, and enters the global dynamic analysis process. Make a preliminary prediction of the concentration of the on-site test data, assuming that its concentration is the global average concentration Calculate the difference between the predicted concentration value of the on-site test data and the concentration of the historical data. The calculation formula is as follows:

[0108] If Δy If the difference Δ exceeds the set abnormal threshold, the sample is considered as a suspected abnormal sample. The suspected abnormal sample is calibrated: according to the concentration distribution range of the historical data, the concentration prediction value of the abnormal sample is adjusted to a reasonable range; For the on-site data to be measured similar to the historical sample or abnormal, the calibrated concentration value is directly used as the final prediction result. For other data, the global average concentration is still used as the prediction value.

[0109] Specific use: obtain the preprocessed and screened historical data set from S1-S6 steps, including natural gas spectrum data and its corresponding concentration label, calculate the concentration label in the historical data set by simple moving average to obtain a global average concentration value The calculation formula is as follows:

[0110] Wherein, N is the number of samples in the historical data set, is the concentration label of the i sample.

[0111] The similarity of the on-site data to be measured is evaluated, and the similarity of the on-site data to be measured with the historical data is judged. If the similarity of the on-site data to be measured with the historical data is lower than the set threshold, it is considered that the data is not suitable for local model analysis, and enters the global dynamic analysis process.

[0112] The concentration of the on-site data to be measured is preliminarily predicted, assuming that the concentration is the global average concentration , the difference between the concentration prediction value of the on-site data to be measured and the concentration of the historical data is calculated, and the calculation formula is as follows:

[0113] Wherein, is the preliminary prediction concentration of the on-site data to be measured.

[0114] If Δ y exceeds the set abnormal threshold, the sample is considered as a suspected abnormal sample.

[0115] The suspected abnormal sample is calibrated: according to the concentration distribution range (such as mean ± 2 times standard deviation) of the historical data, the concentration prediction value of the abnormal sample is adjusted to a reasonable range.

[0116] For the on-site data to be measured similar to the historical sample or abnormal, the calibrated concentration value is directly used as the final prediction result. For other data, the global average concentration is still used as the prediction value.

[0117] Real-time feedback and adaptive learning module is introduced in step S8 to detect data quality and model prediction performance in real time, combine reinforcement learning algorithm, automatically adjust parameters according to real-time feedback, and optimize prediction performance. Real-time feedback and adaptive learning include the following steps: The Fourier transform infrared spectrometer is used to continuously collect the infrared spectrum data of natural gas on site. During the data collection process, data quality evaluation is carried out synchronously, including calculation of signal-to-noise ratio, detection of abnormal value proportion and checking of data integrity. Among them, the signal-to-noise ratio is calculated by comparing the standard deviations of the signal band and the noise band, the abnormal value is detected by using the Mahalanobis distance method, and the detection threshold is established based on the statistical characteristics of the historical data; The reinforcement learning model is constructed and trained, and the state space is defined as the combination of the reduced spectral features, historical prediction errors and data quality indicators. The action space includes continuous action and discrete action, which are used to adjust the model parameters and select the prediction model respectively; When designing the reward function, the prediction accuracy and data quality factors are considered comprehensively, the proximal policy optimization algorithm is used for model training, and the data quality callback function is set to realize the intervention mechanism under abnormal conditions; Adaptive learning and parameter optimization are implemented during system operation. The online gradient descent algorithm is used to fine-tune the model parameters in real time, and the ring buffer is used to store the latest data for incremental learning; Statistical characteristic parameters are updated daily to ensure the timeliness of abnormal detection. At the same time, a hierarchical abnormal response mechanism is established to take different measures according to the severity of the abnormality, from reducing the collection frequency to starting the backup sensor to system shutdown alarm; The system continuously outputs real-time monitoring results during operation, including gas concentration prediction value, confidence, model state and data quality indicators and other information; These information are output in structured data format for subsequent analysis and display. At the same time, the system regularly performs cross-validation to evaluate the performance of the model on new data, and triggers the model retraining process when the performance drops below the threshold.

[0118] In specific use, the Fourier transform infrared spectrometer is used to continuously collect the infrared spectrum data of natural gas on site. During the data collection process, data quality evaluation is carried out synchronously, including calculation of signal-to-noise ratio, detection of abnormal value proportion and checking of data integrity.

[0119] Among them, the signal-to-noise ratio is calculated by comparing the standard deviations of the signal band and the noise band, the abnormal value is detected by using the Mahalanobis distance method, and the detection threshold is established based on the statistical characteristics of the historical data; The reinforcement learning model is constructed and trained, and the state space is defined as the combination of the reduced spectral features, historical prediction errors, and implementation data quality indicators. The action space includes continuous actions and discrete actions, which are used to adjust the model parameters and select the prediction model, respectively; The prediction accuracy and data quality factors are considered in the design of the reward function, and the proximal policy optimization algorithm is used for model training, and the data quality callback function is set to realize the intervention mechanism in abnormal situations; During operation, adaptive learning and parameter optimization are implemented. The online gradient descent algorithm is used to fine-tune the model parameters in real time, and the ring buffer is used to store the latest data for incremental learning; The statistical feature parameters are updated daily to ensure the timeliness of the anomaly detection. At the same time, a hierarchical anomaly response mechanism is established, and different measures are taken according to the severity of the anomaly, from reducing the collection frequency to starting the backup sensor to system shutdown alarm; Real-time monitoring results are continuously output during operation, including gas concentration prediction values, confidence levels, model status, and data quality indicators; These information is output in a structured data format, which is convenient for subsequent analysis and display. At the same time, cross-validation is performed regularly to evaluate the performance of the model on new data, and when the performance drops below a certain threshold, the model retraining process is triggered.

[0120] The spectral data is preprocessed using piecewise multivariate scatter correction and Mahalanobis distance method to eliminate noise and outliers, and combined with XGBoost model and Bayesian optimization technology, an efficient decision-making process is constructed to automatically select the optimal algorithm and hyperparameter configuration, a qualitative analysis model of natural gas is established to identify the gas type, and a similarity measurement threshold is set according to the dynamic modeling requirements to filter the historical samples similar to the field data, further, a local dynamic analysis model and a global dynamic analysis model are constructed to predict the natural gas concentration similar to or abnormal to the historical data, finally, real-time feedback and adaptive learning methods are introduced, through deep reinforcement learning and online gradient descent algorithm, the data quality is dynamically monitored and the model parameters are optimized to ensure the efficiency and accuracy of the measurement system. This method can automatically adapt to data changes in complex environments, reduce manual intervention, improve measurement efficiency and reliability, and is particularly suitable for real-time monitoring and rapid response scenarios.

[0121] Segmented multivariate scatter correction is superior to traditional global correction in terms of improving signal-to-noise ratio, preserving feature peak clarity, and retaining characteristic peak clarity by correcting independently in wavelength intervals for spectral baseline drift and scattering noise. Mahalanobis distance method is superior to single variable detection in terms of higher accuracy of abnormal value identification based on covariance matrix detection for multivariate correlation anomalies (such as multi-dimensional outlier data caused by gas mixing error and instrument failure). The combination of physical noise reduction and statistical detection forms a closed loop for precise prediction and robustness, and the preprocessed data reduces modeling error, which is suitable for natural gas multi-component and dynamic change scenarios, and improves the reliability of real-time monitoring.

[0122] XGBoost pre-screening efficient algorithm narrows the search range, and Bayesian optimization accurately optimizes the hyperparameters, which shortens the hyperparameter optimization time and improves the model training efficiency compared to single technology. Real-time combination of spectral data characteristics automatically adjusts the algorithm and parameters to improve the qualitative classification accuracy and reduce the quantitative prediction error (RMSE) when the natural gas components change (such as single component to multi-component mixture).

[0123] XGBoost combined with Bayesian optimization search parameters greatly improves the accuracy of mixed gas category identification and solves the classification ambiguity problem caused by overlapping absorption peaks. Collaborative optimization shortens the search time of hyperparameters and improves the efficiency of model training, which meets the requirements of fast response and high precision in natural gas pipeline online monitoring, especially for complex scenarios with dynamic changes in gas sources.

[0124] For samples highly similar to historical data (selected by Siamese network), an improved K-nearest neighbor algorithm is used to predict the concentration using weighted average. Global dynamic analysis model processes low similarity or abnormal samples (such as gas source mutation and instrument failure data) with historical data.

[0125] The global model provides abnormal calibration reference for the local model (such as historical concentration distribution range), and the local model accumulates new samples for the global model (updates the historical data set through incremental learning), forming a closed loop from precise prediction to robustness.

[0126] The global model provides abnormal calibration reference for the local model (such as historical concentration distribution range), and the local model accumulates new samples for the global model (updates the historical data set through incremental learning), forming a closed loop from precise prediction to robustness.

[0127] Dual-model parallel computing can complete the similarity judgment to model invocation and finally result output process in a relatively short time, meeting the millisecond-level response requirements of natural gas pipeline real-time monitoring.

[0128] Based on real-time spectral data, automatically adjust model parameters, cope with natural gas multi-component mixed gas ratio fluctuation, reduce model prediction error. Through the reward function, learn the mapping relationship between data quality and parameter configuration, for example, automatically switch to a more robust algorithm (such as from K-Nearest Neighbors to XGBoost) when noise increases, improve the long-term stability of the system.

[0129] The effect of online gradient descent (OGD) algorithm: within the parameter value range, it is reasonable to force parameter update (such as learning rate is kept at 0.001-0.1), prevent gradient explosion or disappearance, ensure the convergence speed of the model in non-stationary data (such as gas containing temporary impurities).

[0130] After combining, DRL formulates long-term optimization strategy, and OGD executes real-time parameter fine-tuning. Through the state evaluation of DRL combined with the parameter projection of OGD, realize the linkage of data quality monitoring-model parameter calibration, make the prediction accuracy of the system in high noise scene higher than that of single technology.

[0131] Using the exploration mechanism of DRL to automatically mine unannotated potential abnormal patterns (such as new impurity gas spectrum), combined with the online learning ability of OGD, without manual intervention, the model can be extended to apply to a wider range, reducing the dependence on historical sample set.

[0132] The above is only an embodiment of the present application, the present application is not limited to this embodiment. The specific structure and characteristics of the scheme known in the art are not described in detail here. The ordinary skilled person in the art knows all the ordinary technical knowledge in the field of the application before the filing date or the priority date, can know all the prior art in this field, and has the ability to apply conventional experimental means before that date. The ordinary skilled person in the art can improve and implement the present scheme based on their own ability under the guidance of the present application. Some typical known structures or known methods should not be an obstacle for the ordinary skilled person in the art to implement the present application. It should be noted that for those skilled in the art, without departing from the structure of the present application, a number of modifications and improvements can be made, which should be considered as the protection scope of the present application. These will not affect the effect and practicality of the present application. The protection scope of the present application should be subject to the content of its claims. The specific implementation mode in the specification can be used to explain the content of the claims.

Claims

1. A real-time feedback and adaptive learning method for infrared spectral measurement of natural gas, characterized in that, Includes the following steps: Step S1: Use an infrared spectrometer to acquire infrared spectral information of natural gas and construct a historical sample set; Step S2: Preprocess the spectral data of the historical sample set; Step S3: Construct a decision-making process using extreme gradient boosting and Bayesian optimization, selecting the optimal algorithm and its corresponding hyperparameter configuration from the defined algorithm set to minimize the loss function; Step S4: Based on the spectral data preprocessed in Step S2 and the optimal qualitative analysis algorithm and hyperparameters determined in Step S3, construct a qualitative analysis model, use the qualitative analysis model to identify the types of natural gas, and select a dataset that matches the identification results from the historical sample set. Step S5: Set the threshold value for similarity measurement according to the requirements of dynamic modeling, and measure the similarity between the data collected on site and the historical sample data obtained in step S4 through comparison principles; Step S6: Based on the local similar samples obtained in step S5, and combined with the improved K-nearest neighbor algorithm, construct a local dynamic quantitative analysis model to predict the natural gas concentration of the on-site sample to be tested. Step S7: Construct a global dynamic analysis model. For field data with low similarity to historical samples or abnormality, use the global average concentration of the historical dataset for preliminary prediction. Determine whether it is an abnormal sample by calculating the difference between the predicted value and the historical data concentration and perform calibration. Output the calibrated concentration value as the final prediction result. Step S8: Introduce a real-time feedback and adaptive learning module to continuously collect spectral data and store it as time series data. Monitor data quality and model prediction performance in real time. When data quality is below the threshold or model performance deteriorates, dynamically adjust model parameters and hyperparameters through deep reinforcement learning and online gradient descent algorithms to optimize prediction performance.

2. The real-time feedback and adaptive learning method for infrared spectral measurement of natural gas according to claim 1, characterized in that, In step S1, experimental equipment is used to obtain infrared spectral information of natural gas, and the obtained spectral data is regarded as a historical sample set; the historical sample set includes: single-component natural gas, multi-component mixed natural gas, category label and concentration label.

3. The real-time feedback and adaptive learning method for infrared spectral measurement of natural gas according to claim 2, characterized in that, The preprocessing includes noise reduction using a piecewise multivariate scattering correction method and outlier removal using the Mahalanobis distance method. The Mahalanobis distance method calculates the Mahalanobis distance of a sample based on the feature vector of the sample point, the mean vector of the dataset, and the covariance matrix, and determines whether it is an outlier sample based on a threshold determined by the chi-square distribution.

4. The real-time feedback and adaptive learning method for infrared spectral measurement of natural gas according to claim 3, characterized in that, The data preprocessing method in S2 is segmented multivariate scattering correction and outlier data removal, and gas infrared absorption spectroscopy preprocessing; it includes the following steps: The infrared spectral dataset of natural gas from the experiment was divided into a training set and a test set according to a certain ratio. The original spectral data was then denoised using a piecewise scattering correction method. Furthermore, for any potential anomalies in the dataset, Mahalanobis distance was used to detect abnormal samples in the denoised data. This process is based on the formula... x is the feature vector of the sample point, and μ is the mean vector of the dataset. After calculating the Mahalanobis distance of each sample, a threshold determined based on the chi-square distribution is set. If the Mahalanobis distance of a sample point exceeds the threshold, it is considered an abnormal sample and is removed.

5. The real-time feedback and adaptive learning method for infrared spectral measurement of natural gas according to claim 4, characterized in that, The decision-making process in S3 utilizes an extreme gradient boosting model and Bayesian optimization techniques to find the optimal strategy, including the following steps: Define the set of algorithms , where element A(i) represents an algorithm and its corresponding hyperparameter space; Find the optimal combination of algorithm and hyperparameters to minimize the loss function. ; Combining the XGBoost model and the Bayesian optimization algorithm, the decision-making process first uses the XGBoost model to perform a preliminary evaluation of each algorithm in the algorithm set. Then, the Bayesian optimization algorithm is used to find the optimal configuration in the hyperparameter space of these algorithms. In each iteration, the prediction results of the XGBoost model are used to update the surrogate model of the Bayesian optimization, and the acquisition function EI is used to determine the next evaluation point. The acquisition function is used to balance exploration and exploitation and guide the search for optimal parameters. In this way, the search range can be effectively narrowed and the best algorithm and hyperparameter combination can be found quickly, thereby realizing the optimal strategy in the qualitative and quantitative analysis stages. The optimization objective of the XGBoost model can be expressed as: ; in, These are model predictions. It is the actual value. It is a regularization term. It is the prediction function of the k-th decision tree. These are the corresponding hyperparameters; The key to Bayesian optimization lies in constructing an accurate surrogate model and an effective data collection function; the surrogate model is typically a Gaussian process whose mean and variance are determined by historical data points. ; in, K is the predicted mean of the surrogate model, k(x,x) is the kernel function, k(x) is the kernel function vector, and K is the kernel matrix. It is the noise variance; The acquisition function EI is used to determine the next evaluation point; it measures the current optimal value. The following are the potential improvements that the new point x might bring: ; To calculate EI, it is necessary to... The posterior distribution is sampled, and the next evaluation point x is determined by maximizing EI, which is expected to provide the greatest improvement; the process is iterated until a stopping condition is met, which is reaching the maximum number of iterations or the time limit.

6. The real-time feedback and adaptive learning method for infrared spectral measurement of natural gas according to claim 5, characterized in that, In step S4, a qualitative analysis model is established to identify the types of natural gas. This model can identify specific natural gas from the sample, and based on the identification results, historical datasets matching the qualitative analysis results are selected. The qualitative analysis process includes the following steps: Using the natural gas experimental data preprocessed in step S2 and the optimal qualitative analysis algorithm and hyperparameter settings determined in step S3, a model for qualitative analysis of natural gas is constructed. The qualitative analysis model trained above is used to process the collected measurement data and obtain the qualitative classification results of natural gas. Based on the qualitative analysis results, a historical dataset of gas categories matching the results was selected from the dataset processed in step S2.

7. The real-time feedback and adaptive learning method for infrared spectral measurement of natural gas according to claim 6, characterized in that, In step S5, a similarity measurement threshold is set according to the needs of dynamic modeling, and the similarity measurement between the data obtained from on-site measurement and the historical sample data obtained in step S4 is performed based on the comparison principle. This process includes the following steps: A Siamese network is constructed, consisting of two identical subnetworks sharing the same parameters. Each subnetwork receives one sample as input and outputs the feature representation of that sample. A contrastive loss function is defined to optimize the network parameters, making the feature representations of similar samples closer together and the feature representations of dissimilar samples further apart. The Siamese network is trained using a large number of paired samples, including positive sample pairs and negative sample pairs, where positive sample pairs come from the same class and negative sample pairs come from different classes. For the samples to be tested collected on-site and the samples in the historical sample set, their feature representations are calculated using the trained Siamese network, and the Euclidean distance between the two feature representations is calculated. A similarity threshold is set, and the similarity between the sample to be tested and historical samples is determined based on the magnitude of the Euclidean distance. If the Euclidean distance is less than the similarity threshold, the sample to be tested is considered to be similar to the historical samples. Samples similar to the test sample are selected from the historical sample set and used for the construction of subsequent local dynamic analysis models.

8. The real-time feedback and adaptive learning method for infrared spectral measurement of natural gas according to claim 7, characterized in that, In step S6, a local dynamic quantitative analysis model is constructed, which, combined with an improved K-nearest neighbor algorithm, is used to predict the natural gas concentration of the sample to be tested in the field. This process includes the following steps: The locally similar sample dataset selected in step S5 is used as input. These samples have high similarity to the field test samples in terms of spectral features. The locally similar sample dataset is divided into a training set and a validation set. The training set is used for model training, and the validation set is used to evaluate model performance. For each historical sample in the training set The distance between the sample and the on-site sample was calculated using the Euclidean distance method. Similarity between samples; assign weights to each sample based on similarity; Based on the calculated weights, select the K samples with the largest weights as the nearest neighbors; The K value can be dynamically adjusted based on the performance on the validation set to achieve the best prediction effect; the gas concentration of the on-site sample is predicted by weighted average using the selected K nearest neighbor samples and their weights. Subsequently, the model performance is evaluated on the validation set, and metrics such as mean squared error and coefficient of determination are calculated on the validation set. Based on the performance on the validation set, the K value and parameters in the weight calculation formula are dynamically adjusted to optimize the prediction accuracy. In the local dynamic modeling stage, based on the above process and the optimal algorithm and hyperparameters obtained in step S3, a local dynamic analysis model is constructed to obtain the gas concentration of the sample to be tested.

9. The real-time feedback and adaptive learning method for infrared spectral measurement of natural gas according to claim 8, characterized in that, In step S7, a global dynamic analysis model is constructed to predict the concentration of natural gas and to process on-site test data that has low similarity to historical samples or is considered abnormal and unsuitable for analysis using local models. In addition, this process also includes calibrating suspected abnormal samples by combining anomaly detection mechanisms to improve the accuracy of subsequent analysis and verification. The global dynamic modeling and analysis process includes the following steps: From steps S1-S6, obtain the preprocessed and filtered historical dataset, including natural gas spectral data and its corresponding concentration labels. Perform a simple moving average calculation on the concentration labels in the historical dataset to obtain a global average concentration value. ; A similarity assessment is performed on the on-site data to determine its similarity to historical data; If the similarity between the on-site data to be tested and the historical data is lower than the set threshold, the data is considered unsuitable for analysis using a local model and enters the global dynamic analysis process. A preliminary prediction of the concentration of the on-site measured data is made, assuming that its concentration is the global average concentration. The difference between the predicted concentration of the on-site test data and the historical concentration data is calculated using the following formula: ; If Δy exceeds the set anomaly threshold, the sample is considered a suspected anomaly sample; the suspected anomaly sample is calibrated: based on the concentration distribution range of historical data, the concentration prediction value of the anomaly sample is adjusted to a reasonable range; For field data with low or abnormal similarity to historical samples, the calibrated concentration value is used directly as the final prediction result; for other data, the global average concentration is still used. As a predicted value.

10. The real-time feedback and adaptive learning method for infrared spectral measurement of natural gas according to claim 9, characterized in that, Step S8 introduces a real-time feedback and adaptive learning module to monitor data quality and model prediction performance in real time. Combined with reinforcement learning algorithms, it automatically adjusts parameters based on real-time feedback to optimize prediction performance. The real-time feedback and adaptive learning include the following steps: Continuously collect on-site infrared spectral data of natural gas and compare it with historical data to evaluate the quality of the collected data in real time, including signal-to-noise ratio, data integrity, and outlier ratio. At the same time, monitor the predictive performance of the model to ensure its accuracy and stability on real-time data. When the data quality falls below a preset threshold or the model performance deteriorates significantly, an alarm is triggered, data collection is automatically paused, and manual intervention or re-collection is required. In the adaptive learning process, reinforcement learning algorithms are first used to automatically adjust model parameters based on real-time feedback to optimize prediction performance. At the same time, online learning algorithms are employed to enable the model to learn new data features in real time without retraining the entire model. Incremental learning algorithms are also combined to dynamically update historical datasets to ensure the timeliness and accuracy of the data. Throughout this process, hyperparameters are dynamically adjusted based on real-time feedback to adapt to different environmental conditions and data changes.

Citation Information

Cited By

  • Gas detection method and system based on quartz tuning fork enhanced photoacoustic spectrum

    CN121558634A

  • Infrared spectrum atmospheric absorption interference correction method and system

    CN122306736A

  • Infrared spectrum atmospheric absorption interference correction method and system

    CN122306736B