# Deep Learning for Anomaly Detection in CNC Machine Vibration Data: A RoughLSTM-Based Approach
## 3 Proposed Model: RoughLSTM  
In this study, a novel approach called RoughLSTM is proposed. This method integrates the LSTM model, commonly used in time series data analysis, with RST in order to overcome the limitations of LSTM and obtain more reliable results, particularly for complex problems such as anomaly detection. Although LSTM has shown considerable success in time series analysis, it generates outputs based on exact classification thresholds, which may lead to false positive or false negative results, especially when dealing with uncertain or ambiguous data. Rough set theory, on the other hand, models these uncertainties explicitly, offering a more flexible approach to the classification process. RoughLSTM combines the strengths of LSTM in time series analysis with the uncertainty management capabilities  
Figure 1: Structure of the long short-term memory (LSTM) layer and internal composition of an LSTM cell. of RST. This enables a clearer distinction between the regions of certain and uncertain classes. The proposed architecture begins with a preprocessing phase that includes normalization, windowing with a size of 50, and data augmentation for time series inputs. The core structure consists of two LSTM layers with 100 and 50 units, respectively, separated by dropout layers to prevent overfitting. The model incorporates two fully connected layers--an initial layer with two units and a final layer with thirty units--utilizing ReLU activation functions throughout and Softmax activation in the output layer. A key feature of this architecture is the rough set layer with an epsilon value of 0.1, which processes the outputs to classify signals as either normal or anomalous. In particular, handling examples in boundary regions more accurately enhances the overall accuracy of the model and allows for more reliable classification of uncertain data. The working mechanism of the proposed RoughLSTM model is schematically illustrated in Figure 2. This diagram presents the data flow, components, and processing steps of the model in detail. Additionally, the internal functioning of the rough set layer in the RoughLSTM model is explained in detail, and an operational diagram is provided in Figure 3 to visualize this process. Figure 2: Architecture of the proposed RoughLSTM model. In this study, RST is used to process the outputs of the LSTM model. The LSTM model processes the time series data and generates an output value for each time step. These output values are typically expressed as a probability score (e.g., in the range of [0, 1]). However, classifying these scores based on an exact threshold value (e.g., 0.5) may result in incorrect outcomes for ambiguous examples. To address this issue, an uncertainty threshold (\(\epsilon\)) is introduced, which is determined heuristically based on the distribution of model outputs. The selection of \(\epsilon\) is guided by empirical analysis, ensuring that the boundary region effectively captures ambiguous cases while maintaining a balance between false positives and false negatives. This threshold is optimized according to the data distribution and determines the precision of the model. In this context, the uncertainty region (\(\Delta_{ur}\)) is defined as follows:  
\[\Delta_{ur}=[0.5-\epsilon,\;0.5+\epsilon] \tag{9}\]  
In the formula, 0.5 indicates the decision boundary in the classification problem. Moreover, this stage divides the outputs of the model into three main regions: the upper approach, lower approach, and border region. Figure 3: Flow diagram of rough set layer. _Upper approach_ (\(\overline{rR}\)): The samples in this region definitively belong to a specific class. The mathematical expression for this region is as follows:  
\[\overline{rR}(x)=\{x|x>0.5+\varepsilon\} \tag{10}\]  
Definite positive samples, i.e., those with values greater than \(0.5+\varepsilon\), are considered anomalies with high confidence. These are the most reliable and accurately detected anomaly samples by the model.