# State Estimation for DC Microgrids using Modified Long Short-Term Memory Networks
## 3 Deep Learning Theoretical Background
### Long Short-Term Memory Network  
The LSTM network is a special type of RNN that is capable of learning long-term dependencies. The LSTM network structure allows it to learn the correlation between an output based on the current input and the previous calculated output. Hence, LSTM is good at processing and predicting sequential data such as time-series data. LSTM was developed by [PERSON] and [PERSON] in 1997 [30]. LSTM is modeled similarly to a chain of repeating modules of neural networks. LSTM does not suffer much from vanishing or exploding gradient problems, as with RNNs, because of the inclusion of the  
Figure 2: A multilayer perceptron (MLP) network. forget gate \(f_{t}\) and the dependency of the current cell state to the forget gate [24; 26]. Typically, LSTM is composed of a cell state, a forget gate, an input gate, and an output gate. Figure 3 illustrates a single LSTM unit, as discussed in [23; 24]. The important part of LSTM is the cell state \(C_{t}\), which acts as a memory that stores values for a period of time. The cell state \(C_{t}\) is regulated by three gates composed of a sigmoid function, which gives output values of between 0 and 1 [23; 24; 26]. At time step \(t\), the forget gate layer \(f_{t}\) would assess the input \(x_{t}\) and the previous step's hidden state \(h_{t-1}\) in order to decide which information would be forgotten from the cell state \(C_{t-1}\). A value between 0 and 1 would be assigned for each element in the cell state vector \(C_{t-1}\). The value 0 would indicate that the LSTM should forget the state, while the value 1 would mean that the state should be kept. The forget gate equation is written as  
\[f_{t}=\sigma\left(W_{f}h_{t-1}+U_{f}x_{t}+b_{f}\right). \tag{8}\]  
Afterward, the input gate would decide which cell unit would be updated by giving an output of between 0 and 1, using the equation  
\[i_{t}=\sigma\left(W_{i}h_{t-1}+U_{i}x_{t}+b_{i}\right). \tag{9}\]  
Then, the candidate set of new values would be calculated for the cell state using \(x_{t}\) and \(h_{t-1}\), with the equation written as  
\[\widetilde{C}_{t}=tanh\left(W_{C}h_{t-1}+U_{C}x_{t}+b_{C}\right). \tag{10}\]  
The new cell state \(C_{t}\) would then be updated with the equation  
\[C_{t}=f_{t}*C_{t-1}+i_{t}*\widetilde{C}_{t}. \tag{11}\]  
In order to determine which cell state to output, \(x_{t}\) and \(h_{t-1}\) would be passed through the output gate, which would give an output value of between 0 and 1 for each component in the cell state \(C_{t}\), with the equation written as  
\[o_{t}=\sigma\left(W_{o}h_{t-1}+U_{o}x_{t}+b_{o}\right). \tag{12}\]  
The updated hidden state \(h_{t}\) is then calculated by putting the cell state through a tanh function and multiplying it with output \(o_{t}\), which is written as  
\[h_{t}=o_{t}*tanh(C_{t}). \tag{13}\]  
Figure 3: A single long short-term memory (LSTM) unit. Note that in Equations (8)-(13), the term \(f\) refers to the forget gate, \(i\) refers to the input gate, \(o\) refers to the output gate, and \(C\) refers to the cell; all of which are of the same dimensions as the hidden vector \(h\). \(W\), \(U\), and \(b\) are the recurrent weight matrix, the input weight matrix, and the bias terms, respectively. The LSTM network can be trained using a supervised learning technique similar to the MLP network's backpropagation algorithm, called the backpropagation through time (BPTT) algorithm [24]. This algorithm is used for recurrent networks such as LSTM networks. The BPTT algorithm is started by unfolding a recurrent neural network in time. The unfolded network contains one input time step, one output, and one copy of the network for each time step. Next, for each time step, the loss and the corresponding error will be calculated and backpropagated. After the process is finished, the recurrent network will be folded back, and the weights will be updated. As the number of timesteps in the BPTT algorithm increases, the calculation process also become more complex, making it computationally expensive compared to the standard backpropagation algorithm.