Neural Network Adaptive Control with Long Short-Term Memory
In this study, we propose a novel adaptive control architecture, which
provides dramatically better transient response performance compared to
conventional adaptive control methods. What makes this architecture unique is
the synergistic employment of a traditional, Adaptive Neural Network (ANN)
controller and a Long Short-Term Memory (LSTM) network. LSTM structures, unlike
the standard feed-forward neural networks, can take advantage of the
dependencies in an input sequence, which can contain critical information that
can help predict uncertainty. Through a novel training method we introduced,
the LSTM network learns to compensate for the deficiencies of the ANN
controller during sudden changes in plant dynamics. This substantially improves
the transient response of the system and allows the controller to quickly react
to unexpected events. Through careful simulation studies, we demonstrate that
this architecture can improve the estimation accuracy on a diverse set of
uncertainties for an indefinite time span. We also provide an analysis of the
contributions of the ANN controller and LSTM network to the control input,
identifying their individual roles in compensating low and high-frequency error
dynamics. This analysis provides insight into why and how the LSTM augmentation
improves the system's transient response. The stability of the overall system
is also shown via a rigorous Lyapunov analysis.
Emirhan Inanc, Yigit Gurses, Abdullah Habboush, Yildiray Yildiz, Anuradha M. Annaswamy
# Neural Network Adaptive Control with Long Short-Term Memory

###### Abstract

In this study, we propose a novel adaptive control architecture, which provides dramatically better transient response performance compared to conventional adaptive control methods. What makes this architecture unique is the synergistic employment of a traditional, Adaptive Neural Network (ANN) controller and a Long Short-Term Memory (LSTM) network. LSTM structures, unlike the standard feed-forward neural networks, can take advantage of the dependencies in an input sequence, which can contain critical information that can help predict uncertainty. Through a novel training method we introduced, the LSTM network learns to compensate for the deficiencies of the ANN controller during sudden changes in plant dynamics. This substantially improves the transient response of the system and allows the controller to quickly react to unexpected events. Through careful simulation studies, we demonstrate that this architecture can improve the estimation accuracy on a diverse set of uncertainties for an indefinite time span. We also provide an analysis of the contributions of the ANN controller and LSTM network to the control input, identifying their individual roles in compensating low and high-frequency error dynamics. This analysis provides insight into why and how the LSTM augmentation improves the system's transient response. The stability of the overall system is also shown via a rigorous Lyapunov analysis.

## I Introduction

Although Neural Networks (NN) is a fairly old concept [1], cheap and fast parallel computing unlocked their potential and lead to their current predominance in artificial intelligence and machine learning [2]. Computer vision and natural language processing are examples of fields that benefited greatly from these developments [3, 4]. Deep learning research produced derivatives of recurrent neural networks (RNN) such as long short-term memory (LSTM) [5] and gated recurrent unit [6], which are powerful structures for processing sequential data [7]. Reinforcement learning (RL) is another concept in machine learning that made advancements through applications of deep learning [8]. In RL, there exists a state that is updated with respect to an action selected by an agent that makes its choices based on observations to maximize its cumulative reward. A similarity can be drawn between control systems and RL where states, control inputs and feedback connections are parallel to states, actions, and observations, respectively. There are studies that take advantage of this fact to design RL-based controllers [9, 10].

The potential shown by earlier applications provides an incentive to utilize NN in adaptive control. The literature on this topic is extensive and well established [11, 12, 13, 14, 15]. Using an online-tuned feed-forward NN controller with adaptive update laws is proven to be stable and can successfully compensate the uncertainties [14]. However, if there are sudden changes in the uncertainty, the transient response can be oscillatory, which results in poor performance. This problem is addressed in [16] with the addition of external memory similar to a neural turing machine's (NTM) [17]. However, unlike the common practice in NTMs, a feed-forward network, instead of an RNN, is used in [17]. Feed-forward networks that have access to only the current state cannot take full advantage of the dependencies in a sequence. Instead, using a recurrent structure with internal memory can increase the capability of sequence estimation and thus improve performance [18].

To address the above mentioned issues, we propose a novel control architecture that consists of an Adaptive Neural Network (ANN) controller and an LSTM. The purpose of the LSTM is to take advantage of the long and short-term dependencies in the input sequence to improve the transient response of the controller. Specifically, we train the LSTM in such a way that it learns to compensate for the inadequacies of the ANN controller in response to sudden and unexpected uncertainty variations. Offline training in closed-loop systems is challenging since the trained element affects the system dynamics. This closed loop structure similarly exists in RL applications and is addressed by previous studies [19, 20]. Inspired by these methods, we train the LSTM in a closed-loop setting to predict and compensate for the undesired transient error dynamics. We demonstrate via simulations that thanks to its predictive nature, LSTM offsets high-frequency errors, and thus complements the ANN controller, where the latter helps with handling the low-frequency dynamics.

To summarize, the contribution of this paper is a novel adaptive control framework that provides enhanced transient performance compared to conventional approaches. This is achieved by making the traditional ANN controller work in collaboration with an LSTM network that is trained in the closed-loop system.

