# Switched Auto-Regressive Neural Control (S-ANC) for Energy Management of Hybrid Microgrids
## 2 Identifying the Distinctions between S-MPC and AR-RNN-LSTM
### Strategy
The following equation can mathematically represent an AR model of order q [32]:  
\[X(k)=c+\varphi(1)X(k-1)+\varphi(2)X(k-2)+\cdots+\varphi(q)X(k-q)+\varepsilon(k) \tag{2}\]  
where \(X(k)\) represents the value of the time series at time \(k\) in this equation. \(c\) is a constant term or an intercept. \(\varphi\) terms represent AR model coefficients. The coefficients or weights associated with the previous values of the time series are denoted by 1, 2, \(\ldots\), \(q\). \(X(k-1)\), and \(X(k-2)\), \(\ldots\), \(X(k-q)\) represent the lagged values of the time series at time points \(k-1\), \(k-2\), \(\ldots\), \(k-q\), respectively. \(\varepsilon(k)\) is the error term or random noise at time \(k\), representing the data portion the model cannot explain. RNN-LSTM is a neural network type ideally suited to processing sequential data. Unlike feed-forward neural networks, it has loops that allow information to be passed from one sequence step to the next. The approach for employing RNN-LSTM includes selecting an appropriate network architecture, an optimization algorithm for training the network, and an appropriate set of hyperparameters. RNN-LSTM is an extension of a feed-forward neural network with internal memory. RNN-LSTM is recurrent because it performs the same function for each data input, while the output of the current input is dependent on the previous computation. After the output has been generated, it is duplicated and sent back into the recurrent network [69]. For decision-making, it considers both the current input and the output from the previous input it learned. As shown in Figure 1b, the input vector of an LSTM network is \(u(k-1)\) at time step \(k\). \(y(k)\) represents the output vectors passed through the network between time steps \(k\) and \(k+1\). Three gates update and control the  
Figure 1: Block diagram of (**a**) S-MPC and (**b**) AR-LSTM. cell states in an LSTM network: the forget gate, input gate, and output gate. The gates are activated by hyperbolic tangent and sigmoid functions. Given new information that has entered the network, the forget gate determines which cell state information to forget. Given new input information, the input gate determines what new information will be encoded into the cell state. Using the output vector \(y(k)\), the output gate controls what information encoded in the cell state is sent to the network as input in the subsequent time step. In the mathematical modeling of RNN-LSTM, the current state can be expressed mathematically as  
\[x(k)=f(x(k-1),u(k)) \tag{3}\]  
where \(x(k)\) represents the current state, \(x(k-1)\) represents the previous state, and \(u(k)\) is the current input. Because the input neuron would have applied the transformations to the previous input, we now have the state of the previous input rather than the input itself. Each successive input is, therefore, referred to as a time step. Considering the simplest form of RNN-LSTM, where the activation function is tanz, the weight at the recurrent neuron is \(W_{xx}\), and the weight at the input neuron is \(W_{ux}\), we can write the equation for the state at time \(k\) as follows [69]:  
\[x(k)=tanz(W_{xx}x(k-1)+W_{ux}u(k)) \tag{4}\]  
In this instance, the recurrent neuron only considers the previous state. The equation may involve multiple such states for longer sequences. After calculating the final state, the output can be generated. Once the current state has been computed, we can then calculate the output state as follows [69]:  
\[y(k)=W_{xy}x(k) \tag{5}\]  
where \(y(k)\) is the output state and \(W_{xy}\) is the weight at the output state. This process is represented in Figure 2.  
First, it extracts \(u(0)\) from the input sequence and then outputs \(y(0)\), which, along with \(u(1)\), is the input for the subsequent step. Therefore, \(y(0)\) and \(u(1)\) are the inputs for the subsequent step. Similarly, \(y(1)\) from the subsequent step is the input for \(u(2)\) for the subsequent step, and so on. Consequently, it remembers the context throughout training.