# Anomaly Detection of the Brake Operating Unit on Metro Vehicles Using a One-Class LSTM Autoencoder
## 3 Proposed Methods
### Lstm Autoencoder Model for Anomaly Detection  
#### 3.2.1 Long Short Term Memory (LSTM)  
LSTM is a type of Recurrent Neural Network (RNN) which allows the network to learn order dependence in a sequence prediction task [41]. There are different sorts of LSTM models such as LSTM with a peephole connection. However, the LSTM with a peephole connection requires more memory, trainable parameters, and training time. Also, the performance gap between the vanilla LSTM model and the LSTM model with a peephole connection is very little and for certain tasks, the performance of the LSTM model with a peephole connection is even worse than the vanilla LSTM model [42]. Hence, in this study, we use the vanilla LSTM model which is the default LSTM setting of deep learning frameworks and is widely used for many applications. There are three different control gates for regulating information flow in the vanilla LSTM cell: a forget gate, an input gate, and an output gate. Each gate is composed out of a pointwise multiplication operation and a sigmoid neural network layer. The sigmoid neural network layers output numbers between 0 and 1, indicating a portion of input information that should be let through. Time series data is represented as a sequence of input vectors \(x=x_{1},x_{2},\dots,x_{t},\dots\) which is fed into the LSTM, where \(x_{t}\in\mathbb{R}^{m}\) represents an m-dimensional vector at timestamp \(t\).  
Figure 2: Architecture of our proposed model for detecting anomaly from the BOU data.  
Given new information \(x_{t}\) that entered the network, the forget gate \(f_{t}\) controls what information in the cell state to forget by outputting a number between 0 and 1 as follows:  
\[f_{t}=\sigma(W_{f}[h_{t-1},x_{t}]+b_{f}) \tag{1}\]  
where \(\sigma\) represents sigmoid activation function, \(h_{t-1}\) represents the output of the previous LSTM block (at timestamp \(t-1\)), \(W_{f}\) and \(b_{f}\) represent the weight matrix and the bais of the gate, respectively. The input gate \(i_{t}\) which decides what information is relevant to update in the current LSTM cell state, is defined as follows:  
\[i_{t}=\sigma(W_{i}[h_{t-1},x_{t}]+b_{i}) \tag{2}\]  
where \((W_{i},b_{i})\) represent the weight matrix and the biases of input gate, respectively. After that, a vector of new candidate value \(\hat{C}_{t}\) which could be added to the state is create as follows:  
\[\hat{C}_{t}=tanh(W_{c}[h_{t-1},x_{t}]+b_{c}) \tag{3}\]  
where \(tanh\) represents hyperbolic tangent (tanh) activation function, \((W_{c},b_{c})\) represent the weight matrix and the biases of memory cell state. Then, the old cell state \(C_{t-1}\) is multiplied by \(f_{t}\), and added by \(i_{t}*\hat{C}_{t}\) that updates the cell state to new values which gives us our new cell state \(C_{t}\) as follows:  
\[C_{t}=f_{t}*C_{t_{1}}+i_{t}*\hat{C}_{t} \tag{4}\]  
Finally, the output gate \(o_{t}\) which controls what data to pass as the output hidden state \(h_{t}\) is defined as follows:  
\[o_{t}=\sigma_{3}(W_{o}[h_{t-1},x_{t}]+b_{o}) \tag{5}\]  
\[h_{t}=o_{t}*tanh(C_{t}) \tag{6}\]  
where \(W_{o}\) and \(b_{o}\) are the weight matrix and the bias of output gate, respectively.