In Section II, we describe the formulation of the ANN controller. In Section III, the proposed LSTM augmentation and the training method are explained, together with a stability analysis. Simulation results are given in Section IV and a summary is given in Section V.
## II Problem Formulation

Consider the following plant dynamics

\[\dot{x}_{p}(t)= A_{p}x_{p}(t)+B_{p}(u(t)+f(x_{p}(t))), \tag{1a}\] \[y_{p}(t)= C_{p}^{T}x_{p}(t), \tag{1b}\]

where \(x_{p}(t)\in\mathbb{R}^{n_{p}}\) is the accessible state vector, \(u(t)\in\mathbb{R}^{m}\) is the plant control input, \(A_{p}\in\mathbb{R}^{n_{p}\times n_{p}}\) is a known system matrix, \(f(x_{p}(t)):\mathbb{R}^{n_{p}}\rightarrow\mathbb{R}^{m}\) is a state-dependent, possibly nonlinear, matched uncertainty, \(B_{p}\in\mathbb{R}^{n_{p}\times m}\) is a known control input matrix, and \(C_{p}\in\mathbb{R}^{n_{p}\times s}\) is a known output matrix, and \(y_{p}(t)\in\mathbb{R}^{s}\) is the plant output. Furthermore, it is assumed that the pair \((A_{p},B_{p})\) is controllable.

**Assumption 1**: _The unknown matched uncertainty \(f(x_{p}(t)):\mathbb{R}^{n_{p}}\rightarrow\mathbb{R}^{m}\) is continuous on a known compact set \(S_{p}\triangleq\{x_{p}(t):\|x_{p}(t)\|\leq b_{x}\}\subset\mathbb{R}^{n_{p}}\), where \(b_{x}\) is a known positive constant._

**Remark 1**: _The proposed method also applies for an unknown state matrix \(A_{p}\): Suppose that the plant dynamics are given by_

\[\dot{x}_{p}(t)=A_{u}x_{p}(t)+B_{p}(u(t)+f_{u}(x_{p}(t))), \tag{2}\]

_where \(A_{u}\in\mathbb{R}^{n_{p}\times n_{p}}\) is an unknown state matrix and \(f_{u}(x_{p}(t))\) is a state-dependent, possibly nonlinear, matched uncertainty. The dynamics (2) can be written in the form of (1) and for a known matrix \(A_{p}\), by defining \(f(x_{p}(t))\triangleq K_{u}x_{p}(t)+f_{u}(x_{p}(t))\), given that the matching condition \(A_{p}=A_{u}-B_{p}K_{u}\) is satisfied for some feedback gain \(K_{u}\in\mathbb{R}^{m\times n_{p}}\). This allows us to proceed assuming \(A_{p}\) is known, without loss of generality._

To achieve command following of a bounded reference input \(r(t)\in\mathbb{R}^{s}\), an error-integral state \(x_{e}(t)\in\mathbb{R}^{s}\) is defined as

\[\dot{x}_{e}(t)=r(t)-y_{p}(t), \tag{3}\]

which, when augmented with (1), yields the augmented dynamics

\[\dot{x}(t) =Ax(t)+B_{m}r(t)+B(u(t)+f(x_{p}(t))), \tag{4a}\] \[\dot{y}(t) =C^{T}x(t), \tag{4b}\]

where \(x(t)\triangleq[x_{p}(t)^{T},x_{e}(t)^{T}]^{T}\in\mathbb{R}^{n}\) is the augmented state, whose dimension is \(n\triangleq n_{p}+s\), and the system matrices \(A\), \(B_{m}\), \(B\) and \(C\) are

\[A \triangleq\begin{bmatrix}A_{p}&0_{n_{p}\times s}\\ -C_{p}^{T}&0_{s\times s}\end{bmatrix}\in\mathbb{R}^{n\times n}, \tag{5a}\] \[B_{m} \triangleq\begin{bmatrix}0_{n_{p}\times s}\\ -I_{s\times s}\end{bmatrix}\in\mathbb{R}^{n\times s},\] (5b) \[B \triangleq\begin{bmatrix}B_{p}\\ 0_{s\times m}\end{bmatrix}\in\mathbb{R}^{n\times m},\] (5c) \[C \triangleq\begin{bmatrix}-C_{p}^{T}&0_{s\times s}\end{bmatrix}^{T} \in\mathbb{R}^{n\times s}. \tag{5d}\]

A baseline state feedback controller is designed as

\[u_{bl}(t)=-Kx(t), \tag{6}\]

where \(K\in\mathbb{R}^{m\times n}\) is selected such that \(A_{m}\triangleq A-BK\) is Hurwitz. Then, a reference model is defined as

\[\dot{x}_{m}(t)=A_{m}x_{m}(t)+B_{m}r(t), \tag{7}\]

where \(x_{m}(t)\in\mathbb{R}^{n}\) is the state vector of the reference model.

