# Self-Healing of Semantically Interoperable Smart and Prescriptive Edge Devices in IoT
## 3 SEDGE Proposed Methodology
### Application Layer
#### Long short-term memory networks (LSTM)
Additionally, the autoencoder is trained by minimizing the reconstruction error as described in the following equation [42]:  
\[L=\frac{1}{2}\sum_{x}\|x-\hat{x}\|^{2}. \tag{7}\]  
There are several different types of autoencoders that have been proposed in the literature, including the LSTM autoencoder, convolutional autoencoder, and vanilla autoencoder. The LSTM autoencoder consists of LSTM modules in both the encoder and decoder modules. LSTMs are well-suited for time series forecasting or anomaly detection due to their ability to learn patterns in data over long sequences [43]. Generally, as mentioned in [44], an encoder-decoder model in anomaly detection applications learns the representation of the data using only the normal sequences and then uses the trained model to reconstruct them. When the model is fed with an abnormal sequence, it might not be reconstructed well, leading to a high error. Several studies [45; 46] have demonstrated the use of the LSTM autoencoder for anomaly detection in time series data. **Anomaly Detection Method**  
Figure 9 presents the method implemented for anomaly detection application. It consists of two LSTM nodes for the encoder and two for the decoder (AE-LSTM). The training phase of the method includes data with normal points which are scaled using the standardization method. On the other hand, the test phase includes data with normal and anomaly points. Ten days from twelve different Rpi devices were used for the training, with measurements every 10 s. The used dataset for the training and test procedures had the form of (samples \(\times\) time steps \(\times\) variables). The input data are split into smaller parts using a sliding window algorithm, and each part is fed to the encoder layer. For the sliding window, the number 3 was selected as the optimal value. The encoder of the proposed method includes two LSTM nodes with 256 and 64 neurons, respectively. The output from the encoder is passed through the latent space representation, which is operated as a dimension reduction method. Additionally, two LSTM nodes were used for the decoder layer with 64 and 256 neurons, respectively. The ReLU activation function was used for both the encoder and decoder layers [47]. Finally, the reconstructed output is available from the decoder layer. The proposed method was trained using the Adam optimizer for 200 epochs with learning rate \(1^{e-2}\). Subsequently, the dropout regularization with a value of 0.2 was applied after the output of the encoder and the decoder to improve its accuracy and to avoid overfitting. The detection process is held in the final step, and it includes the calculation of the error between the actual and predicted time series as well as a threshold value, which is used to classify the data as normal or anomaly points. The error is calculated using the mean absolute error (MAE), the predicted value \(\hat{x}\), and the true one \(x\)[42]:  
\[MAE=\sum_{i=1}^{D}|x-\hat{x}|. \tag{8}\]  
Finally, based on the three-sigma statistic rule, a threshold value was selected to determine whether the prediction errors represent anomalies of the system [48]:  
\[Threshold\_value=mean(squared\_error)+3*std(squared\_error) \tag{9}\]