# Multi-Patch Time Series Transformer for Robust Bearing Fault Detection with Varying Noise
## 4 Deep Learning Models for Anomaly Classification
### MultiPatchTST Model  
This paper proposes the MultiPatchTST model, a model based on the previously introduced PatchTST architecture, for bearing sensor data anomaly classification. The MultiPatchTST model addresses key limitations of the original PatchTST model, where patch length is arbitrarily set by the user, potentially overlooking optimal configurations. Additionally, the best-performing patch lengths may vary across different datasets, making it labor intensive to experiment with multiple patch lengths manually.  
The MultipatchTST model solves this problem by generating multiple PatchTST models with patch lengths from one to the user-set sequence length (seq_len). For example, if seq_len=120, the model generates 120 PatchTST models, each corresponding to a patch size from one to one-hundred-and-twenty. Each model processes the data independently, and the results from each model are passed to the MLP layer to produce the final output value, which is called the result. This is the output of the MultiPatchTST model.  
This approach eliminates the need for users to manually specify patch lengths, automatically identifying and applying the optimal patch size for each dataset. Consequently, the MultiPatchTST model enhances performance by adapting to the characteristics of the data without additional experimentation. Figure 1 shows the architecture of the MultiPatchTST model. The bottom left image is an example image of the input time-series data, the top box is the backbone of the PatchTST model, the purple box in the bottom center represents the PatchTST models with sizes up to n, and the dotted box on the right represents the MLP structure that receives the output of each PatchTST model as an input. and Algorithm 1 is the pseudocode for the MultiPatchTST model.  
```
Input: DataLoader (dls), Input channels (c_in), Output channels (c_out), Sequence length (seq_len), Hidden dimensions (hidden_dim) Output: Final model predictions Steps:
1. Initialize the parent class.
2. Generate valid patch lengths based on the sequence length: Set self.patch_lengths to valid patch lengths derived from seq_len.
3. Create multiple PatchTST models with different patch lengths: For each patch length in self.patch_lengths: Create a PatchTST model with the given parameters.
4. Define an MLP to combine outputs from all PatchTST models: Set self.hidden_dim to hidden_dim. Initialize self.mlp as: A linear layer with input size (len(patch_lengths)*c_out) and output size (hidden_dim). A ReLU activation. A linear layer with input size (hidden_dim) and output size (c_out).
5. Define the forward function: Initialize outputs as an empty list. For each model in self.patch_models: Append model's prediction on x to outputs. Concatenate all outputs into a single tensor. Apply self.mlp on concatenated outputs to generate final output. Return the final output.
6. Define the get_valid_patch_lengths function: Generate valid patch lengths based on the sequence length. Return a list of integers from 1 to seq_len (inclusive).
```  
**Algorithm 1**Pseudocode for MultiPatchTST model.