Although the matched uncertainty \(f(x_{p}(t))\) is of unknown structure, Assumption 1 implies that it can be approximated by a multi-layer neural network in the following form

\[f(x_{p}(t))=W^{T}\bar{\sigma}(V^{T}\bar{x_{p}}(t))+\varepsilon(x_{p}(t)), \tag{8}\]

such that

\[\|\varepsilon(x_{p}(t))\|\leq\varepsilon_{N},\qquad\forall x\in S, \tag{9}\]

respectively, where the NN reconstruction error vector \(\varepsilon(x_{p}(t))\) is unknown, but bounded by a known constant \(\varepsilon_{N}>0\) in the domain of interest \(S_{p}\subset\mathbb{R}^{n_{p}}\). Such a bound depends on the number of hidden neurons \(n_{h}\) and the weight matrices of the neural network \(W\) and \(V\). The following assumption is necessary and is standard in the literature.

**Assumption 2**: _The unknown ideal weights \(W\) and \(V\) are bounded by known positive constants such that \(\|V\|_{F}\leq V_{M}\) and \(\|W\|_{F}\leq W_{M}\)._

The input to the NN and the output of the hidden layer is given by

\[\bar{x}_{p}(t) \triangleq\begin{bmatrix}x_{p}(t)^{T}&1\end{bmatrix}^{T}\in \mathbb{R}^{n_{p}+1}, \tag{10a}\] \[\bar{\sigma}(V^{T}\bar{x}_{p}(t)) \triangleq\begin{bmatrix}\sigma(V^{T}\bar{x}_{p}(t))&1\end{bmatrix}^ {T}\in\mathbb{R}^{n_{h}+1}, \tag{10b}\]

where the nonlinear activation function \(\sigma(.):\mathbb{R}^{n_{h}}\rightarrow\mathbb{R}^{n_{h}}\) can be either sigmoid or tanh. Note that \(x_{p}(t)\) and \(\sigma(V^{T}\bar{x}_{p}(t))\) are augmented with unity elements to account for hidden and outer layers biases, respectively. For the convenience of notation, we drop the overbar notation and write (8) as

\[f(x_{p}(t))=W^{T}\sigma(V^{T}x_{p}(t))+\varepsilon(x_{p}(t)), \tag{11}\]

where the dimensions of the weight matrices are loosely defined as \(W\in\mathbb{R}^{n_{h}\times m}\) and \(V\in\mathbb{R}^{n_{p}\times n_{h}}\).

By defining the state tracking error as

\[e(t)\triangleq x(t)-x_{m}(t), \tag{12}\]

the control objective is to make \(e(t)\) converge to zero while keeping all system signals bounded, with minimal transients. To achieve this, we use the control input

\[u(t)=u_{bl}(t)+u_{ad}(t)+u_{lstm}(t)+v(t), \tag{13}\]

where \(u_{bl}(t)\) is the baseline controller (6) that achieves the reference model dynamics (7) in the absence of uncertainty, \(u_{ad}(t)\) is an adaptive neural network (ANN) controller designed to compensate for the matched uncertainty \(f(x_{p}(t))\), and \(u_{lstm}\) is the output of a long short-term memory (LSTM) network. Furthermore, \(v(t)\) is a robustifying term, which is defined subsequently.

In this paper, we focus our attention on enhancing the transient response of the closed-loop system. Particularly, we propose the synergistic employment of a traditional ANN controller and an LSTM network to obtain superior performance compared to conventional approaches. In what follows, we detail each control term in (13).
### _Adaptive Neural Network Controller_

The adaptive neural network (ANN) controller is designed to compensate for the matched nonlinear uncertainty \(f(x_{p}(t))\), and is expressed as,

\[u_{ad}(t)=-\hat{f}(x_{p}(t)), \tag{14}\]

where \(\hat{f}(x_{p}(t))\) represents an estimate of \(f(x_{p}(t))\). Using (11), we define the estimate \(\hat{f}(x_{p}(t))\) as

\[\hat{f}(x_{p}(t))=\hat{W}^{T}(t)\sigma(\hat{V}^{T}(t)x_{p}(t)), \tag{15}\]

where \(\hat{V}(t)\in\mathbb{R}^{n_{h}\times n}\) is the input-to-hidden-layer weight matrix and \(\hat{W}(t)\in\mathbb{R}^{m\times n_{h}}\) is the hidden-to-output-layer weight matrix. These weights serve as estimates for the unknown ideal weights \(V\) and \(W\), respectively. Through proper use of Taylor series-based arguments [14], the weights are updated using the adaptive laws

\[\dot{\hat{W}} =F(\hat{\sigma}-\hat{\sigma}^{\prime}\hat{V}^{T}x_{p})e^{T}PB-F \kappa\|e\|\hat{W}, \tag{16a}\] \[\dot{\hat{V}} =Gx_{p}e^{T}PB\hat{W}^{T}\hat{\sigma}^{\prime}-G\kappa\|e\|\hat{V}, \tag{16b}\]

