Natural gas pipeline multi-factor internal corrosion rate prediction method based on integrated QPSO-BP
By integrating the QPSO-BP algorithm, the number of hidden layer nodes of the BP neural network is optimized, and combined with PCA dimensionality reduction and multi-model integration, the local optimal solution problem of the BP neural network when predicting the corrosion rate in multiple factors of oil and gas pipelines is solved, achieving higher prediction accuracy and robustness.
Patent Information
- Application Number
- CN202411586666.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-02-25
AI Technical Summary
When the prior art predicts the multi-factor internal corrosion rate of oil and gas pipelines, BP neural networks are prone to fall into local optimal solutions, resulting in weak global search capabilities and poor robustness, affecting the prediction accuracy.
The integrated QPSO-BP algorithm is adopted to optimize the number of hidden layer nodes of the BP neural network through QPSO, helping the network to jump out of the local optimal solution, find the global optimal solution, and improve the accuracy of prediction through PCA dimensionality reduction processing and the results of multiple models.
It effectively improves the global search capability and robustness of BP neural network when predicting corrosion rates in multiple factors of oil and gas pipelines, and significantly improves the accuracy and reliability of prediction.
Smart Images

Figure CN119513538A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a natural gas pipeline multi-factor internal corrosion rate prediction method based on integrated QPSO-BP, and relates to the field of oil and gas pipeline corrosion prediction. Background Art
[0002] With the continuous exploitation of oil and gas resources, the use of transportation pipelines is becoming more and more frequent. However, as the service life of pipelines continues to increase, the hidden dangers of internal corrosion failure are gradually increasing. Once a leak occurs, it will not only cause huge economic losses, but also cause serious environmental pollution. Therefore, it is necessary to study the corrosion phenomenon and corrosion prediction inside oil and gas transportation pipelines in order to reduce the risk of corrosion failure.
[0003] The degree of internal corrosion of oil and gas pipelines mainly depends on factors such as the medium transported in the pipe and the operating conditions, including temperature, pressure, flow rate, and corrosive media. The interior of the pipeline usually contains H2S, CO2, and Cl - Under the combined action of multiple factors, the corrosion mechanism is complex and full of changes. Therefore, it is urgent to carry out the prediction of multi-factor internal corrosion rate of natural gas pipelines.
[0004] BP is the abbreviation of BackPropagation, which means back propagation. It has high fault tolerance, strong learning ability and robustness, and can fully adapt to complex nonlinear relationships. Because it is easy to fall into the local optimal solution, the BP neural network may not be able to reach the global optimal solution. This may cause the accuracy of the network to decrease and affect subsequent prediction tasks. Optimizing the BP neural network through QPSO can help the network jump out of the local optimal solution and find the global optimal solution. Therefore, based on the integrated QPSO-BP neural network algorithm, the present invention establishes a method for predicting the multi-factor internal corrosion rate of natural gas pipelines, which specifically solves the problem of oil and gas pipeline corrosion prediction and protects the integrity of oil and gas pipelines. Summary of the invention
[0005] The purpose of the present invention is to overcome the shortcomings of the above-mentioned prior art and provide a method for predicting the multi-factor internal corrosion rate of a natural gas pipeline based on an integrated QPSO-BP algorithm to solve the problems of weak global search capability, poor robustness, and easy falling into local minimum when the BP neural network faces partial data.
[0006] The method for predicting the multi-factor internal corrosion rate of natural gas pipelines based on the integrated QPSO-BP algorithm specifically includes the following steps:
[0007] Step 1: Obtain sampling data;
[0008] Step 2: Perform PCA dimensionality reduction on the data;
[0009] Step 3: Construct BP neural network prediction model;
[0010] Step 4: Use the QPSO algorithm to obtain the optimal number of hidden layer nodes of the BP neural network;
[0011] Step 5: Use the number of hidden layer nodes output by QPSO to establish multiple BP neural network models.
[0012] Step 6: Integrate the prediction results of multiple models to obtain the final prediction result.
[0013] Furthermore, the corrosion factors included in the sampling data in step 1 include operating temperature (°C), full-line pressure (MPa), CO2 partial pressure (MPa), full-line gas flow rate (m / s), calculated critical inclination (rad), true inclination (rad), water accumulation probability, gas phase shear stress Pa / m, liquid phase shear stress Pa / m, surface tension, gas viscosity, liquid viscosity, in-situ pH value, Cl - Ion content, SO4 - Content, Na + Content, K + Content, Ca 2+ Content, Mg 2+ Content and other 19 corrosion factors.
[0014] Further, the step 2 specifically includes the following steps:
[0015] Step 2.1, standardize the data to obtain the standardized matrix Z;
[0016] Step 2.2, calculate the covariance matrix;
[0017] Step 2.3, calculate the eigenvalue;
[0018] Step 2.4: Calculate the principal component score matrix T.
[0019] Further, the step 2.1 is specifically as follows:
[0020] First, calculate the mean and standard deviation of each corrosion factor. The mean and standard deviation calculation formula is:
[0021]
[0022]
[0023] In formula (1), X ij is the i-th data of the j-th corrosion factor, is the mean value of the jth corrosion factor;
[0024] In formula (2), S jis the standard deviation of the jth factor;
[0025] Finally, the data is processed using the standardization formula to obtain the standardization matrix Z. The standardization formula is:
[0026]
[0027] In formula (3), Zij represents the i-th data of the j-th corrosion factor.
[0028] Further, the step 2.2 is specifically as follows:
[0029] The covariance matrix is calculated according to the covariance matrix calculation formula, and the covariance matrix calculation formula is:
[0030]
[0031] In formula (4), R is the covariance matrix.
[0032] Further, the step 2.3 is specifically as follows:
[0033] Perform eigenvalue decomposition on the covariance matrix and set the eigenvalue of R to be λ1≥λ2≥λ3≥...≥λ k ≥0, the corresponding eigenvectors are V1, V2, ... V k . k 、V k Represent the Kth eigenvalue and eigenvector respectively.
[0034] Further, the step 2.4 is specifically as follows:
[0035] The principal component score matrix T is calculated according to the principal component score formula, and the principal component score formula is:
[0036]
[0037] In formula (5), Z i is the i-th row of the standardized data matrix Z, t ik It represents the score of the i-th sample on the k-th principal component.
[0038] Further, the step 4 specifically includes the following steps:
[0039] Step 4.1: Perform grid initialization processing on the natural gas pipeline multi-factor internal corrosion rate prediction model based on the QPSO-BP algorithm.
[0040] Step 4.2, determine the individual fitness through iterative calculation, and update the position parameters according to the results;
[0041] Step 4.3, determine whether the iteration of the corrosion prediction model is completed. If the number of iterations reaches the maximum value or reaches the target threshold after iteration, the iteration is completed, otherwise return to 4.2 for iteration.
[0042] Further, the step 4.1 is specifically as follows:
[0043] The grid initialization processing, the initialization objects are the number of parameters optimized by the QPSO algorithm, the total number of particles used for optimization, the maximum number of iterations, the upper and lower bounds of each particle, the shrinkage and expansion coefficient β, the random number μ, and the acceptable mean square error used to determine whether to end use.
[0044] Further, the step 4.2 is specifically as follows:
[0045] First, the preprocessed training set is initialized based on the QPSO-BP algorithm;
[0046] Next, the optimal position P of the individual is calculated through iterative calculation best,i and the global optimal value g best , substitute the average value formula of the optimal position of all particles into the average value formula of the optimal position of all particles to calculate the average value m of the optimal position of all particles best ;
[0047] Finally, according to the concept of quantum interference, the particles in QPSO will influence each other, increase the diversity of the search, prevent falling into the local optimal solution, and update the particle position. The average value formula of the optimal position of all individual particles and the particle position update formula are:
[0048]
[0049]
[0050] In formula (7), X i (t+1) is the position of particle i at the t+1th iteration after the update, p i The individual optimal p of the particle best,i and the global optimal position g best Combination, β is the contraction and expansion coefficient, x i (t) is the position of the particle at the tth iteration, and μ is a random number uniformly distributed in the interval [0,1].
[0051] Further, the step 4.3 is specifically as follows:
[0052] After each time the QPSO algorithm is used to find the optimal solution, the mean square error (MSE) of the BP network prediction after each optimization is calculated. If the mean square error (MSE) of the BP network prediction is less than the set limit mean square error (MSE′), the iteration is stopped; or, when the number of iterations reaches the maximum value, the iteration is stopped; otherwise, return to step 4.2 and iterate again. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 A flowchart of optimizing the number of BP hidden layer nodes based on QPSO provided by the present invention;
[0054] Figure 2 The present invention provides a flow chart of a method for predicting the multi-factor internal corrosion rate of a natural gas pipeline based on integrated QPSO-BP.
[0055] Figure 3 The final corrosion rate is obtained by integrating the prediction results of multiple model test sets trained by the natural gas pipeline multi-factor internal corrosion prediction model based on integrated QPSO-BP provided by the present invention. Specific implementation methods
[0056] See also Figure 2 As shown, the present invention provides a method for predicting the multi-factor internal corrosion rate of a natural gas pipeline based on integrated QPSO-BP, and the specific steps include:
[0057] Step 1: Obtain the operating temperature (℃), full-line pressure (MPa), CO2 partial pressure (MPa), full-line gas flow rate (m / s), calculated critical inclination (rad), true inclination (rad), water accumulation probability, gas phase shear stress Pa / m, liquid phase shear stress Pa / m, surface tension, gas viscosity, liquid viscosity, in-situ pH value, Cl - Ion content, SO4 - Content, Na + Content, K + Content, Ca 2+ Content, Mg 2+ Field data of 19 corrosion factors such as content.
[0058] Step 2: Perform PCA dimensionality reduction on the data, dividing 30% of the data into a training set and 70% into a test set. The specific process is as follows:
[0059] Step 2.1: First, calculate the mean and standard deviation of each corrosion factor. The mean and standard deviation calculation formula is:
[0060]
[0061]
[0062] In formula (1), X ij is the i-th data of the j-th corrosion factor, is the mean value of the jth corrosion factor;
[0063] In formula (2), S j is the standard deviation of the jth factor;
[0064] Finally, the data is processed using the standardization formula to obtain the standardization matrix Z. The standardization formula is:
[0065]
[0066] In formula (3), Z ij Represents the i-th data of the j-th corrosion factor.
[0067] Step 2.2 is as follows:
[0068] The covariance matrix is calculated according to the covariance matrix calculation formula, and the covariance matrix calculation formula is:
[0069]
[0070] In formula (4), R is the covariance matrix.
[0071] Step 2.3 is as follows:
[0072] Perform eigenvalue decomposition on the covariance matrix and set the eigenvalue of R to be λ1≥λ2≥λ3≥...≥λ k ≥0, the corresponding eigenvectors are V1, V2, ... V k . k 、V k Represent the Kth eigenvalue and eigenvector respectively.
[0073] Step 2.4 is as follows:
[0074] The principal component score matrix T is calculated according to the principal component score formula, and the principal component score formula is:
[0075]
[0076] In formula (5), Z i is the i-th row of the standardized data matrix Z, t ik It represents the score of the i-th sample on the k-th principal component.
[0077] Step 3: Build a BP neural network prediction model, set the number of input layers to 19, and the number of final output layers to 1.
[0078] Step 4: Use the QPSO algorithm to obtain the optimal number of hidden layer nodes of the BP neural network. The specific process is as follows:
[0079] Step 4.1 is as follows:
[0080] The grid initialization processing, the initialization objects are the number of parameters optimized by the QPSO algorithm, the total number of particles used for optimization, the maximum number of iterations, the upper and lower bounds of each particle, the shrinkage and expansion coefficient β, the random number μ, and the acceptable mean square error used to determine whether to end use.
[0081] Step 4.2 is as follows:
[0082] First, the preprocessed training set is initialized based on the QPSO-BP algorithm;
[0083] Next, the optimal position P of the individual is calculated through iterative calculation best,i and the global optimal value g best , substitute the average value formula of the optimal position of all particles into the average value formula of the optimal position of all particles to calculate the average value m of the optimal position of all particles best ;
[0084] Finally, according to the concept of quantum interference, the particles in QPSO will influence each other, increase the diversity of the search, prevent falling into the local optimal solution, and update the particle position. The average value formula of the optimal position of all individual particles and the particle position update formula are:
[0085]
[0086]
[0087] In formula (7), X i (t+1) is the position of particle i at the t+1th iteration after the update, p i The individual optimal p of the particle best,i and the global optimal position g best Combination, β is the contraction and expansion coefficient, x i (t) is the position of the particle at the tth iteration, and μ is a random number uniformly distributed in the interval [0,1].
[0088] Step 4.3 is as follows:
[0089] After each time the QPSO algorithm is used to find the optimal solution, the mean square error (MSE) of the BP network prediction after each optimization is calculated. If the mean square error (MSE) of the BP network prediction is less than the set limit mean square error (MSE′), the iteration is stopped; or, when the number of iterations reaches the maximum value, the iteration is stopped; otherwise, return to step 4.2 and iterate again.
[0090] Step 5: The optimal number of hidden layer nodes is 15. Substitute the optimal number of hidden layer nodes into and train multiple QPSO-BP models.
[0091] Step 6: Integrate the prediction results of multiple models to obtain the final prediction result. The prediction result is as follows: Figure 3As shown in Figure 2, the maximum corrosion prediction error is 2.123%, the minimum is 0.0046%, and the average prediction error is 0.226%.
Claims
1. A multi-factor internal corrosion rate prediction method for natural gas pipelines based on integrated QPSO-BP, characterized in that: The specific steps include: Step 1: Obtain sampling data; Step 2: Perform PCA dimensionality reduction on the data; Step 3: Construct BP neural network prediction model; Step 4: Use the QPSO algorithm to obtain the optimal number of hidden layer nodes of the BP neural network; Step 5: Use the number of hidden layer nodes output by QPSO to establish multiple BP neural network models; Step 6: Integrate the prediction results of multiple models to obtain the final prediction result.
2. The method for predicting the multi-factor internal corrosion rate of a natural gas pipeline based on the QPSO-BP algorithm according to claim 1 is characterized in that: Step 4 specifically includes the following steps: Step 2.1, perform grid initialization processing on the natural gas pipeline multi-factor internal corrosion rate prediction model based on QPSO-BP algorithm; Step 2.2, determine the individual fitness through iterative calculation, and update the position parameters according to the results; Step 2.3, determine whether the iteration of the corrosion prediction model is completed. If the number of iterations reaches the maximum value or reaches the target threshold after iteration, the iteration is completed, otherwise return to 2.2 for iteration.
3. The method for predicting the multi-factor internal corrosion rate of a natural gas pipeline based on the QPSO-BP algorithm according to claim 2 is characterized in that , the step 2.1 is specifically as follows: The grid initialization processing, the initialization objects are the number of parameters optimized by the QPSO algorithm, the total number of particles used for optimization, the maximum number of iterations, the upper and lower bounds of each particle, the shrinkage and expansion coefficient β, the random number μ, and the acceptable mean square error used to determine whether to end use.
4. According to the method for predicting the multi-factor internal corrosion rate of natural gas pipelines based on the QPSO-BP algorithm according to claim 2, the step 2.2 is specifically: First, the preprocessed training set is initialized based on the QPSO-BP algorithm; Next, the optimal position P of the individual is calculated through iterative calculation best,i and the global optimal value g best , substitute the average value formula of the optimal position of all particles into the average value formula of the optimal position of all particles to calculate the average value m of the optimal position of all particles best ; Finally, according to the concept of quantum interference, the particles in QPSO will influence each other, increase the diversity of the search, prevent falling into the local optimal solution, and update the particle position. The average value formula of the optimal position of all individual particles and the particle position update formula are: In formula (7), X i (t+1) is the position of particle i at the t+1th iteration after the update, p i The individual optimal p of the particle best,i and the global optimal position g best Combination, β is the contraction and expansion coefficient, x i (t) is the position of the particle at the tth iteration, and μ is a random number uniformly distributed in the interval [0,1].
5. The method for predicting the multi-factor internal corrosion rate of a natural gas pipeline based on the QPSO-BP algorithm according to claim 2 is characterized in that The method for judging whether the iteration of the natural gas pipeline multi-factor internal corrosion prediction model is completed in step 2.3 is as follows: After each time the QPSO algorithm is used to find the optimal solution, the mean square error (MSE) of the BP network prediction after each optimization is calculated. If the mean square error (MSE) of the BP network prediction is less than the set limit mean square error (MSE′), the iteration is stopped; or, when the number of iterations reaches the maximum value, the iteration is stopped; otherwise, return to step 2.2 and iterate again.