# Deep Learning for Anomaly Detection in CNC Machine Vibration Data: A RoughLSTM-Based Approach
## 3 Proposed Model: RoughLSTM
_Lower approach_ (\(\underline{rR}\)): This includes definitive negative samples. Mathematically, it is expressed as follows:  
\[\underline{rR}(x)=\{x|x<0.5-\varepsilon\} \tag{11}\]  
Definite negative samples, i.e., those with values less than \(0.5-\varepsilon\), are classified as normal cases with high confidence. This region represents the samples that the model confidently identifies as normal. _Boundary region_ (\(rR_{r}\)): The boundary region contains ambiguous samples. The samples in this region require further analysis and are defined as follows:  
\[rR_{r}(x)=\{x|\ 0.5-\varepsilon\leq x\leq 0.5+\varepsilon\} \tag{12}\]  
Ambiguous samples, where the data fall between \(0.5-\varepsilon\) and \(0.5+\varepsilon\), are cases that require further analysis. This region represents situations where the model needs additional information or secondary evaluations. In the next step, the uncertainty score is calculated. For each ambiguous sample, an uncertainty score is calculated based on its distance from the boundary region. This score is then normalized to a standard value. \[U_{\Delta}(x)=\frac{|x-0.5|}{\varepsilon} \tag{13}\]  
where \(x\) represents the output value of the model. Once the uncertainty score is determined, the decision mechanism classifies samples based on their uncertainty levels:  
High-score samples (\(U_{\Delta}(x)>1\)): These samples are far from the boundary region, making them highly reliable for classification. * If \(x>0.5+\varepsilon\), the sample is classified as an anomaly with high confidence. * If \(x<0.5-\varepsilon\), the sample is classified as normal with high confidence. Low-score samples (\(U_{\Delta}(x)=1\)): These samples lie exactly on the boundary of the uncertainty region. They can still be classified using the standard threshold-based approach but may require additional verification. Medium-score samples (\(0<U_{\Delta}(x)<1\)): These samples fall within the uncertainty region and require further analysis before making a final decision. A secondary analysis can involve additional contextual information, feature extraction, or ensemble-based decision-making to improve classification reliability. By incorporating this adaptive decision mechanism, RoughLSTM effectively mitigates the limitations of sharp classification boundaries in standard LSTM models. This approach enhances the robustness of anomaly detection by reducing false positives and false negatives, improving interpretability, and allowing for a more flexible decision-making process in uncertain cases. The step-by-step operation of the RoughLSTM model is detailed in the pseudocode provided in Algorithm 1. This pseudocode clearly outlines the key components of the model, including data input, handling of uncertainties in the rough set layer, and time series analysis performed by the LSTM network. Thus, the implementation and workflow of the RoughLSTM model are systematically presented. ```
1:procedureRoughLSTM(signal, num samples, anomaly intervals)
2: Convert signal to double if necessary
3: Normalize signal \(\triangleright\) Windowing the Signal
4: Define window size = 50, overlap = 25
5: Compute num windows
6:for i = 1 to num windows do
7: Extract window from signal
8: Check if window overlaps with any anomaly intervals
9: Label as normal (1) or anomalous (0)
10:endfor\(\triangleright\) Rough Set Parameters
11: Define \(\epsilon\) = 0.1 (uncertainty threshold)
12: Generate additional noisy samples
13: Convert Data to LSTM Format
14: Convert each window to cell array format
15: Shuffle data
16: Split into Train (70%), Validation (15%), and Test (15%)
17: Convert 0 (Anomalous) and \(1\) (Normal) to categorical format
18: Define Rough-LSTM Model
19: Train the Model
20: Train using Adam optimizer with 50 epochs
21: Testing and Post-processing
22: Predict using trained model
23: Apply Rough Set Post-processin
24: Compute Accuracy
25: Compare predictions with ground truth
26: Compute accuracy
27:return Y PredRoughLSTM, accuracyRoughLSTM
28:endprocedure
```  
**Algorithm 1** RoughLSTM Pseudocode