where \(F\in\mathbb{R}^{n_{h}\times n_{h}}\) and \(G\in\mathbb{R}^{n_{p}\times n_{p}}\) are symmetric positive definite matrices, serving as learning rates, \(\kappa>0\) is a scalar gain, and \(\hat{\sigma}\) and \(\hat{\sigma}^{\prime}\) are defined as

\[\hat{\sigma} \triangleq\sigma(\hat{V}^{T}(t)x_{p}(t)), \tag{17}\] \[\hat{\sigma}^{\prime} \triangleq\frac{d\sigma(z)}{dz}\bigg{|}_{z=\hat{V}^{T}(t)x_{p}(t)}.\]

Further, \(P\in\mathbb{R}^{n\times n}\) is the symmetric positive definite solution of the Lyapunov equation

\[A_{m}^{T}P+PA_{m}=-Q, \tag{18}\]

for some symmetric positive definite matrix \(Q\in\mathbb{R}^{n\times n}\).

### _Robustifying Term_

The usage of the baseline controller, ANN controller, and the robustifying term is sufficient to solve the adaptive control problem, as demonstrated in [14] for nonlinear robot arm dynamics. However, for a generic multi-input multi-output (MIMO) dynamical system with matched uncertainties (1), a difficulty arises from the control input matrix \(B\). A subsidiary contribution of this paper is a modified robustifying term \(v(t)\), which achieves the same stability results in [14], but for generic MIMO linear systems.

The robustifying term, \(v(t)\) (see (13)) is used to provide robustness against disturbances that arise from the high-order Taylor series terms [14]. For the considered MIMO linear plant dynamics, we propose a modified robustifying term which is defined as

\[v(t)=\begin{cases}0,&\text{if }\|B^{T}Pe\|=0\\ -\frac{B^{T}Pe}{\|B^{T}Pe\|}k_{z}\|e\|(\|\hat{Z}\|_{F}+Z_{M}),&\text{otherwise} \end{cases}, \tag{19}\]

with

\[k_{z}>C_{2}, \tag{20}\]

where \(Z_{M}\triangleq\sqrt{W_{M}^{2}+V_{M}^{2}}\), and matrices \(B\) and \(P\) are defined in the previous subsection, whereas \(e\) is given in (12). Furthermore, \(C_{2}\triangleq 2C_{\sigma^{\prime}}.Z_{M}\), where \(C_{\sigma^{\prime}}\) is a known upper bound for the absolute value of the sigmoid or tanh activation function derivatives, i.e. \(||\sigma^{\prime}(.)||\leq C_{\sigma^{\prime}}\), where \(\sigma^{\prime}(z)=d\sigma(z)/dz\).

In order not to diverge from the main contribution of the paper, we defer the derivation of the ANN controller and the proposed modified robustifying term to the Appendix. The following section introduces the main focus of this paper.

## III LSTM Network Design

We propose an LSTM network that works in coordination with the ANN controller to compensate for the uncertainties in the system, with better transients compared to conventional approaches. Combined usage of LSTM and ANN is not arbitrary. Indeed, in this section, we precisely define the separate roles of LSTM and ANN in the closed-loop system. The overall control architecture is given in Fig. 1. By taking the state tracking error \(e(t)=x(t)-x_{m}(t)\) as the input, the LSTM network computes the control input \(u_{lstm}(t)\), which is fed to the plant to compensate for the ANN controller deficiencies. The motivation behind the LSTM network is to improve the transient response of the system and achieve faster convergence by taking advantage of the sequence prediction capabilities of the LSTM architecture.

**Remark 2**: _LSTM network takes a sequence as an input and computes a sequence as the output. Hence, the sampling time of the network arises as a design parameter. The particular selection of the sampling time of the network is application dependent. A proper selection would match the sampling time at which the ANN is implemented, or it can be made larger to reduce the computational load. Nevertheless, the exact sampling time of the network is irrelevant in the proposed architecture since, as shown subsequently, the LSTM network can be trained offline to perform under a given sampling time._

**Remark 3**: _The LSTM input sequence \(e^{n}\) is generated from the continuous-time signal \(e(t)\) as_

\[e^{n}=e(nT),\quad n=0,1,2,\ldots \tag{21}\]

_where \(T>0\) is the sampling time of the LSTM. Furthermore, the output sequence of the LSTM \(u_{lstm}^{n}\) is converted to the continuous-time signal \(u_{lstm}(t)\) which accounts for the control input of the LSTM, where_

\[u_{lstm}(t)=u_{lstm}^{n},\ \ \text{for}\ nT\leq t<(n+1)T,\ \ n=0,1,2,\ldots \tag{22}\]

_LSTM is a Recurrent Neural Network (RNN), which, unlike a conventional neural network structure, can learn the long-term dependencies of a sequence. This is accomplished with an additional hidden state, a cell state, and gates that update the states in a systematic way. One cell of LSTM can be seen in Fig. 2._

