# Cyber-Physical Attack Detection and Recovery Based on RNN in Automotive Brake Systems
## 2 Sensor Attack Detection
### Recurrent Neural Network Architecture  
RNN considers present information with historical information. RNN knows a current state of a system by checking time series data. A RNN architecture which is well designed enables a RNN classifier to differentiate attacked sensor data from normal sensor data correctly.  
There are some parameters in architectures. We change one parameter while other parameters are fixed. While the parameters are changing, we choose the parameter when the result is the best experimentally. Firstly, the number of layers has to be selected to make an architecture. After the number of layers is fixed, the architecture is selected by comparing with RNN, Long Short-Term Memory (LSTM) and Gated Recurrent Unit (GRU) among DNNs [13; 14]. Time step which DNNs consider as historical data is set to 90 by reference to [15]. Validation accuracy is checked with the fixed hyper-parameters. Table 2 shows the validation accuracy of each architecture depending on Neural Network (NN) models and the number of recurrent layers. Return sequences is a parameter term to decide whether that RNN layers maintain the number of a dimension same as time step in the output sequence. The access of a hidden state in a memory block of an RNN architecture relies on return sequences. Therefore, return sequences affects performances of RNN models, and it is important to set return sequences in the design of the architecture. The validation accuracy is the accuracy when a validation loss is the lowest among validation losses of epochs.  
In order to check the accuracies with fixed some parameters, return sequences first was set to true, and the number of recurrent layers was only changed. When the number of layers was two, the result was the best. The validation accuracy was more than 99% when the return sequences and the number of layers were modified to false and one, respectively. Therefore, the number of layers was not increased anymore. This is because the validation accuracy would not rise much from 99% although the calculation cost grows due to the growth of the number of layers.  
We set hyper-parameters with Architecture 6 that shows the highest validation accuracy and uses RNN. In addition, the reason why to apply RNN is a simple situation where sensors are homogeneous, that is, there is no need to employ LSTM and GRU to have high computational complexity. Figure 3 presents Architecture 6 (bold) of RNN as shown in Table 2 in detail. In this work, features are each sensor data and input to RNN model like an image. \(X_{i}\), vector data of FL, FR, RL, and RR, is input as input data by 90 time steps. The input shape is (90, 4). The data passes the RNN layer which connects the previous information to the present information and are calculated at the Batch Normalization (BN) layer [16]. The number of neurons of the BN layer is equal to that of hidden neurons of RNN layer. Also, the number of neurons of the Softmax layer is the same as that of classes (15 in this work), and each neuron of Softmax layer calculates a probability of each class. Lastly, the architecture outputs a class number to have the highest probability. At a learning step, Adam is used as an optimizer and cross entropy is employed to calculate a loss [17].  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Architecture** & **Neural Network Model** & **The Number of Recurrent Layers** & **Return Sequences** & **Validation Accuracy** \\ \hline Architecture 1 & LSTM & 1 & True & 65.13 \\ Architecture 2 & LSTM & 2 & True & 84.26 \\ Architecture 3 & LSTM & 3 & True & 58.18 \\ Architecture 4 & LSTM & 1 & False & 99.22 \\ Architecture 5 & GRU & 1 & False & 99.27 \\
**Architecture 6** & **RNN** & **1** & **False** & **99.32** \\ \hline \hline \end{tabular}
\end{table}
Table 2: Some designed architectures to select the best architecture. LSTM: Long Short-Term Memory; GRU: Gated Recurrent Unit; RNN: Recurrent Neural Network.