Transformer oil well production prediction method and device based on gating constraint and Kalman filtering, and medium
Patent Information
- Application Number
- CN202610568075.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-27
- Publication Date
- 2026-08-04
AI Technical Summary
[0008]为了解决上述至少一个技术问题,本发明的目的在于提供一种基于门控约束和卡尔曼滤波的 Transformer 油井产量预测方法,以解决现有油井产量预测技术存在的极端工况下输出失真、卡尔曼滤波适用前提不匹配导致修正效果、稳定性和鲁棒性不足、长时序预测误差持续累积,以及修正逻辑存在未来信息泄露、无法适配油田现场在线实时预测需求的问题
[0053] Using forward linear interpolation to fill in missing values improves the continuity and availability of time series data.
Smart Images

Figure CN122509750A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of oil well production time series prediction technology, and more specifically, to a Transformer oil well production prediction method, equipment and medium based on gating constraints and Kalman filtering. Background Technology
[0002] Oil well production forecasting is an important technical aspect of oil and gas field development and production management. The forecast results can provide a basis for adjusting oil well production systems, optimizing production allocation, and evaluating development effectiveness.
[0003] Existing oil well production prediction methods mainly include empirical decline analysis, statistical regression, and deep learning-based prediction methods. Empirical decline analysis has clear physical significance for reservoir development, but its adaptability to complex operating conditions and multivariate coupled scenarios is limited. Statistical regression methods have significant limitations in handling the strongly nonlinear relationships and long-term time-series dependencies in oil well production data. While deep learning methods based on recurrent neural networks and long short-term memory networks have improved prediction accuracy to some extent, they still lack effective means to address issues such as missing data, feature redundancy, well switching, and long-term prediction error accumulation.
[0004] Among them, the Transformer model possesses a self-attention mechanism, enabling adaptive modeling of correlations between different time steps and features. It exhibits significant technical advantages over Long Short-Term Memory (LSTM) networks in global feature extraction, long-range temporal dependency capture, and parallel computing, and has been gradually applied to oil well production time-series prediction scenarios. However, existing Transformer-based production prediction schemes still fail to address the core issues of prediction distortion during well opening and closing and the continuous accumulation of long-term prediction errors. Furthermore, publicly available Kalman filtering methods can only perform single-step corrections or offline smoothing of the prediction results at the current moment, failing to achieve residual recursive correction during long-term prediction. They also suffer from the problem of leaking future information by using current measured data to correct the prediction results at the current moment, only optimizing offline fitting accuracy and unable to be applied to online real-time prediction scenarios in oilfields.
[0005] In existing research on oil and gas production forecasting based on Kalman filtering, most studies use the original production forecast values output by the model as the object of filtering correction, with few studies focusing on targeted filtering correction designs around the model prediction residuals. Because oil and gas production time series inherently exhibit significant long-term declining trends and non-stationary fluctuations caused by abrupt changes in operating conditions, they deviate somewhat from the applicability premise of the approximately linear, zero-mean stationary Gaussian sequence required for optimal Kalman filtering estimation, thus limiting the stable effectiveness of the filtering correction. Meanwhile, existing methods mostly focus on single-time correction of the current prediction result or offline smoothing optimization of historical data, paying less attention to the design of residual recursive correction mechanisms in long-term prediction processes. This processing logic, which corrects the prediction results based on concurrent measured data, inevitably introduces the risk of future information leakage. While it can effectively improve the offline fitting accuracy of historical data, it is difficult to directly adapt to the engineering application requirements of real-time online prediction in oilfields.
[0006] Furthermore, historical production data from oil wells often contains missing values, noise interference, and significant production fluctuations. Directly modeling based on this raw data can easily lead to increased prediction bias. Simultaneously, oil wells frequently switch between open and closed states during actual production. If the model does not explicitly and effectively constrain the closed-state, it will output non-zero prediction results that are completely inconsistent with the actual production status, further exacerbating prediction errors. Moreover, under complex and fluctuating operating conditions, high-error samples, and localized production surges, a single prediction model is prone to instability and excessive local bias, failing to meet the actual requirements of oil and gas field development and production for prediction accuracy, stability, and robustness.
[0007] Therefore, it is necessary to propose an oil well production prediction method that can take into account data preprocessing, feature selection, state constraints, time series modeling, and causal recursive residual correction, so as to improve the accuracy, stability and robustness of oil well production prediction, while meeting the industrial application requirements of online real-time prediction in oil fields. Summary of the Invention
[0008] To address at least one of the aforementioned technical problems, the present invention aims to provide a Transformer oil well production prediction method based on gating constraints and Kalman filtering. This method aims to solve the problems of existing oil well production prediction technologies, such as output distortion under extreme operating conditions, mismatch of Kalman filtering application premises leading to correction effect, insufficient stability and robustness, continuous accumulation of long-term prediction errors, and the possibility of future information leakage in the correction logic, as well as the inability to adapt to the online real-time prediction needs of oilfields.
[0009] The first aspect of this invention provides a Transformer oil well production prediction method based on gating constraints and Kalman filtering, comprising the following steps:
[0010] Obtain historical production data of the target oil well, preprocess the historical production data of the target oil well, and obtain preprocessed historical production data.
[0011] Extract feature information from preprocessed historical production data, select features based on set conditions, and construct conditional gating constraint feature information that characterizes the operating status of oil wells;
[0012] The selected features and conditional gating constraint features are constructed into time series samples in chronological order and then normalized to obtain the normalized result information.
[0013] Input the normalized result information into the preset Transformer prediction model to obtain the initial prediction result information of oil well production;
[0014] Based on the conditional gating constraint features, the initial prediction result of the oil well production is subjected to state constraints to obtain the state-constrained prediction result.
[0015] The prediction residual value is obtained based on the prediction residual between the actual observation value at the current time and the prediction result after state constraints;
[0016] The predicted residual value is recursively estimated using Kalman filtering to obtain the residual state estimate. The residual is then corrected based on the residual state estimate to obtain the final oil well production prediction result.
[0017] In a preferred embodiment of the present invention, historical production data of the target oil well is obtained, and the historical production data of the target oil well is preprocessed to obtain preprocessed historical production data, specifically including:
[0018] Obtain historical production data of the target oil well, including date, well opening time, average downhole pressure, average downhole temperature, average tubing pressure differential, average annular pressure, choke size percentage, average wellhead pressure, average wellhead temperature, pressure difference across the choke ring, and oil well production.
[0019] The historical production data of the target oil well is format-validated to remove duplicate data and missing fields.
[0020] The missing fields are filled in using the forward linear interpolation method to obtain the completed historical production data.
[0021] Analyze the completed historical production data based on outlier identification methods, and analyze the differences in the completed data.
[0022] The missing fields are adjusted based on the imputation difference values to obtain the preprocessed historical production data.
[0023] In a preferred embodiment of the present invention, a mutual information method is used to calculate the mutual information value between candidate input features and target output. The candidate input features are then preliminarily sorted and filtered based on the mutual information value. The mutual information is represented as:
[0024] ;
[0025] Where X is the input feature, Y is the target output, p(x, y) is the joint probability distribution, and p(x) and p(y) are the marginal probability distributions, respectively.
[0026] In a preferred embodiment of the present invention, the Transformer prediction model includes an input mapping layer, a position encoding layer, a multi-head self-attention layer, a feedforward network layer, a residual connection layer, a normalization layer, and an output layer, and sets an early stopping mechanism and Dropout regularization during training.
[0027] In a preferred embodiment of the present invention, the historical production data is divided into a training set, a validation set, and a test set in chronological order, wherein the ratio of the training set, validation set, and test set is 8:1:1. The training set, validation set, and test set are transformed respectively. The data transformation process includes normalizing the continuous input features, fitting normalization parameters based on the training set, and transforming the training set, validation set, and test set respectively using the normalization parameters.
[0028] In a preferred embodiment of the present invention, the normalized result information is input into a preset Transformer prediction model to obtain the initial prediction result information of oil well production, specifically including:
[0029] The mapping process of the input mapping layer is represented as follows:
[0030]
[0031] in, This represents the feature matrix output by the input mapping layer; , These are the trainable weight matrix and bias term of the input mapping layer, respectively; This represents the preprocessed oil well production time series feature matrix;
[0032] Position encoding is performed based on the position encoding layer to obtain:
[0033]
[0034] in, This represents the encoded feature matrix after injecting location information; Represents the temporal position encoding matrix;
[0035] The multi-head self-attention is calculated as follows:
[0036] ;
[0037] The final output of the bullish self-attention is ;
[0038] in, This is the output feature matrix of the single-head self-attention operation; , , These represent the query matrix, key matrix, and value matrix, respectively, all of which are obtained by linear mapping from the encoded feature matrix Z′. Key matrix The transpose of the matrix, Let K be the feature dimension of the key matrix. This is the scaling factor; It is a normalized exponential function;
[0039] The feedforward network is represented as:
[0040]
[0041] in, The output characteristics of the feedforward network; This is the output feature matrix after the aforementioned residual connections and layer normalization; , These are the trainable weight matrices for the two-layer network; , These are the trainable bias terms for the two-layer network; It is a non-linear activation function;
[0042] The initial prediction results are obtained from the output layer:
[0043]
[0044] in, This is the initial prediction result. , These are the trainable weight matrix and bias term of the output layer, respectively; This is the temporal feature vector output by the Transformer encoder.
[0045] In a preferred embodiment of the present invention, the Kalman filter causal recursive residual correction includes: updating the residual state estimate based on the current time-predicted residual, and using the updated residual state estimate to correct the prediction result at the next time, so that the current time information only affects the prediction result at subsequent time, without modifying the current time and the already output prediction result.
[0046] According to an embodiment of the present invention, a grid search method is used to optimize the Transformer prediction model parameters and Kalman filter parameters, wherein the Kalman filter parameters include system noise parameter Q and measurement noise parameter R.
[0047] Furthermore, statistical analysis was performed on the prediction results corresponding to different combinations of system noise parameter Q and measurement noise parameter R, and a parameter heatmap was constructed to determine the optimal range of values for system noise parameter Q and measurement noise parameter R.
[0048] Furthermore, RMSE, MAE, R², MAPE, P95AE, and WAPE were used to evaluate the prediction results, with P95AE used to characterize the error distribution features in the high error range to reflect the robustness of the model.
[0049] Conditional gating constraint features are used to characterize the well open and shut-in states of an oil well; when the oil well is in the shut-in state, the predicted value at the corresponding time is constrained to zero; when the oil well is in the open state, the model prediction results are retained.
[0050] A second aspect of the present invention provides a computer device including a memory and a processor, wherein the memory includes a program for a Transformer oil well production prediction method based on gating constraints and Kalman filtering, and the program for the Transformer oil well production prediction method based on gating constraints and Kalman filtering is executed by the processor.
[0051] A third aspect of the present invention provides a computer-readable storage medium including a Transformer oil well production prediction method program based on gating constraints and Kalman filtering. When the Transformer oil well production prediction method program based on gating constraints and Kalman filtering is executed by a processor, it implements the steps of the Transformer oil well production prediction method based on gating constraints and Kalman filtering.
[0052] The technical solution of the present invention has the following advantages compared with the prior art:
[0053] Using forward linear interpolation to fill in missing values improves the continuity and availability of time series data.
[0054] The mutual information method is used to filter input features, which reduces the adverse effects of redundant features on model training and prediction.
[0055] By constructing conditional gating constraint features and explicitly incorporating the well opening and closing states into the prediction process, unreasonable non-zero prediction results during the well closing stage can be effectively suppressed.
[0056] By using the Transformer model to model multivariate time series data, the ability to represent long-term dependencies and complex nonlinear trends is enhanced.
[0057] Kalman filtering is used to correct the prediction residuals using pure causal recursive residuals, making the filtering process more consistent with the applicable premise of linear Gaussian filtering, effectively reducing error accumulation, and improving prediction stability, robustness and online correction capability.
[0058] By using grid search and heatmap analysis of parameters, the rationality and interpretability of the selection of Transformer model and Kalman filter parameters are improved.
[0059] By using multiple metrics, including P95AE, the model's performance in the high error range can be more comprehensively characterized, demonstrating stronger robustness.
[0060] After repeated field tests and verifications, the single-step full-process prediction of this invention can achieve millisecond-level online inference. The algorithm runs stably, has high computational efficiency, and has small fluctuations, meeting the engineering requirements for real-time prediction in certain industrial scenarios. Attached Figure Description
[0061] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, some of the drawings in the following description are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0062] Figure 1 This is a schematic diagram of the overall process of an embodiment of the present invention;
[0063] Figure 2 This is a schematic diagram of the conditional gating constraint and Kalman filter causal recursive residual correction process in an embodiment of the present invention;
[0064] Figure 3 This is a comparison chart of the actual values and the Transformer predicted values in the embodiments of the present invention;
[0065] Figure 4 This is a comparison chart of the actual values and the predicted values of Transformer and Kalman filters in the embodiments of the present invention;
[0066] Figure 5 This is a comprehensive comparison chart of the actual values and different prediction results in the embodiments of the present invention;
[0067] Figure 6 This is a residual distribution diagram of an embodiment of the present invention;
[0068] Figure 7This is a schematic diagram of the QR parameter heatmap of an embodiment of the present invention. Detailed Implementation
[0069] To better understand the above-mentioned objectives, features, and advantages of the present invention, the present invention will be further described in detail below with reference to specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0070] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and therefore the scope of protection of the invention is not limited to the specific embodiments disclosed below.
[0071] Example 1
[0072] See Figures 1-5 As shown, this invention proposes a Transformer oil well production prediction method based on gating constraints and Kalman filtering, specifically including:
[0073] Step 1: Data Acquisition;
[0074] The original data in the application embodiment comes from the publicly available dataset of the Volve oil field in the Norwegian North Sea. The selected well is well 15 / 9-F-12, and its historical production data is obtained. The historical production data includes date, well opening time, average downhole pressure, average downhole temperature, average tubing pressure differential, average annular pressure, choke size percentage, average wellhead pressure, average wellhead temperature, pressure difference on both sides of the choke ring, and well production.
[0075] Step 2: Data preprocessing;
[0076] Historical production data is sorted in ascending order by date. For missing values in the data, forward linear interpolation is used to complete them, maintaining the continuity of the time series trend. For boundary missing values that still exist after forward linear interpolation, further processing using forward or backward completion methods can be employed.
[0077] Step 3: Mutual information feature selection;
[0078] The mutual information value between the preprocessed candidate input features and the target output is calculated, and preliminary sorting and filtering are performed based on the magnitude of the mutual information value. The mutual information can be represented as:
[0079]
[0080] Where X is the input feature, Y is the target output, p(x, y) is the joint probability distribution, and p(x) and p(y) are the marginal probability distributions, respectively.
[0081] In this embodiment, the determination of the final input feature set considers not only the mutual information evaluation results but also the significance of feature engineering, feature redundancy, and model prediction performance. Furthermore, well opening time is used to characterize the well's operating status and condition-gated constraint features are constructed; well production is retained as an autoregressive historical production feature. Finally, well opening time, average tubing pressure differential, average wellhead pressure, pressure differential across the choke ring, choke size percentage, average downhole pressure, average downhole temperature, and well production are selected as the model input features.
[0082] Step 4: Construction of conditional gating constraint features;
[0083] The well operation status is used to construct conditional gating constraint characteristics. Specifically, based on the well opening time, a binary state characteristic IS_ON is constructed: when the well opening time is greater than zero, IS_ON=1, indicating that the well is in the well opening state; when the well opening time is equal to zero, IS_ON=0, indicating that the well is in the well shut-in state.
[0084] The binary state feature IS_ON is added to the model input feature set and used together with other continuous input features as the input to the prediction model. During the model output stage, state constraints are applied to the prediction results based on the IS_ON corresponding to the current prediction sample. When IS_ON is less than a preset threshold, the well is determined to be in a shut-in state, and the predicted production at the corresponding time is set to zero. When IS_ON is greater than or equal to the preset threshold, the original model prediction output is retained.
[0085] Preferably, the preset threshold is 0.5.
[0086] Step 5: Data partitioning and time series sample construction;
[0087] The preprocessed data is divided into training, validation, and test sets in chronological order, with a ratio of 8:1:1. Subsequently, continuous input features are normalized, and normalization parameters are fitted only based on the training set. These normalization parameters are then used to transform the training, validation, and test sets respectively to prevent future information leakage.
[0088] A sliding time window method is used to construct time series samples. Let the time window length be T (30 in this embodiment), and the input feature dimension be d. Then, time series input samples are constructed starting from time t:
[0089]
[0090] The corresponding prediction target is the target output at time t+T:
[0091] The time-series input samples contain only historical information before the target time, and do not contain information about the target time and subsequent times.
[0092] In this embodiment, the time window slides forward one time step along the time axis each time. That is, the output on day 31 is predicted using the data from day 1 to day 30, the output on day 32 is predicted using the data from day 2 to day 31, and so on, until all samples are constructed.
[0093] Step 6: Transformer Initial Prediction;
[0094] The constructed time series samples are input into the Transformer prediction model to obtain the initial prediction results of oil well production.
[0095] The Transformer prediction model includes an input mapping layer, a position encoding layer, a multi-head self-attention layer, a feedforward network layer, a residual connection layer, a normalization layer, and an output layer. During training, an early stopping mechanism and Dropout regularization are set to reduce the risk of overfitting.
[0096] The mapping process of the input mapping layer is represented as follows:
[0097]
[0098] in, This represents the feature matrix output by the input mapping layer; , These are the trainable weight matrix and bias term of the input mapping layer, respectively; This represents the preprocessed oil well production time series feature matrix;
[0099] Position encoding is performed based on the position encoding layer to obtain:
[0100]
[0101] in, This represents the encoded feature matrix after injecting location information; Represents the temporal position encoding matrix;
[0102] The multi-head self-attention is calculated as follows:
[0103] ;
[0104] The final output of the bullish self-attention is ;
[0105] in, This is the output feature matrix of the single-head self-attention operation; , , These represent the query matrix, key matrix, and value matrix, respectively, all of which are obtained by linear mapping from the encoded feature matrix Z′. Key matrix The transpose of the matrix, Let K be the feature dimension of the key matrix. This is the scaling factor; It is a normalized exponential function;
[0106] The feedforward network is represented as:
[0107]
[0108] in, The output characteristics of the feedforward network; This is the output feature matrix after the aforementioned residual connections and layer normalization; , These are the trainable weight matrices for the two-layer network; , These are the trainable bias terms for the two-layer network; It is a non-linear activation function;
[0109] The initial prediction results are obtained from the output layer:
[0110]
[0111] in, This is the initial prediction result. , These are the trainable weight matrix and bias term of the output layer, respectively; This is the temporal feature vector output by the Transformer encoder.
[0112] Step 7: State constraint processing;
[0113] The initial prediction results are state-constrained based on the IS_ON feature of the last historical time step (t-1) of the model input sequence, according to conditional gating constraints. Let the state determination threshold be... Preferably, when the last historical moment of the input sequence When the well is determined to be in a shut-in state, the following constraints are applied:
[0114]
[0115] When the input sequence is the last historical moment When the well is determined to be in an open state, the original model output is retained:
[0116]
[0117] in, This is the initial prediction result. This is the prediction result after state constraints.
[0118] Step 8: Kalman filter causal recursive residual correction;
[0119] The prediction results after adding state constraints are corrected for causal recursive residuals using Kalman filtering.
[0120] In this embodiment, a one-dimensional univariate standard Kalman filter is used to perform causal recursive correction on the residuals. In this scenario, the state transition matrix A=1, the observation matrix H=1, and the identity matrix I=1.
[0121] Let the prediction residual at the current time be:
[0122] t=0,1,…,n−1
[0123] in, This represents the actual output at the current moment. The result is the prediction after state constraints, and n is the total number of time steps in the prediction sequence.
[0124] The residual state is predicted as follows:
[0125] t=1,2,…,n−1
[0126]
[0127] Among them, among them, Let be the prior residual state at time t. Let Q be the prior residual covariance, and let Q be the system noise covariance. Let be the posterior estimate of the residual at time t-1;
[0128] Let be the posterior error covariance at time t-1.
[0129] The Kalman gain is:
[0130]
[0131] in, To measure the noise covariance.
[0132] The residual status is updated as follows:
[0133]
[0134] Covariance updated to:
[0135]
[0136] When \(t + 1\lt n\), the predicted result for the next moment is corrected using the updated residual state estimate:
[0137] , \(t = 0,1,\cdots,n - 2\);
[0138] In the above correction process, first, the residual between the true value of the oil well production at the current moment and the model prediction result after constraint is calculated, and this residual is selected as the estimation object of the Kalman filter. After fitting by the main model and being limited by the constraint conditions, the deterministic trend, non - linear working condition disturbances, and invalid fluctuations outside the constraints in the production sequence have been removed. The obtained residual is closer to a stationary Gaussian distribution with zero mean and approximate linearity, which can better meet the applicable premise of the Kalman filter and help ensure the convergence of the filter iteration and the optimal estimation effect.
[0139] In the above correction process, the prediction residual information at the current moment is only used to update the residual state, and the prediction result for subsequent moments is corrected based on the updated residual state estimate. This process does not involve correcting the prediction result at the current moment or the already output moments, so it belongs to causal recursive residual correction.
[0140] Through ADF unit root test verification in the present invention, the ADF statistic of the residual sequence is - 4.9743, which is less than the critical value - 3.4552 corresponding to the 1% significance level, and the P - value is 0.000025. The original hypothesis of the existence of a unit root is rejected at the 1% significance level, and it is a highly stationary time series, which can fully meet the application requirements of the Kalman filter; while for the original production prediction sequence output by the Transformer model, the ADF statistic is - 1.0164, which is much greater than the critical value - 3.4549 corresponding to the 1% significance level, and the P - value is 0.747222. The original hypothesis of the existence of a unit root cannot be rejected at the conventional significance level, and it belongs to a non - stationary time series. If directly used as the input of the Kalman filter, it does not meet the core applicable premise of its linear stationary system and is likely to affect the stable performance of the optimal estimation effect of the Kalman filter.
[0141] The overall time complexity of the present invention is \(O(n)\). The Kalman filter performs recursive update on one - dimensional residuals, and the single - step calculation is at the constant level \(O(1)\), with high overall computational efficiency and good real - time performance.
[0142] Step 9: Parameter optimization and heat map analysis;
[0143] In this embodiment, the relevant parameters of the Transformer prediction model and Kalman filter are optimized. For the Transformer prediction model, a grid search method is used to optimize its hyperparameters, which include batch size, learning rate, number of encoding layers, number of attention heads, hidden layer dimension, feedforward network dimension, and Dropout regularization parameters. Based on the search results, further fine-tuning is performed near the optimal parameter range to determine the final parameter configuration of the Transformer prediction model.
[0144] For Kalman filtering, a logarithmic scale grid search method is used to optimize the system noise parameter Q and the measurement noise parameter R. The prediction effect under different combinations of Q and R parameters is statistically analyzed, and a QR parameter heatmap is plotted to determine the optimal region of Kalman filter parameters. Based on this, the parameter combinations near the optimal region are further tested and locally fine-tuned to obtain better parameter values.
[0145] Furthermore, in this embodiment, some candidate hyperparameters for the Transformer prediction model's grid search are set as follows: batch size is set to [16, 32, 64], and learning rate is set to […]. , , The number of encoding layers is set to [2, 4], the number of attention heads is set to [2, 3], the hidden layer dimension is set to [32, 64], the feedforward network dimension is set to [64, 128], the Dropout regularization parameter is set to [0.1, 0.2, 0.3], the initial value of the maximum number of iterations is set to 300, and the number of early stopping threshold iterations is 50.
[0146] Furthermore, the Kalman filter parameter candidate settings are as follows: the search range for both the system noise parameter Q and the measurement noise parameter R is set to... Between 10 and 25, 25 candidate values are selected at logarithmic intervals within the range. This constructs a QR parameter search grid. Subsequently, a grid search method is used to traverse different parameter combinations. For different operating conditions, it is not limited to a single index, but can be selected from multiple evaluation indices. In this embodiment, a parameter heatmap is drawn based on the evaluation index RMSE to determine the preferred region of Kalman filter parameters.
[0147] Furthermore, since the optimal values of the Kalman filter parameters Q and R are affected by the Transformer prediction results, it is preferable to optimize the Kalman filter parameters after the Transformer prediction model parameters have been tuned.
[0148] Furthermore, in this embodiment, through grid search and local fine-tuning, the final parameters are selected as batch size 63 and learning rate. The system has 2 encoding layers, 2 attention heads, 64 hidden layer dimensions, 128 feedforward network dimensions, 64 fully connected layer neurons, Dropout regularization of 0.22, an initial maximum number of iterations of 500, an early stopping threshold of 125 iterations, a system noise parameter Q of 0.046, and a measurement noise parameter R of 0.21.
[0149] Step 10: Evaluation of prediction results;
[0150] In this embodiment, RMSE, MAE, R², MAPE, P95AE, and WAPE are selected as evaluation indicators for prediction performance. Among them, RMSE, MAE, and R² are commonly used indicators to evaluate the overall prediction error and goodness of fit of the model; MAPE and WAPE are used to evaluate the model's prediction performance from the perspective of relative error. WAPE still has excellent computational stability and distortion resistance when the actual output sample contains zero or extremely small values; P95AE is used to reflect the error distribution in the high error sample interval, thereby evaluating the robustness of the model under complex fluctuating conditions, high error samples, and local mutation samples.
[0151] After inverse normalization, the aforementioned indicators are used to comprehensively evaluate the prediction results:
[0152] Root Mean Square Error (RMSE):
[0153]
[0154] Mean Absolute Error (MAE):
[0155]
[0156] Coefficient of determination R²:
[0157]
[0158] Mean Absolute Percentage Error (MAPE):
[0159]
[0160] 95th percentile absolute error P95AE:
[0161] Let the absolute error be:
[0162] The 95th percentile absolute error P95AE is the absolute error of all... The 95th percentile is used to characterize the distribution characteristics of the high error interval.
[0163] Weighted Absolute Percentage Error (WAPE):
[0164]
[0165] This represents the total number of time-series samples in the test set, i.e., the total duration of oil well production time-series data used in the performance evaluation. This represents the actual production value of the oil well at time i. Let be the final predicted value of the well production at time i. This is the arithmetic mean of the actual production values of all oil wells in the test set.
[0166] Step 11: Validation of Results;
[0167] Historical production data from well 15 / 9-F-12 in the Volve oilfield of the Norwegian North Sea were selected for validation. The samples were divided into training, validation, and test sets in chronological order, with a ratio of 8:1:1. To verify the stability and reliability of the method, three different random number seeds (42, 50, and 68) were used. Experiments were conducted under the same conditions, and the initial prediction results of the Transformer were compared with the prediction results after causal recursion correction using Kalman filtering. All evaluation results were calculated based on the actual production after inverse normalization and are the average and standard deviation of the three random number seeds.
[0168] Transformer 30.0125±3.6431 19.1792±2.6517 0.8963±0.0243 13.0530%±1.5763 % 58.7935±7.5520 10.1702%±1.4061% Transformer and Kalman Filter 22.4704±1.1103 9.7232±0.2621 0.9423±0.0057 6.3901%±0.0882% 42.7638±2.3226 5.1559%±0.1390%
[0169] Experimental results show that the uncorrected Transformer model has an average RMSE of 30.0125, an average R² of 0.8963, an average MAPE of 13.0530%, an average P95AE of 58.7935, and an average WAPE of 10.1702% under three random seeds. After Kalman filtering and causal recursion correction, the average RMSE decreases to 22.4704, the average R² increases to 0.9423, the average MAPE decreases to 6.3901%, the average P95AE decreases to 42.7638, and the average WAPE decreases to 5.1559%.
[0170] As can be seen, compared with the uncorrected Transformer model, the Kalman filter causal recursive correction method proposed in this invention reduces the RMSE, MAE, MAPE, P95AE and WAPE indices, while improving R². It also shows more stability under three sets of random number seeds, indicating that the method of this invention can effectively improve the accuracy and stability of oil well production prediction.
[0171] Among them, P95AE decreased from 58.7935 to 42.7938, indicating that the method of the present invention has better suppression ability in the high error range and can improve the robustness of the model under complex fluctuation conditions.
[0172] Combination Figures 3 to 5 The comparison chart of prediction results shows that while the uncorrected Transformer model can basically track the overall trend of oil well production, it still exhibits certain deviations in local fluctuation ranges and the later low-production phase. Using the method of this invention, the overall deviation between the predicted curve and the actual curve is reduced, and the ability to track actual production changes in multiple fluctuation ranges is improved, thus addressing the problems of unstable predictions and large local deviations in single-model predictions. Simultaneously, this invention enhances the adaptability of the prediction results to actual operating conditions through conditional gating constraints, ensuring that the predicted output remains consistent with the actual production state under special operating conditions such as well shut-in and production stoppages. Specifically, around mid-August 2016, the target oil well entered a production stoppage state, and the actual production dropped to zero. This invention uses conditional gating constraints to restrict the prediction results for this period, constraining the predicted value to zero within this production stoppage range, thereby ensuring the consistency between the prediction results and the actual operating conditions.
[0173] Through lightweight architecture design and residual correction strategy optimization, this invention achieves an average single-step full-process prediction time of only 42.88ms and a maximum time of no more than 59.39ms after 100 actual tests. While ensuring prediction accuracy, it has high computational efficiency and certain industrial real-time performance and practicality.
[0174] Combination Figure 6 As shown in the residual distribution diagram, the residual distribution of the method of the present invention is more concentrated near zero, and the curve is close to a bell curve, indicating that the prediction error has further converged and the overall stability of the model has been improved.
[0175] Combination Figure 7 The QR parameter heatmap diagram shown is illustrated in this embodiment. The optimal combination of noise parameter Q and measurement parameter R is around 0.046 and 0.21, respectively.
[0176] In summary, this invention can effectively reduce prediction errors and improve model stability and robustness in oil well production prediction tasks, and has certain engineering application value.
[0177] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0178] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to the above embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0179] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A Transformer oil well production prediction method based on gating constraints and Kalman filtering, characterized in that, Includes the following steps: Obtain historical production data of the target oil well, preprocess the historical production data of the target oil well, and obtain preprocessed historical production data. Extract feature information from preprocessed historical production data, select features based on set conditions, and construct conditional gating constraint feature information that characterizes the operating status of oil wells; The selected features and conditional gating constraint features are constructed into time series samples in chronological order and then normalized to obtain the normalized result information. Input the normalized result information into the preset Transformer prediction model to obtain the initial prediction result information of oil well production; Based on the conditional gating constraint features, the initial prediction result of the oil well production is subjected to state constraints to obtain the state-constrained prediction result. The prediction residual value is obtained based on the prediction residual between the actual observation value at the current time and the prediction result after state constraints; The predicted residual value is recursively estimated using Kalman filtering to obtain the residual state estimate. The residual is then corrected based on the residual state estimate to obtain the final oil well production prediction result.
2. The Transformer oil well production prediction method based on gating constraints and Kalman filtering according to claim 1, characterized in that, Obtain historical production data from the target oil well, and preprocess the historical production data to obtain preprocessed historical production data, specifically including: Obtain historical production data of the target oil well, including date, well opening time, average downhole pressure, average downhole temperature, average tubing pressure differential, average annular pressure, choke size percentage, average wellhead pressure, average wellhead temperature, pressure difference across the choke ring, and oil well production. The historical production data of the target oil well is format-validated to remove duplicate data and missing fields. The missing fields are filled in using the forward linear interpolation method to obtain the completed historical production data. Analyze the completed historical production data based on outlier identification methods, and analyze the differences in the completed data. The missing fields are adjusted based on the imputation difference values to obtain the preprocessed historical production data.
3. The Transformer oil well production prediction method based on gating constraints and Kalman filtering according to claim 1, characterized in that, The mutual information method is used to calculate the mutual information value between candidate input features and target output. Based on the mutual information value, the candidate input features are initially sorted and filtered. The mutual information is represented as: ; Where X is the input feature, Y is the target output, p(x, y) is the joint probability distribution, and p(x) and p(y) are the marginal probability distributions, respectively.
4. The Transformer oil well production prediction method based on gating constraints and Kalman filtering according to claim 3, characterized in that, The Transformer prediction model includes an input mapping layer, a position encoding layer, a multi-head self-attention layer, a feedforward network layer, a residual connection layer, a normalization layer, and an output layer, and sets an early stopping mechanism and Dropout regularization during training.
5. The Transformer oil well production prediction method based on gating constraints and Kalman filtering according to claim 1, characterized in that, The historical production data is divided into a training set, a validation set, and a test set in chronological order, with a ratio of 8:1:
1. The training set, validation set, and test set are each subjected to transformation processing. The data transformation processing includes normalizing continuous input features, fitting normalization parameters based on the training set, and using the normalization parameters to transform the training set, validation set, and test set respectively.
6. The Transformer oil well production prediction method based on gating constraints and Kalman filtering according to claim 5, characterized in that, The normalized result information is input into the preset Transformer prediction model to obtain the initial prediction result information of oil well production, specifically including: The mapping process of the input mapping layer is represented as follows: in, This represents the feature matrix output by the input mapping layer; , These are the trainable weight matrix and bias term of the input mapping layer, respectively; This represents the preprocessed oil well production time series feature matrix; Position encoding is performed based on the position encoding layer to obtain: in, This represents the encoded feature matrix after injecting location information; Represents the temporal position encoding matrix; The multi-head self-attention is calculated as follows: ; The final output of the bullish self-attention is ; in, This is the output feature matrix of the single-head self-attention operation; , , These represent the query matrix, key matrix, and value matrix, respectively, all of which are obtained by linear mapping from the encoded feature matrix Z′. Key matrix The transpose of the matrix, Let K be the feature dimension of the key matrix. This is the scaling factor; It is a normalized exponential function; The feedforward network is represented as: in, The output characteristics of the feedforward network; This is the output feature matrix after the aforementioned residual connections and layer normalization; , These are the trainable weight matrices for the two-layer network; , These are the trainable bias terms for the two-layer network; It is a non-linear activation function; The initial prediction results are obtained from the output layer: in, This is the initial prediction result. , These are the trainable weight matrix and bias term of the output layer, respectively; This is the temporal feature vector output by the Transformer encoder.
7. The Transformer oil well production prediction method based on gating constraints and Kalman filtering according to claim 6, characterized in that, The Kalman filter causal recursive residual correction includes: updating the residual state estimate based on the current time-predicted residual, and using the updated residual state estimate to correct the prediction result at the next time, so that the current time information only affects the prediction result at subsequent times, without modifying the current time and the already output prediction result.
8. A computer device comprising a memory and a processor, the memory including a program for a Transformer oil well production prediction method based on gating constraints and Kalman filtering, the program for the Transformer oil well production prediction method based on gating constraints and Kalman filtering being executed by the processor.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a Transformer oil well production prediction method program based on gating constraints and Kalman filtering. When the Transformer oil well production prediction method program based on gating constraints and Kalman filtering is executed by a processor, it implements the steps of the Transformer oil well production prediction method based on gating constraints and Kalman filtering as described in any one of claims 1 to 7.