In Fig. 2, \(e_{norm}^{n}\) is the normalized version of the input sequence \(e^{n}\), \(h^{n}\) is the hidden state, and \(c^{n}\) is the cell state. \(R,W\), and \(b\) are the recurrent weight matrices, input weight matrices, and bias vectors, respectively. \(\sigma_{g}\) denotes the gate activation function (sigmoid) and \(\sigma_{c}\) denotes the
state activation function (\(tanh\)). Subscripts \(f,g,i\), and \(o\) denote forget gate, cell candidate, input gate, and output gate, respectively. \(out_{f}^{n},\bar{c}^{n},out_{i}^{n}\), and \(out_{o}^{n}\) denote the output of the gate operations. The superscript \(n\) denotes the current time step and \(n-1\) is the previous time step.

a) Forget Gate: The forget gate decides the relevant information that the cell state should take from the hidden state and the input. This is achieved with a sigmoid activation function.

\[out_{f}^{n}=\sigma_{g}(W_{f}e_{norm}^{n}+R_{f}h^{n-1}+b_{f}). \tag{23}\]

b) Input Gate: The new information that is going to be added to the cell state is determined by the input gate and cell candidate. First, the hyperbolic tangent \(tanh\) activation function is used to determine which information is going to be added to the cell state. Then, a sigmoid function is used to determine how much of this information is going to be added. This process is given as

\[\bar{c}^{n}=\sigma_{c}(W_{g}e_{norm}^{n}+R_{g}h^{n-1}+b_{g}), \tag{24}\]

\[out_{i}^{n}=\sigma_{g}(W_{i}e_{norm}^{n}+R_{i}h^{n-1}+b_{i}). \tag{25}\]

c) Output Gate: The output gate decides how much of the cell state is going to be a part of the hidden state, using a sigmoid function as

\[out_{o}^{n}=\sigma_{g}(W_{o}e_{norm}^{n}+R_{o}h^{n-1}+b_{o}). \tag{26}\]

The cell state \(c\) is first erased using the forget gate \(out_{f}\), then new information is added through the input gate \(out_{i}\) and cell candidate \(\bar{c}\). This is achieved with the calculation

\[c^{n}=out_{f}^{n}\odot c^{n-1}+out_{i}^{n}\odot\bar{c}^{n}. \tag{27}\]

The gates mentioned above are used to determine the hidden state \(h\) and the cell state \(c\) for the next time step. The hidden state is updated using the output gate \(out_{o}\) and cell state \(c\) that is mapped between -1 and 1 using a \(tanh\) function as

\[h^{n}=out_{o}^{n}\odot\sigma_{c}(c^{n}). \tag{28}\]

A fully connected layer is utilized to obtain an \(m-\)dimensional output to match the dimension of the control input as

\[u_{lstm}^{n}=W_{fc}h^{n}+b_{fc}, \tag{29}\]

where \(W_{fc}\) and \(b_{fc}\) are the weight matrix and bias vector of the fully connected layer, respectively. Then, the control input \(u_{lstm}(t)\) is constructed from the LSTM output as shown in (22).

The ability to learn the dependencies within sequences helps the LSTM to predict the evolution of an unknown function. It is noted that in a typical ANN implementation, the speed of the response can be increased by increasing the adaptation rates, which may cause undesired oscillations. With LSTM augmentation, faster convergence is achieved without the need for large learning rates. The training and implementation details of LSTM are explained in the following subsections.

### _Training Method_

Since the LSTM network operates in a closed loop system, the system states and the "truth", which is the variable it is trying to estimate, are affected by the LSTM output (see Fig. 1). As the training progresses, the training data itself evolves with time, which allows the data to be used only once to train the network.

Our main philosophy to use LSTM is to compensate for the inadequacies of the conventional ANN controller: We know that ANN controllers are successful in compensating for the uncertainties asymptotically. However, adjusting their transient characteristics is not a trivial task. Instead of increasing the learning rates, LSTM provides better transients by actually predicting the type of transients and compensating accordingly. To achieve this, the goal for the LSTM is set to predict the estimation error of the ANN controller and compensate for this error. The estimation error of the ANN, or the deviation of the ANN controller input (14), \(\hat{f}(x_{p}(t))\), from the actual uncertainty, \(f(x_{p}(t))\), is given as

\[\tilde{f}(x_{p}(t))\triangleq f(x_{p}(t))-\hat{f}(x_{p}(t)). \tag{30}\]

Fig. 1: Block diagram of the proposed control architecture.

Fig. 2: Detailed sketch of an LSTM cell
The "truth" for the LSTM, or the desired signal for the LSTM to produce, is selected as

\[y(t)=-\tilde{f}(x_{p}(t)). \tag{31}\]

Therefore, LSTM provides a signal to the system that is an estimate of this truth, expressed as

\[u_{lstm}(t)=y(\hat{t}). \tag{32}\]

