Nonlinear filtering method based on self-attention and lattice trajectory piecewise linear approximation
By embedding the self-attention mechanism network in the Kalman filtering algorithm, and combining the linear approximation and batch estimation algorithm of grid trajectory sharding, the accuracy and robustness of the Kalman filter in the case of high noise and model mismatch are solved. Problem, more efficient state estimation and more stable training process are achieved.
Patent Information
- Application Number
- CN202410758052.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-06-13
AI Technical Summary
The prior art is inadequate in the case of high noise and model mismatch, and the accuracy and robustness of the Kalman filter are insufficient, and the recurrent neural network performs poorly in capturing long-distance dependencies in time series data, and the training process is unstable. and inefficient.
The nonlinear filtering method based on linear approximation of self-attention and grid trajectory slicing is used to estimate the state of the nonlinear system model through the Kalman filtering algorithm embedded in the self-attention mechanism network. The nonlinear system is approximated by the grid trajectory sharding linear approximation method, and a pre-trained data set is constructed through batch estimation algorithm to simplify the training process.
The accuracy and robustness of nonlinear system state estimation are improved, the instability and inefficiency in the recursive nested training process of recurrent neural networks are avoided, and the parallel processing capability of the self-attention mechanism network is enhanced.
Smart Images

Figure CN118611625B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a nonlinear filtering method based on self-attention and grid trajectory piecewise linear approximation, and belongs to the technical field of filtering. Background Art
[0002] In the framework of modern control theory, the state variables of the control system cannot be directly measured or are affected by noise. Therefore, state estimation becomes an important part of control system design, among which Kalman filter and extended Kalman filter are widely used. However, in practical applications, the performance of these model-based filters depends largely on the accuracy of the system model and noise parameters. Once these parameters are not set correctly, the accuracy of the Kalman filter will drop significantly.
[0003] In order to solve the above problems, many scholars have improved the Kalman filter by combining data-driven methods, which are mainly divided into two categories: external combination and internal nesting. The external combination category mainly uses neural networks to identify system parameters or perform fusion filtering with Kalman filters. The neural network and the Kalman filter are relatively independent. In the prior art, for example, Gao et al. proposed an adaptive Kalman filter navigation algorithm, which adaptively estimates the process noise covariance matrix through reinforcement learning, thereby improving the robustness and accuracy of navigation. For another example, Tian et al. proposed a battery state estimation method based on a deep neural network, in which the output of the deep neural network and the output of the ampere-hour counting method are combined through a linear Kalman filter. This method makes the battery state estimation more accurate and rapid. The internal nesting category mainly embeds the neural network into the Kalman filter framework. The neural network is used to replace a part of the traditional Kalman filter, and the neural network is closely combined with the Kalman filter. For another example, Jung et al. proposed a memory Kalman filter, which overcomes the Markov property and linear limitations of the traditional Kalman filter by learning the transfer probability density function through a long short-term memory network. For example, Revach et al. combined the Kalman filter with the gated recurrent unit and proposed KalmanNet, in which the gated recurrent unit was used to estimate the Kalman gain. This filtering method performs better on model mismatch and nonlinear problems. It directly embeds the neural network into the Kalman filter framework, retaining interpretability while combining the powerful fitting ability of the neural network. It is a relatively novel and promising research direction.
[0004] However, most of the current methods use long short-term memory networks or gated recurrent units to learn time series data. These recurrent neural networks perform poorly in capturing the long-distance dependencies of time series data, and their recursive nested training process is unstable and inefficient. Summary of the invention
[0005] The present invention provides a nonlinear filtering method based on self-attention and grid trajectory piecewise linear approximation, aiming to solve at least one of the technical problems existing in the prior art.
[0006] The technical solution of the present invention relates to a nonlinear filtering method, and the method according to the present invention comprises the following steps:
[0007] S100, obtaining a nonlinear system model and an estimated value of its initial state;
[0008] S200, estimating the state of the nonlinear system model through a Kalman filter algorithm embedded in a self-attention mechanism network;
[0009] The training of the self-attention mechanism network includes the following steps:
[0010] S210, constructing a state trajectory according to the nonlinear system model and the initial state estimation value, and approximating the original nonlinear model using a lattice trajectory piecewise linear approximation method to obtain a lattice piecewise approximate model of the system;
[0011] S220, constructing training, validation, and test data sets according to the nonlinear system model and randomly generated noise, and constructing a pre-training data set from the training data set according to the system's lattice sharding approximation model and batch estimation algorithm;
[0012] S230, batch pre-training the simplified self-attention mechanism network according to the pre-training data set, saving the network weights, and then embedding it into the Kalman filter framework to perform end-to-end formal training using the training data set.
[0013] Further, the step S10 includes:
[0014] The nonlinear system model is expressed as follows:
[0015] x k =f(x k-1 )+w k (2a)
[0016] y k =h(x k )+v k (2b)
[0017] w k ~N(0,Q),v k ~N(0,R) (2c)
[0018] In the formula, f and h represent the nonlinear state transition and observation function respectively, x k ∈R m represents the state vector at time k, y k ∈Rn represents the observed value at time k; w k and v k They represent the process noise and observation noise at time k respectively, and their covariance matrices are Q and R respectively.
[0019] Further, the step S210 includes:
[0020] S211, through the initial state estimation And f(x) obtains a state trajectory X containing L state points Tra ={x i |i=1,…,L};
[0021] S212, select all state points as linearization points, and at each state point x i A first-order Taylor expansion is used to construct the linear segment;
[0022] S213: construct a lattice piecewise linear model using the linear segments to approximate the original nonlinear system.
[0023] in,
[0024]
[0025] In the formula, x represents the state point, and Represents the linearization point x i The linear segments constructed for f(x) and h(x) are constructed at the same time. The lattice trajectory piecewise linear model f is constructed. LTPWL (x)≈f(x) and h LTPWL (x)≈h(x).
[0026] Further, in step S220,
[0027] Each piece of training data includes the true value of the state and the system output within a period of time. The i-th piece of training data can be expressed as follows:
[0028] D i ={(x j ,y j})|j=1,…,L} (7)
[0029] In the formula, x j and j Represent the true value of the state and the observed output at time j respectively;
[0030] The training data set contains N pieces of data, and each piece of data contains L time steps of data.
[0031] Further, in step S220,
[0032] Each of the pre-training data includes the input feature X of the network Input and the state truth value x j , the i-th pre-training data can be expressed as follows:
[0033]
[0034] In the formula, the input feature X of the network input ={Δx k-s ,…,Δx k-1 ,Δy k-s+1 ,…Δy k}, where Δ represents the forward update difference, represents the new information; the pre-training dataset is represented as
[0035] Further, the step S220 includes:
[0036] S221, at time k, through the real state x of the system k Find the linear segment corresponding to the grid slice linear model at the current moment and Will Added as a bias term to the system observation y k To obtain the system model under the grid trajectory piecewise linear model, it is expressed as follows:
[0037]
[0038] S222. Using a batch estimation algorithm to obtain a posterior estimate of the state variables to construct pre-training data.
[0039] Further, in step S200,
[0040] The self-attention mechanism network includes two linear embedding layers, a position encoding layer, a simplified attention layer, two fully connected layers and a linear mapping layer;
[0041] The step S230 includes: given an input feature Δx k-1 ∈R (B,s,m) and Δy k ∈R (B,s,n) , mapped by two linear embedding layers and concatenated through one of the fully connected layers to produce the input sequence Then, after adding position information through the position encoding layer, it is sent to the simplified attention layer to capture the dependencies between sequence elements, and the input sequence passes through another fully connected layer of multi-layer perceptron MLP to capture nonlinear characteristics. Finally, the features are mapped to the predicted value K through the linear mapping layer. k∈R (B,m*n) Output after that; where B represents the batch size, s represents the size of the sliding window, m represents the dimension of the system state, and n represents the dimension of the system output.
[0042] Further, in step S230,
[0043] The Kalman filter framework is trained end-to-end through error back propagation;
[0044] Among them, the loss function It is expressed as follows:
[0045]
[0046] Where, all trainable parameters of the self-attention mechanism network are θ;
[0047] Among them, the derivative relationship between the square error and the Kalman gain is expressed as follows:
[0048]
[0049] Among them, the intermediate x j represents the true value of the state at time j; represents the a posteriori estimate of the system state at time j; represents the prior estimate of the system state at time k; Indicates new information; represents the transpose of information; T represents the transpose matrix, K k represents the Kalman gain.
[0050] The technical solution of the present invention also relates to a computer-readable storage medium on which program instructions are stored, and the above-mentioned method is implemented when the program instructions are executed by a processor.
[0051] The technical solution of the present invention also relates to a nonlinear filtering system based on self-attention and grid trajectory piecewise linear approximation, wherein the device comprises a computer device, which contains the above-mentioned computer-readable storage medium.
[0052] The beneficial effects of the present invention are as follows:
[0053] The present invention provides a nonlinear filtering method based on self-attention and grid trajectory piecewise linear approximation. Under the conditions of high noise interference and model mismatch, compared with the traditional model-based Kalman filtering algorithm and the existing Kalman filtering algorithm combined with a neural network, the Kalman filtering embedded with the self-attention mechanism proposed by the present invention can obtain a better filtering effect, and can improve the accuracy and robustness of state estimation for nonlinear systems.
[0054] The present invention designs a pre-training method based on a lattice trajectory piecewise linear model and a batch estimation algorithm, which improves the problems of instability and low efficiency of the recursive training process when using a recurrent neural network, and fully utilizes the parallel processing capability of the self-attention mechanism network. The pre-training data is constructed by batch estimating the value of the system state within a period of time, thereby avoiding the recursive nesting process of the Kalman filter, and can effectively solve the problems of instability and low efficiency of the training process when the network gradually processes the state sequence data in a recursive manner.
[0055] The present invention proposes a Kalman filter algorithm embedded with a self-attention mechanism, which can better capture the dependencies between state sequences, thereby obtaining better filtering performance. The process is simplified by using a single matrix X to simultaneously perform multiplication of the attention distribution and the output sequence, and by reducing the number of parameters, the simplified method improves efficiency without losing the model's ability to capture key dependencies. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 Schematic diagram of an embodiment of a nonlinear system model according to the method of the present invention.
[0057] Figure 2 Schematic diagram of the structure of the traditional self-attention mechanism according to the method of the present invention.
[0058] Figure 3 Schematic diagram of the simplified attention mechanism according to the method of the present invention.
[0059] Figure 4 Schematic diagram of the structure of the self-attention mechanism network according to the method of the present invention.
[0060] Figure 5 Schematic diagram of the structure of the Kalman filter framework according to the method of the present invention. DETAILED DESCRIPTION
[0061] The concept, specific structure and technical effects of the present invention will be clearly and completely described below in combination with the embodiments and drawings to fully understand the purpose, scheme and effect of the present invention.
[0062] It should be noted that, unless otherwise specified, when a feature is referred to as being "fixed" or "connected" to another feature, it may be directly fixed or connected to another feature, or it may be indirectly fixed or connected to another feature. The singular forms "a", "said" and "the" used herein are also intended to include the plural forms, unless the context clearly indicates otherwise. In addition, unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art. The terms used in this specification are intended only to describe specific embodiments and are not intended to limit the invention. The term "and / or" used herein includes any combination of one or more of the related listed items.
[0063] It should be understood that, although the term first, second, third etc. may be adopted to describe various elements in the present disclosure, these elements should not be limited to these terms. These terms are only used to distinguish the same type of elements from each other. For example, without departing from the scope of the present disclosure, the first element may also be referred to as the second element, and similarly, the second element may also be referred to as the first element. The use of any and all examples or exemplary language ("for example", "such as" etc.) provided herein is only intended to better illustrate embodiments of the present invention, and unless otherwise required, the scope of the present invention will not be limited.
[0064] Reference Figure 1 In some embodiments, the nonlinear filtering method based on self-attention and grid trajectory piecewise linear approximation according to the present invention comprises at least the following steps:
[0065] S100, obtaining a nonlinear system model and an estimated value of its initial state;
[0066] S200, estimating the state of the nonlinear system model through a Kalman filter algorithm embedded in a self-attention mechanism network;
[0067] Among them, the training of the self-attention mechanism network includes the following steps:
[0068] S210, constructing a state trajectory according to the nonlinear system model and the initial state estimation value, and approximating the original nonlinear model using a lattice trajectory piecewise linear approximation method to obtain a lattice piecewise approximate model of the system;
[0069] S220, constructing training, validation, and test data sets according to the nonlinear system model and randomly generated noise, and constructing a pre-training data set from the training data set according to the system's lattice sharding approximation model and batch estimation algorithm;
[0070] S230, batch pre-training the simplified self-attention mechanism network according to the pre-training data set, saving the network weights, and then embedding it into the Kalman filter framework to perform end-to-end formal training using the training data set.
[0071] In order to improve the accuracy and robustness of state estimation for nonlinear systems, the present invention proposes a nonlinear filtering method based on self-attention and lattice trajectory piecewise linear approximation, which estimates the state variables in the control system by combining the self-attention mechanism network with the Kalman filter. In addition, a network pre-training method is designed based on the lattice trajectory piecewise linear approximation and batch estimation algorithm.
[0072] Specifically, the present invention proposes a Kalman filter algorithm embedded with a self-attention mechanism, called AtKF (Attention Kalman Filter), which can better capture the dependencies between state sequences, thereby obtaining better filtering performance. In addition, the present invention designs a pre-training method based on a grid trajectory piecewise linear model and a batch estimation algorithm, which improves the instability and inefficiency of the recursive training process when using a recurrent neural network, while making full use of the parallel processing capabilities of the self-attention mechanism network.
[0073] Among them, inspired by KalmanNet, the present invention uses the self-attention mechanism in the transformer network to replace the gated recurrent unit, and sends the state feature sequence in a historical time window into the network, so as to improve the accuracy and robustness of the estimation by more comprehensively capturing the dependencies between state sequences. In addition, the present invention designs a parallel pre-training method, which constructs pre-training data by batch estimating the value of the system state within a period of time, thereby avoiding the recursive nesting process of Kalman filtering, and can effectively solve the problem of unstable and inefficient training process when the network gradually processes the state sequence data in a recursive manner. Batch estimation of nonlinear systems requires them to be piecewise linearized first.
[0074] At the same time, for the lattice piecewise linear model, it is a method for representing piecewise linear functions analytically and compactly. Because of its algebraic characteristics of max and min operations on affine functions, it is named the lattice piecewise linear model. For example, Tarela et al. summarized several representation methods of lattice piecewise linear functions. For another example, Ovchinnikov gave a proof that the lattice piecewise linear model can represent any piecewise linear function, and Xu et al. gave a method for removing redundant terms and redundant literals from the lattice piecewise linear model. For another example, Wang et al. proposed a lattice trajectory piecewise linear model method for approximating nonlinear systems with lattice piecewise linear models. The present invention uses the lattice trajectory piecewise linear model to piecewise linearize the nonlinear system, and then generates pre-training data through a batch estimation algorithm to perform non-nested training on the network.
[0075] In some application embodiments, the discrete-time nonlinear system of the present invention is shown in the following equation (2):
[0076] x k =f(x k-1 )+w k (2a)
[0077] y k =h(x k )+v k (2b)
[0078] w k ~N(0,Q),v k ~N(0,R) (2c)
[0079] Where f and h represent the nonlinear state transition and observation function, respectively, k ∈R m represents the state vector at time k, y k ∈R n Represents the observed value at time k. k and v k They represent the process noise and observation noise at time k respectively, both are assumed to be Gaussian white noise, and their covariance matrices are Q and R respectively.
[0080] Specific implementation of step S210
[0081] The present invention constructs a state trajectory according to a nonlinear system model and an initial state estimate, and approximates the original nonlinear system model using a lattice trajectory piecewise linear approximation method to obtain a lattice piecewise approximate model of the system. The lattice trajectory piecewise linear model is a lattice piecewise linear model approximation method for a nonlinear system, which can simultaneously complete the linearization of a nonlinear system and the construction of a lattice piecewise linear model.
[0082] The present invention first selects a set of linearization points along the state trajectory of the system, and constructs a linear segment at each linearization point, and finally uses these linear segments to construct a lattice piecewise linear model to approximate the original nonlinear system. Figure 1 As an example of a nonlinear function shown in FIG. 1 , it is assumed that the present invention selects linearization points x1, x2 and x3 along the state trajectory (here, the x-axis), and constructs corresponding linear segments l1, l2 and l3 at these linearization points. Then, the present invention can construct a lattice model of the form of formula (3) to represent the piecewise linear function composed of these three linear segments, so as to complete the approximation of the original nonlinear function.
[0083]
[0084] Comparing formula (3) with the traditional piecewise form (4), we can see that the expression of the grid piecewise linear model is more compact and does not need to consider the interval range of x.
[0085]
[0086] The general form of the grid-piece linear model is shown in formula (5):
[0087]
[0088] Where N is the base area The number of is a polyhedron that satisfies and Indicates that in the base area is greater than or equal to the linear segment l i The index set of the affine function of (x), namely
[0089] In some application examples, see Figure 1 The piecewise linear function shown has three base regions, so N = 3. Taking the linear segment l1 as an example, in the base region The affine functions greater than or equal to l1 are l1 and l2, and then l1 and l2 are minimized to construct a "term" in the lattice piecewise linear model, where the term min{l1,l2} is obtained. The terms for the linear segments l2 and l3 can be constructed in the same way, which respectively obtain the terms min{l1,l2} and min{l1,l3}, and then the maximum value of these three terms is taken to obtain the final lattice piecewise linear model. Among them, when evaluating the lattice piecewise linear model, the present invention only needs to substitute the value of the independent variable x, without considering the interval range of the independent variable like the traditional piecewise form. In addition, the present invention can conveniently find the linear segment l representing the current system dynamics through comparison operations. i .
[0090] Specifically, the present invention performs a grid trajectory piecewise linear approximation on the nonlinear system (see Formula 2), which is achieved by initial state estimation And f(x) obtains a state trajectory X containing L state points Tra ={x i |i=1,…,L}, select all state points as linearization points, and at each state point x i A first-order Taylor expansion is used to construct a linear segment, as shown in formula (6).
[0091]
[0092] Among them, x represents the state point, and Represents the linearization point x i The linear segments constructed for f(x) and h(x) are constructed to construct the lattice trajectory piecewise linear model f LTPWL (x)≈f(x) and h LTPWL (x)≈h(x).
[0093] Specific implementation of step S220
[0094] The training data set of the present invention is constructed by a nonlinear system (Formula 2) and randomly generated noise. Each piece of training data contains the true value of the state and the system output within a period of time. Assuming that the training data set contains N pieces of data, each piece of data contains L time steps of data, then the i-th piece of training data can be expressed as Formula (7):
[0095] D i ={(x j ,y j})|j=1,…,L} (7)
[0096] where x j and j Represent the true state value and observed output at time j respectively. The training data set can be expressed as The validation and test datasets can be constructed similarly.
[0097] See Figure 4 As shown, the input feature X of the network input ={Δx k-s ,…,Δx k-1 ,Δy k-s+1 ,…Δy k},in represents the forward update difference, If the network is directly embedded in the Kalman filter for training, the network needs to be trained in the form of nested recursion on the entire trajectory. The present invention uses the grid trajectory piecewise linear model and batch estimation algorithm of the nonlinear system constructed in step S210 to directly estimate the state within a period of time and construct a pre-training data set, thereby avoiding the nested recursive training form.
[0098] Specifically, each pre-training data includes the input feature X of the network Input and the state truth value x j , the i-th pre-training data can be expressed as formula (8):
[0099]
[0100] The pre-training dataset can be expressed as
[0101] After the lattice trajectory piecewise linear approximation model of the nonlinear system is constructed in step S210, the pre-training dataset can be constructed through the training dataset. Specifically, for any state trajectory, taking time k as an example, the present invention uses the system real state x k Find the linear segment corresponding to the grid slice linear model at the current moment and Among them will be Added as a bias term to the system observation y k Then the system model under the grid trajectory piecewise linear model can be summarized as shown in formula (9):
[0102]
[0103]
[0104] The grid trajectory piecewise linear model is equivalent to a linear time-varying system, and the system dynamics at each moment depends on the system state at the current moment. The batch estimation algorithm for discrete-time linear time-varying systems can adopt the existing technical methods, so that for the state trajectory from time 1 to time k, the definition is
[0105] Then the posterior estimate of the state variable satisfies equation (10):
[0106]
[0107] make You can get the posterior estimate of the state variables and then construct the pre-training data.
[0108] Specific implementation of step S230
[0109] See also Figure 4 As shown in Figure 1, the self-attention mechanism network of the present invention consists of two linear embedding layers, a position encoding layer, a simplified attention layer, two fully connected layers, and a linear mapping layer. Given an input feature Δx k-1 ∈R (B,s,m) and Δy k ∈R (B,s,n) , which is concatenated through two linear embedding layers to produce the input sequence Then, after adding position information through the position encoding layer, it is sent to the simplified attention layer to capture the dependencies between sequence elements. The input sequence is processed through a multi-layer perceptron (MLP) to better capture nonlinear characteristics, and finally the linear mapping layer maps the features to output, i.e., the predicted value K of the Kalman gain. k ∈R (B,m*n) Here B represents the batch size, s represents the size of the sliding window, m represents the dimension of the system state, and n represents the dimension of the system output.
[0110] See also Figure 2 The traditional self-attention mechanism converts the input sequence {x1,x2,…,x n} into query, key, and value matrices. For each sequence element x i , which computes the dot product with all sequence elements to form an attention distribution that represents the dependencies between elements through a softmax function. This attention distribution is then multiplied with the value to produce the output sequence v1,v2,…,v n , where each element v i Both integrate information from the entire sequence to ensure that each element reflects the influence of other elements, overcoming distance limitations.
[0111] The simplified attention mechanism used in this invention is a simplified version of the traditional self-attention mechanism, see Figure 3 As shown. The process is simplified by using a single matrix X to perform multiplication of the attention distribution and the output sequence at the same time. Considering the small amount of sequence data and the simple distribution of features in the Kalman filter process, the use of a traditional full multi-head attention mechanism may increase the difficulty of training and lead to overfitting. The simplified method of the present invention by reducing the number of parameters can improve efficiency without losing the ability of the model to capture key dependencies.
[0112] Specifically, the present invention first uses the pre-training dataset to perform independent batch pre-training on the self-attention mechanism, and uses the trained network parameters as the initial point, see Figure 5 As shown, it is then embedded in the Kalman filter framework for end-to-end online training. In some specific embodiments, the present invention sets all trainable parameters of the self-attention mechanism network as θ. In order to train the self-attention mechanism network, the present invention defines the loss function As shown in formula (11):
[0113]
[0114] And because the square error and the Kalman gain of the network output have a derivative relationship as shown in formula (12):
[0115]
[0116] Among them, the intermediate x j represents the true value of the state at time j; represents the a posteriori estimate of the system state at time j; represents the prior estimate of the system state at time k; Indicates new information; represents the transpose of information; T represents the transpose matrix, K k represents the Kalman gain. Therefore, the entire Kalman filter framework can be trained end-to-end through error back propagation.
[0117] In some embodiments, see Figure 5 The overall Kalman filter framework of the present invention is consistent with the traditional Kalman filter algorithm. At each moment, the nonlinear system model is used to recursively infer the system state and predict the system output. Specifically, taking moment k as an example, and represent the prior estimate of the system state and the predicted value of the system output, respectively. Represents the posterior estimate of the system state, and the self-attention mechanism network is embedded in it to predict the Kalman gain K k Since the Kalman gain K k Equivalent to the process noise w k and observation noise v k The proportional coefficient of the predicted value of the large and small fusion model and the system observation value. The method based on the self-attention mechanism network of the present invention fits the noise characteristics in the system by better capturing the dependency of the sequence data, thereby obtaining a better estimation effect.
[0118] A specific embodiment is used here for illustration.
[0119] Specifically, the two-dimensional nonlinear system is shown as follows:
[0120] x k =α·sin(β·x k-1+φ)+δ+w k , (1a)
[0121] y k =a·(b·x k +c) 2 +v k . (1b) The system parameters are shown in the following table:
[0122]
[0123] In the formula, Para s Represents the parameters of the system, Para m The parameters of the model, the state transfer function (1a) and the observation function (1b) of the system are all nonlinear. k ∈R m and k ∈R n Represent the system state and observed output respectively, w k and v k represent process noise and observation noise respectively, both are assumed to be Gaussian distributions, and their covariance matrices are denoted as Q and R.
[0124] The present invention utilizes a nonlinear system and a state initial value x0=[0.1,0.1] T The training, validation, and test data sets were generated under random noise. The training data set contains N = 1000 data, each containing L = 10 time steps. The validation data set contains N = 100 data, each containing L = 10 time steps. The test data set contains N = 200 data, each containing L = 100 time steps. In addition, in order to generate pre-training data, the same nonlinear system and initial state value were used to generate a state trajectory containing 10 time steps under noise-free conditions to construct the grid trajectory piecewise linear model of the system. Regarding the training parameters, the sliding window size s = 4, the batch size is 50, and the learning rate is 1e-4 of the self-attention mechanism network. For the AtKF algorithm, the present invention pre-trains 50 generations and formally trains 20 generations. For fairness, for KalmanNet, the present invention trains 70 generations. All training processes are performed on a GTX-3090 GPU. The present invention compares the estimation results of AtKF with traditional extended Kalman filter EKF (Extended Kalman Filter), unscented Kalman filter UKF (Unscented Kalman Filter), particle filter PF (Particle Filter) and KalmanNet.
[0125] Under different noise interference, by setting the weight coefficient q 2 =r2 For different values, simulation experiments are carried out for different noise levels, where the covariance matrices of process noise and observation noise are set to Q = q 2 I and R = r 2 I, the model used by the filter is consistent with the real system. The estimated error MSE (Mean Squared Error) of different filters is shown in the following table:
[0126] Table 1 Estimation error (MSE) of two-dimensional nonlinear model at different noise levels
[0127]
[0128] When the noise is large, AtKF shows superior performance compared to other filters. Although the performance of AtKF is similar to that of PF under low noise, AtKF significantly exceeds PF under high noise. In particular, when r 2 =16, the MSE of AtKF is 16.6712, which is 30% better than PF, thanks to the ability of the attention mechanism network to compensate for noise by more comprehensively capturing the dependencies between sequences. In addition, the results of the present invention are generally used in KalmanNet, thanks to the fact that the present invention obtains a better network initial weight through pre-training. These results show that the Kalman filter embedded in the neural network can better fit the noise characteristics in the system, thereby improving the estimation results. In addition, the network based on the attention mechanism achieves better estimation performance by more comprehensively capturing the dependencies between sequences.
[0129] In addition, the present invention tests the estimation effect under different noise levels when the model is mismatched. There are differences between the real system and the model used by the filter. The estimation error MSE of different filters is shown in the following table:
[0130] Table 2 Estimation error (MSE) of two-dimensional nonlinear model under model mismatch
[0131]
[0132] It can be seen that the Kalman filter embedded in the neural network is generally better than the traditional model-based filtering method, and the AtKF based on the self-attention mechanism is better than the KalmanNet based on the gated recurrent unit, which further shows that AtKF has stronger robustness and accuracy, and also shows that the self-attention mechanism network can better capture the dependencies between state sequences.
[0133] The above is only a preferred embodiment of the present invention. The present invention is not limited to the above implementation. As long as the technical effect of the present invention is achieved by the same means, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the scope of protection of the present invention. Within the scope of protection of the present invention, its technical scheme and / or implementation method may have various modifications and changes.
Claims
1. A nonlinear filtering method, characterized in that: Applied to a control system, the method comprises the following steps: S100, obtaining a nonlinear system model and an estimated value of its initial state; S200, estimating the state of the nonlinear system model through the Kalman filter algorithm embedded in the self-attention mechanism network; The training of the self-attention mechanism network includes the following steps: S210, constructing a state trajectory according to the nonlinear system model and the initial state estimation value, and approximating the original nonlinear model using a lattice trajectory piecewise linear approximation method to obtain a lattice piecewise approximate model of the system; S220, constructing training, validation, and test data sets according to the nonlinear system model and randomly generated noise, and constructing a pre-training data set from the training data set according to the system's lattice sharding approximation model and batch estimation algorithm; S230, batch pre-training the simplified self-attention mechanism network according to the pre-training data set, saving the network weights, and then embedding it into the Kalman filter framework to perform end-to-end formal training using the training data set. Wherein, the step S100 includes: The nonlinear system model is expressed as follows: x k =f(x k-1 )+w k y k =h(x k )+v k w k ~N(0,Q),v k ~N(0,R) In the formula, f and h represent the nonlinear state transition and observation function respectively, x k ∈R m represents the state vector at time k, y k ∈R n represents the observed value at time k; w k and v k They represent the process noise and observation noise at time k respectively, and their covariance matrices are Q and R respectively. Wherein, the step S210 includes: S211, through the initial state estimation And f(x) obtains a state trajectory X containing L state points Tra ={x i |i=1,…,L}; S212, select all state points as linearization points, and at each state point x i A first-order Taylor expansion is used to construct the linear segment; S213, constructing a lattice piecewise linear model using the linear segments to approximate the original nonlinear system; in, In the formula, x represents the state point, and Represents the linearization point x i The linear segments constructed for f(x) and h(x) are constructed at the same time. The lattice trajectory piecewise linear model f is constructed. LTPWL (x)≈f(x) and h LTPWL (x)≈h(x).
2. The method according to claim 1, characterized in that In the step S220, Each piece of training data includes the true value of the state and the system output within a period of time. The i-th piece of training data can be expressed as follows: D i ={(x j ,y j })|j=1,…,L} In the formula, x j and j Represent the true value of the state and the observed output at time j respectively; The training data set contains N data, and each data contains L time steps of data.
3. The method according to claim 2, characterized in that In the step S220, Each of the pre-training data includes the input feature X of the network Input and the state truth value x j , the i-th pre-training data can be expressed as follows: In the formula, the input feature X of the network input ={Δx k-s , …, Δx k-1 , Δy k-s+1 ,…Δy k }, where Δ represents the forward update difference, Δy k Represents information; the pre-training dataset is represented as 4. The method according to claim 1, characterized in that The step S220 includes: S221, at time k, through the real state x of the system k Find the linear segment corresponding to the grid slice linear model at the current moment and Will Added as a bias term to the system observation y k To obtain the system model under the grid trajectory piecewise linear model, it is expressed as follows: S222. Using a batch estimation algorithm to obtain a posterior estimate of the state variables to construct pre-training data.
5. The method according to claim 3, characterized in that: In the step S200, The self-attention mechanism network includes two linear embedding layers, a position encoding layer, a simplified attention layer, two fully connected layers and a linear mapping layer; The step S230 includes: given an input feature Δx k-1 ∈R (B,s,m) and Δy k ∈R (B,s,n) , mapped by two linear embedding layers and concatenated through one of the fully connected layers to produce the input sequence Then, after adding position information through the position encoding layer, it is sent to the simplified attention layer to capture the dependencies between sequence elements, and the input sequence passes through another fully connected layer of multi-layer perceptron MLP to capture nonlinear characteristics. Finally, the features are mapped to the predicted value K through the linear mapping layer. k ∈R (B,m*n) Output after that; where B represents the batch size, s represents the size of the sliding window, m represents the dimension of the system state, and n represents the dimension of the system output.
6. The method according to claim 5, characterized in that In the step S230, The Kalman filter framework is trained end-to-end through error back propagation; Among them, the loss function It is expressed as follows: Where, all trainable parameters of the self-attention mechanism network are θ; Among them, the derivative relationship between the square error and the Kalman gain is expressed as follows: Among them, the intermediate x j represents the true value of the state at time j; represents the a posteriori estimate of the system state at time j; represents the prior estimate of the system state at time k; Δy k To indicate information; represents the transpose of information; T represents the transpose matrix, K k represents the Kalman gain. 7 . A computer-readable storage medium having program instructions stored thereon, wherein the program instructions, when executed by a processor, implement the method according to any one of claims 1 to 6 .
8. A nonlinear filtering system based on self-attention and lattice trajectory piecewise linear approximation, characterized in that: include: A computer device comprising a computer readable storage medium according to claim 7.
Citation Information
Patent Citations
Liquid level instrument noise optimization method based on nonlinear fusion filtering
CN111756353A
Self-adaptive unscented Kalman filter state estimation method with noise estimator
CN111985093A