# Research on the Lossless Data Compression System of the Argo Buoy Based on BiLSTM-MHSA-MLP
## 3 Data Compression and Decompression
### Compression and Decompression Model  
This paper uses an adaptive arithmetic coding module to achieve compression and decompression. For the initial timesteps, a uniform probability distribution is adopted, and adaptive arithmetic coding is performed to achieve lossless compression. The timestep characters are subsequently passed through the preliminary probability prediction module and the probability prediction module to predict the probability distributions of other characters. The adaptive arithmetic coding module updates the cumulative frequency table and the original character probability distribution according to the probability distribution and the timesteps+1 st character to obtain new probability intervals for other characters. By looping this process, the probability interval of the Nth character can be obtained, and the encoding is then completed. Among them, block 1 refers to the initial timesteps of the column data of each batch, block 2 to block n \(-\) 1 refer to block_len \(\times\) batch_size data, block_len defines the number of time steps processed in each iteration, batch_size indicates the number of samples in each batch, and block n refers to the remaining data in the end. The compression flow chart is shown in Figure 5. The overall compression process is shown in pseudocode as Algorithm 1. Figure 4: Profile data division. ```
1:Input:
2:input_data: data to be compressed
3: timesteps: number of timesteps in each sequence
4: model: probability prediction model
5:Output:
6: com_data: compressed data
7: params: model parameters
8:Initialize parameters:
9: params.append (char2 id_dict, id2 char_dict)
10: integer_encoded \(\leftarrow\) Encode (input_data, char2 id_dict)
11: params.append (len(integer_encoded))
12: [train_x, train_y] \(\leftarrow\) ExtractFeaturesAndLabels(integer_encoded, timesteps)
13:Encode the initial timesteps with a uniform distribution:
14:for i \(\leftarrow\) 0 to timesteps do
15: com_data.append (ArithmeticEncoder (train_y [0, i], uniform))
16:endfor
17:Process remaining data:
18:forj \(\leftarrow\) 0 to len(train_x) do
19: prob \(\leftarrow\) model.predict (train_x[j])
20: com_data.append (ArithmeticEncoder(train_y[j], prob))
21:endfor
22:End:
23:Return com_data and params
```  
**Algorithm 1**Compression algorithm  
Figure 5: Compression process. During the data compression process, the preliminary probability predictor is composed of a BiLSTM network and an MHSA network, which is trained and saved via the 4000 m profile dataset collected by the deep-sea Argo buoy. The probability predictor is based on the preliminary probability predictor and adds an MLP network, which includes multiple fully connected layers and residual network layers. Block_len is introduced during compression to achieve block compression and training, which determines the frequency of model updates and the length of the encoding symbol block. This approach strikes a balance between the model update frequency and computational efficiency. A smaller block length means more frequent model updates, which may lead to better compression effects, but the computational cost is relatively high. When the data volume reaches block_len \(\times\) batch_size, the data are sent to the probability predictor and adaptive arithmetic coding module to complete data compression. At the same time, the data are also used to train the probability prediction model. During the compression process, the parameter requires_grad of the preliminary probability prediction model is set to False to prevent the trained preliminary probability prediction model from being updated. The introduced MLP network is trained during the compression process so that the probability prediction model is dynamically updated and gradually adapts to the distribution of compressed data, thereby providing more accurate predictions. The decompression process is symmetrical to the compression process. First, the initial timesteps are arithmetically decoded via a uniform probability distribution.