During training, an uncertainty \(f_{train}(x_{p}(t))\) is introduced to the closed loop system, and LSTM is expected to learn \(\tilde{f}_{train}(x_{p}(t))=f_{train}(x_{p}(t))-\hat{f}(x_{p}(t))\), where \(-\hat{f}(x_{p}(t))\) is the control signal produced by ANN. Apart from \(\hat{f}_{train}(x_{p}(t))\), LSTM uses the state-tracking error \(e(t)\), defined in (12), as its input (see Fig. 1). Every iteration of training affects the sequence that LSTM is trained on. This dynamic nature of training helps LSTM generalize to a set of functions that are not used in the training set. This is further emphasized in the Simulations Section.

Since there is no initial data set, the data needs to be collected by running the simulation with the initial LSTM weights. Since weight updates of the LSTM network also affect the system dynamics, new data needs to be collected after each episode of training. Before giving the LSTM output \(u_{lstm}\) to the system, a gain "\(k_{lstm}\)" scales \(u_{lstm}\). The role of this gain is to avoid an untrained LSTM network output from negatively affecting the system at the beginning of the training. \(k_{lstm}\) starts from 0 and approaches 1 as the number of training iterations increases, then stays at 1 for the rest of the training. The training loop can be seen in Fig. 3.

### _Normalization_

The inputs of the LSTM network are the components of the tracking error vector \(e\), defined in (12). In order to make sure that these components are on a similar scale, normalization needs to be performed. However, since an initial training data set does not exist, data needs to be collected first in order to acquire the parameters for normalization. For collecting the normalization parameters only, the simulation is run with \(f_{train}\) (see explanations after (32)), \(z\) number of times. A gain is uniformly sampled from \([0,1]\) in every simulation run, to scale \(f_{train}\). This random scaling is used only during the normalization parameter collection, not during training.The LSTM network output \(u_{lstm}\) is not injected to the system during this process. Within the collected data, the minimum, \(e_{i}^{min}\), and the maximum, \(e_{i}^{max}\), values, where "\(i\)" is used to refer the \(i^{th}\) component, of each component of the error vector, are utilized to obtain the normalized input parameters as

\[e_{norm_{i}}=(e_{i}-e_{i}^{min})/(e_{i}^{max}-e_{i}^{min}). \tag{33}\]

### _Stability Analysis_

The following theorem displays the stability properties of the overall architecture.

**Theorem 1**: _Consider the uncertain plant dynamics (1), subject to Assumptions 1 and 2, and the reference model (7). Let the control input be defined by (13), which consists of the baseline controller (6), the ANN controller defined by (14), (15) and (16), the robustifying term given in (19) and (20), and the LSTM controller explained in Section III. Then, given that \(x_{p}(0)\in S_{p}\) (see Assumption 1), the solution \((e(t),\tilde{W}(t),\tilde{V}(t))\) is uniformly ultimately bounded (UUB) and converges to a predefined compact set, where \(\tilde{V}(t)\triangleq V-\hat{V}(t)\) and \(\tilde{W}(t)\triangleq W-\hat{W}(t)\)._

The proof is deferred to the Appendix II.

## IV Simulations

In this section, the performance of the proposed control framework is examined using the short-period longitudinal flight dynamics. The short-period dynamics is given as [21]

\[\begin{bmatrix}\dot{\alpha}\\ \dot{q}\end{bmatrix}=\begin{bmatrix}\frac{Z_{q}}{m\ell}&1+\frac{Z_{q}}{mU}\\ \frac{M_{\alpha}}{J_{q}}&\frac{M_{\delta}}{J_{q}}\end{bmatrix}\begin{bmatrix} \alpha\\ q\end{bmatrix}+\begin{bmatrix}\frac{Z_{\delta}}{J_{q}}\\ \frac{M_{\delta}}{J_{q}}\end{bmatrix}(u+f(x_{p})), \tag{34}\]

where \(\alpha\) is the angle of attack (deg), \(q\) is the pitch rate (deg/s), \(u\) is the elevator deflection (deg), and \(f(x_{p})\) is a state dependent matched uncertainty. Elevator magnitude and rate saturation limits are set as \(+17/-23\) (deg) and \(+37/-37\) (deg/s) [22]. The commanded input is the pitch rate. \(Z_{\alpha}\), \(Z_{q}\), \(M_{\alpha}\), \(M_{q}\), \(Z_{\delta}\) and \(M_{\delta}\) are the stability and control derivatives.

The system matrices for a B-747 aircraft flying at the speed of 274 m/s at 6000 m altitude are given as [16]

\[A_{p}=\begin{bmatrix}-0.32&0.86\\ -0.93&-0.43\end{bmatrix},B_{p}=\begin{bmatrix}-0.02\\ -1.16\end{bmatrix},C_{p}=\begin{bmatrix}0&1\end{bmatrix}^{T}. \tag{35}\]

The augmented state vector is

\[x(t)=\begin{bmatrix}x_{1}(t)&x_{2}(t)&x_{3}(t)\end{bmatrix}^{T}, \tag{36}\]

where \(x_{1}\) is the angle of attack (rad), \(x_{2}\) is the pitch rate (rad/s) and \(x_{3}\) is the error-integral state (3). The input to the LSTM network is,

