# Real Driving Cycle-Based State of Charge Prediction for EV Batteries Using Deep Learning Methods
## 4 Methodology
### Deep Learning-Based SOC Prediction  
In this section, our intention is to predict the future speed from the past speed of the EV; hence, we consider this task as a univariate time series prediction task. Given the observed time series data \(\mathbf{x}=[x_{1},x_{2},\ldots,x_{T}]\in\mathbb{R}^{T}\), the task is to predict the future value \(x_{T+1}\in\mathbb{R}\). Formally, we intend to predict \(\hat{x}_{T+1}\in\mathbb{R}\) through a function \(f\), as follows:  
\[\hat{x}_{T+1}=f(x_{1},x_{2},\ldots,x_{T}), \tag{1}\]  
where \(f(\cdot)\) is a linear or nonlinear function that needs to be learned. Our main contribution is presenting a model for predicting speed, which is based on an LSTM with a temporal attention mechanism. The architecture of the prediction model is shown in Figure 5. First, we use an LSTM layer to encode the information from the input sequence into a feature representation. The final prediction is then made by utilizing the temporal attention mechanism over the output features of the LSTM layer. \begin{table}
\begin{tabular}{c c c c c} \hline \hline  & **First Base** & **Second Base** & **Third Base** & **Fourth Base** \\  & **Segment** & **Segment** & **Segment** & **Segment** \\ \hline Start Point (s) & 0 & 69 & 135 & 224 \\ \hline End Point (s) & 69 & 135 & 224 & 404 \\ \hline Search Start & 0 & 19 & 85 & 174 \\ Point (s) & & & & \\ \hline Search End & 119 & 185 & 274 & 454 \\ Point (s) & & & & \\ \hline examples of & (0, 69), & (19, 85), & (85, 174), & (174, 354), \\ Search periods & (5, 74), & (24, 90), & (90, 179), & (179, 359), \\ (start, end) &... &... &... &... \\  & (45, 114), & (114, 180), & (180, 269), & (269, 449), \\  & (50, 119) & (119, 185) & (185, 274) & (274, 454) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Table showing the start and end time of the segments and the search periods. Recurrent Neural Network (RNN) is one of the family of neural networks specialized in processing sequential data. If a general feed-forward neural network approach is used to process fixed-length data, the network has separate parameters for each input feature, so it needs to learn them separately at each time position. In contrast, an RNN shares weights across multiple time steps. This sharing of weights is important, as it allows for the generalization of unseen sequences and the sharing of statistical strength across time steps. Long short-term memory (LSTM) and gated recurrent unit (GRU), which are variants of RNN, are commonly used for handling sequential data such as language modeling [33,34] and time series prediction [35,36]. LSTM outperforms RNN and GRU for many sequence prediction tasks because of its gating systems, so we chose LSTM for this task. The forward process of an RNN cell is defined as:  
\[\mathbf{f}_{t} =\sigma(\mathbf{W}_{f}[x_{t},\mathbf{h}_{t-1}]+\mathbf{b}_{f}) \tag{2}\] \[\mathbf{i}_{t} =\sigma(\mathbf{W}_{i}[x_{t},\mathbf{h}_{t-1}]+\mathbf{b}_{i})\] (3) \[\mathbf{\tilde{c}}_{t} =\tanh(\mathbf{W}_{c}[x_{t},\mathbf{h}_{t-1}]+\mathbf{b}_{c})\] (4) \[\mathbf{c}_{t} =\mathbf{f}_{t}\cdot\mathbf{c}_{t-1}+\mathbf{i}_{t}\cdot\mathbf{ \tilde{c}}_{t}\] (5) \[\mathbf{o}_{t} =\sigma(\mathbf{W}_{\mathbf{o}}[x_{t},\mathbf{h}_{t-1}]+\mathbf{b }_{o})\] (6) \[\mathbf{h}_{t} =\mathbf{o}_{t}\cdot\tanh(c_{t}) \tag{7}\]  
where \(\mathbf{W}_{f},\mathbf{W}_{i},\mathbf{W}_{c},\mathbf{W}_{o}\in\mathbb{R}^{m \times(m+1)}\) are weight matrices, and \(\mathbf{b}_{f},\mathbf{b}_{i},\mathbf{b}_{c},\mathbf{b}_{o}\in\mathbb{R}^{m}\) are bias to be learned. \(\mathbf{f}_{t}\) is the forget gate, which determines how much previous information is forgotten, \(\mathbf{i}_{t}\) is the input gate, which determines how much new information is added, and \(\mathbf{o}_{t}\) is the output gate, which, along with the current cell state \(\mathbf{c}_{t}\), determines the output of this cell. Recently, researchers have proposed multiple attention mechanisms for time series tasks and achieved better results than LSTM and GRU [37, 38, 39].