# IoT-Based Intelligent Monitoring System Applying RNN
## 3 Design of an IoT-Based Intelligent Monitoring System and RNN Model
To solve this problem, an LSTM cell has been proposed, which is shown in Figure 5. The LSTM cell can be represented using two vectors \(h_{(t)}\) and \(c_{(t)}\). Vector \(h_{(t)}\) denotes the short-term state and vector \(c_{(t)}\) denotes the long-term state. RNNs control which data to store in the long-term state or which data to discard. \(C_{(t-1)}\), long-term memory, passes through the forgetting gate, losing some of its contents and adding a new memory \(i_{(t)}\). The generated \(c_{(t)}\) is sent to the output. The long-term state is copied and passed to the tanh function to produce the short-term state \(h_{(t)}\). Eventually, the LSTM cell recognizes the important input, stores it in a long-term state for some time, and then extracts it whenever needed. This guarantees a good performance when training long time series data. The expressions below show how to calculate the cell state for each time step for one sample. The formula for LSTM is as follows:  
\[i_{(t)}=\sigma\Big{(}W_{xi}x_{(t)}+W_{hi}h_{(t-1)}+b_{i}\Big{)}\]  
\[f_{(t)}=\sigma\Big{(}W_{xf}x_{(t)}+W_{hf}h_{(t-1)}+b_{f}\Big{)}\]  
\[o_{(t)}=\sigma\Big{(}W_{xo}x_{(t)}+W_{ho}h_{(t-1)}+b_{o}\Big{)}\]  
\[g_{(t)}=tanh\Big{(}W_{xg}x_{(t)}+W_{hg}h_{(t-1)}+b_{g}\Big{)}\]  
Figure 4: Architecture of IoT-based intelligent monitoring system applying RNN. \[c_{(t)}=f_{(t)}\otimes c_{(t-1)}+i_{(t)}\otimes g_{(t)}\]  
Figure 4.0  
where the meaning of the parameters are as follows:  
Figure 4.1  
Figure 4.2  
Figure 4.3  
Figure 4.4  
Figure 4.5  
Figure 6 shows the GRU model, which has been implemented more simply than the LSTM model. The two state vectors are expressed as one vector \(h_{(t)}\), and one gate controller \(z_{(t)}\) controls both the erase and input gates. When the gate controller outputs 1, the erase gate opens and the input gate closes. Figure 4.6 Long Short-Term Memory Cell. Figure 4.7 Gated Recurrent Unit. The following expressions show the calculation of the cell state for each time step for one sample. The GRU formula is as follows:  
Figure 4.8  
Figure 4.9  
Figure 3:0  
Figure 3:1  
The input dataset used in the LSTM model comprises 525,000 temperature data, and each X_train datum consists of a temperature vector from time \(t-9\) to time \(t\), and the Y_train data are temperature data at time \(t+1\). The part of the train dataset, 0.2 * training dataset, was used as a validation data. The hidden layer uses two LSTM Layers, each node consists of 10, and the output layer is a fully connected layer and has one output value. The main parameters used in the training are as follows:  
batch size: 1  
loss function: mean squared error  
optimizer: ADAM (Adaptive Moment Estimation)  
Input layer:  
X_train Dim: (525,000, 10)  
Y_train Dim: (525,000, )  
Length: 525,000  
Normalization: 0 - 1 (Min Max Scaler)  
In the case of the GRU model, the basic neural network is the same as the LSTM model, but only the hidden layer part uses the GRU layer. The number of nodes in each hidden layer of the LSTM model is shown in Table 1, while Table 2 shows the case of the GRU model. It is possible to use regulation rate or dropout in case of overfitting, but they were not used in our model because overfitting did not occur. Figure 7 shows the designed structure, which has outputs of Y, 10 sequences, and two hidden layers. If the difference between the Y\({}_{\text{pred1}}\) output as the predicted value and the actual data Y\({}_{1}\) is greater than the threshold, it is counted as an error. Thus, the accuracy of the predictive model can be calculated by examining how accurate it is relative to the \begin{table}
\begin{tabular}{c c c} \hline \hline
**Layer (Type)** & **Output Shape** & **Param** \\ \hline Hidden 0 (LSTM) & (, 10, 10) & 480 \\ \hline Hidden 1 (LSTM) & (, 10) & 840 \\ \hline Output (Dense) & (, 1) & 11 \\ \hline \hline \end{tabular} Total params: 1331  
\end{table} 
Table 1: Number of nodes in each hidden layer (LSTM).