\[in_{lstm}(t)=\begin{bmatrix}e_{norm_{1}}(t)&e_{norm_{2}}(t)&e_{norm_{3}}(t) \end{bmatrix}^{T}, \tag{37}\]

where \(e_{norm_{1}}\), \(e_{norm_{2}}\), and \(e_{norm_{3}}\) are the components of the normalized version of the state tracking error vector (33).

The baseline controller (6) is an LQR controller with cost matrices \(Q_{LQR}=I\) and \(R_{LQR}=1\). The nonlinear uncertainty, \(f_{train}\) (see explanations after (32)) that the Long Short-Term Memory (LSTM) network (29) is trained on is defined as

Fig. 3: Flow chart of the training process
\[f_{train}(x)= \tag{38}\] \[\begin{cases}0.1x_{1}x_{2}&\text{if }0\leq t<5\\ \exp(x_{2})&\text{if }5\leq t<10\\ 2x_{1}x_{2}&\text{if }10\leq t<15\\ -0.1\cos(x_{1})&\text{if }15\leq t<20\\ 0.5(x_{1}x_{2})&\text{if }20\leq t<25\\ 0.1x_{1}x_{2}&\text{if }25\leq t<30\\ -x_{1}x_{2}(\sin(5x_{1}x_{2})+5\sin(x_{2}))&\text{if }30\leq t<35\\ x_{1}x_{2}(3\sin(2x_{1}x_{2})+2x_{1})&\text{if }35\leq t<45\\ -x_{1}x_{2}(2(\tan(2x_{1}x_{2})+x_{2}^{2})&\text{if }45\leq t<55\\ x_{1}x_{2}(x_{1}+x_{2})&\text{if }55\leq t\leq 60\\ \end{cases}.\]

The LSTM network is trained in the presence of an ANN controller (see Section II-A) that has a hidden layer consisting of four neurons. The learning rates in (16a) and (16b) are set as \(F=G=10\), and the Lyapunov matrix \(Q\) in (18) is set as \(Q=I\). The outer weights \((\hat{W})\) and bias \((\hat{b}_{w})\) are initialized to zero. The inner weights \((\hat{V})\) and biases \((\hat{b}_{v})\) are initialized randomly between 0 and 1. In the simulations, the robustifying gain \(k_{z}\) in (20) and scalar gain \(\kappa\) in (16a) and (16b) are set to 0.

The LSTM network contains one hidden layer with 128 neurons. The number of neurons in the input layer is 3 due to the number of state-tracking error components given as input to the network (37). Weights are initialized using Xavier Initialization [23]. The network is trained with stochastic gradient descent, and uses the Adam optimizer with a learning rate of 0.001, an L2 regularization factor of 0.0001, a gradient decay factor of 0.99, and a squared gradient decay factor of 0.999 [24]. The gradient clipping method is used with a threshold value of 1. The simulation step time is set to \(0.01\) s. The minibatch size is taken as 1. To cover both low and high-valued uncertainties, \(f_{train}\) is scaled by a parameter that took the alternating values of 0.2 and 2.

To obtain the normalization constants given in (33), the system is simulated 1000 times (\(z=1000\)), with the gain \(k_{f}\), (see Section III-B).

The loss function is chosen as Mean Squared Error (MSE) given as

\[L(y,\hat{y})=\frac{1}{N}\sum_{i=0}^{N}(y-\hat{y})^{2}, \tag{39}\]

where \(y\) and \(\hat{y}\) are defined in (31) and (32),and \(N\) is the number of data in the data set.

The proposed control framework is tested using the uncertainty defined as

\[f_{test}(x)=\begin{cases}0&\text{if }0\leq t<2\\ -0.1\exp(x_{1}x_{2})&\text{if }2\leq t<8\\ 0.5x_{2}^{2}&\text{if }8\leq t<12\\ 0.05\exp(x_{1}+2x_{2})&\text{if }12\leq t<20\\ -0.1\sin(0.05x_{1}x_{2})&\text{if }20\leq t<28\\ 0.1(x_{1}^{2}+x_{2}^{3})&\text{if }28\leq t<34\\ -0.1\sqrt{cos(x_{2})^{2}}&\text{if }34\leq t<40\\ -0.2\sin(x_{1}x_{2})&\text{if }40\leq t<49\\ 0.1(x_{1}x_{2})^{2}&\text{if }49\leq t<53\\ 0.5x_{2}&\text{if }53\leq t<60\\ 0.1(|x_{2}|^{x_{1}})&\text{if }60\leq t<67\\ -0.5\sin(x_{2})&\text{if }67\leq t<79\\ 0.01\exp(x_{1})&\text{if }79\leq t<86\\ -0.4x_{1}^{2}&\text{if }86\leq t<98\\ 0.2x_{2}^{2}&\text{if }98\leq t\leq 110\\ \end{cases}, \tag{40}\]

where the function is chosen to have different types of sub-functions with different time intervals, compared to the training uncertainty (38).

### _Controller performance in the presence of small uncertainty_

In this section, the effect of the proposed LSTM augmentation is examined using low-value uncertainties. For this purpose, \(f_{test}\) is scaled by 0.1 during the tests. Then, the tracking performance, tracking error, and control inputs of the closed-loop system are compared with and without LSTM augmentation.

Figures 4 and 5 show the tracking and tracking error curves, respectively. While the error plots demonstrate that LSTM augmentation dramatically reduces both the error magnitudes and the transient oscillations, the error values are small enough to be ignored compared to the absolute values of the states. Therefore, one can conclude that in this scenario

Fig. 4: Tracking performances with and without LSTM augmentation, in the presence of small uncertainty.
LSTM augmented and not-augmented cases show similar performances. In Fig. 6, the control inputs are presented. This figure shows that although LSTM augmentation does not affect the magnitude of the total control input in a meaningful manner, it provides damping to the oscillations by providing small but fast compensation to the introduced uncertainties. As we discussed above, since the ANN controller is already successful in compensating for the uncertainties, in this case, LSTM contribution is not prominent.

### _Controller performance in the presence of large uncertainty_

In this section, the effect of the proposed LSTM augmentation is examined in the presence of high-valued uncertainties, which is obtained by using the \(f_{test}\) as is.

Figures 7 and 8 demonstrate that LSTM augmentation substantially improves the transient response of the system, especially in pitch rate tracking, which is the output of interest (see (35)). It is noted that for this case, the same ANN controller and the LSTM network are used as in the small uncertainty case. Individual control inputs are shown in Fig. 9. In this case, unlike the low-uncertainty case, the LSTM augmentation makes the total control signal observably more agile, which is the main reason why excessive oscillations are prevented. This shows the LSTM network uses its memory to predict high-frequency changes in the system. It is noted that in this large uncertainty case the total control input is saturated. This is evident from Fig. 9, where the middle and the bottom sub-figures show the control signals created by the individual components of the overall controller, while the top sub-figure shows the total control input after saturation. The figure shows that the LSTM network produces large and very fast compensation,

Fig. 5: Tracking errors with and without LSTM augmentation, in the presence of small uncertainty.

Fig. 8: Tracking errors with and without LSTM augmentation, in the presence of large uncertainty.

Fig. 6: Control inputs in the presence of small uncertainty. Top: Total control input. Middle: The contributions of individual control inputs in the absence of LSTM. Bottom: The contributions of individual control inputs in the presence of LSTM.

Fig. 7: Tracking performances with and without LSTM augmentation, in the presence of large uncertainty.
which causes saturation. Here, the rate saturation can be problematic since it creates some oscillations in the total control signal (see the zoomed section, blue line, in the top sub-figure). Although the oscillations could be acceptable since they are short-lived, we believe that this issue can also be tackled by training the LSTM network with saturation information. We explain this solution in the next section.

### _Addressing Saturation_

To handle the saturation issue, we modified LSTM training by a) introducing the saturation limits to the plant dynamics during training, and b) informing the LSTM network whenever the control signal rate-saturates. The latter is achieved by providing additional input to the LSTM network as

\[u_{r}(t)=\begin{cases}0.1,&\text{if rate saturation is positive}\\ -0.1,&\text{if rate saturation is negative},\\ 0,&\text{otherwise}\end{cases} \tag{41}\]

The number of neurons in the input layer of the LSTM network is increased to 4 since the modified input to the LSTM network is

\[in_{lstm}(t)=\begin{bmatrix}e_{norm_{1}}(t)&e_{norm_{2}}(t)&e_{norm_{3}}(t)&u_{ r}(t)\end{bmatrix}^{T}. \tag{42}\]

Figure 10 shows the LSTM network contribution and the total control inputs, with and without rate-limit information during training. It is seen that the LSTM network uses the rate-limit information to provide a smoother compensation. Figures 11 and 12 show the tracking and tracking error curves, respectively, when the LSTM network is trained using the rate-limit information. It is seen that the performance of the proposed controller remains similar for the case when LSTM is not trained using the saturation information, although the pitch rate shows initial small jumps at the instances of uncertainty switches.

## V Summary

In this work, we propose a Long Short-Term Memory (LSTM) augmented adaptive neural network (ANN) con

Fig. 11: Tracking performances with LSTM trained without rate information and rate-limit-informed LSTM

Fig. 12: Tracking errors with LSTM trained without rate information and rate-limit-informed LSTM

Fig. 10: Control signals with an without rate-limit-informed LSTM. Top: Total control input. Bottom: LSTM network contribution to the total control input.

Fig. 9: Control inputs in the presence of high uncertainty. Top: Total control input. Middle: The contributions of individual control inputs in the absence of LSTM. Bottom: The contributions of individual control inputs in the presence of LSTM.
trol structure to improve the transient response of adaptive closed-loop control systems. We demonstrate that thanks to its time-series prediction capabilities, LSTM helps the ANN controller compensate for the uncertainties in a more agile fashion, resulting in dramatically improved tracking performance.
