## 6 CNN Training Strategy  
In order to assess the feasibility of using contrastive learning for the clustering of radio signals, a training strategy was devised to differentiate signal modulations in the spectrogram. Consequently, modifications had to be made to the standard SimCLR [17] approach for training the network. Specifically, either a new implementation of the contrastive loss function needed to be developed or a method for generating the training batch had to be devised. The goal was to ensure that positive pairs corresponded to the same modulations, while negative pairs did not contain the same modulations. The decision was made to implement the latter option. To implement the training strategy for the self-supervised learning of modulations during the preprocessing of the database, signal instances with specific modulations were grouped together. An additional augmentation step was introduced, which involved rotating the spectrogram of the signal by 90 degrees. These transformed spectrograms were also saved separately. Single-sideband modulations (LSB and USB) were grouped together due to their low spectrogram resolutions. This approach effectively created 10 separate signal subdatabases. Figure 5 presents examples of positive pairs of radio signals with different SNR coefficients and various sizes of the Fourier transform. Figure 5a shows a positive pair of WBFM signals, Figure 5b shows a positive pair of AM signals, Figure 5c shows a positive pair of LSB signals, and Figure 5d shows a positive pair of OFDM signals. Positive pairs are simultaneously negative with respect to other positive pairs. For example, a positive pair for WBFM (Figure 5a) is simultaneously negative with respect to the AM pair (Figure 5b). Figure 4: An example spectrogram along with the visualization of signal occurrences. The ResNet50 [24] convolutional residual network was employed as the backbone of the clustering model, with a modified dense layer that reduced the output vector size by a factor of 16, reducing from [\(-\)1, 2048] to [\(-\)1, 128]. The value 128 is a dimension of a latent vector, that is used for comparing and clustering RF signals in proposed approach. The input tensor dimensions are [3, 96, 96]. The training script used the Adam optimizer, with a learning rate set to 0.0003 and weight decay set to \(1\times 10^{-4}\). During the training process, the average loss, TOP1 accuracy, and validation clustering accuracy metrics were computed every epoch using the obtained feature vectors for the validation set. The validation set was extracted from rfspec-db [22] and consisted of the first 10% of spectrograms in the database. The Rand Index (RI) [25] was used for validation, as described by Equation (3). \[RI=\frac{TP+TN}{TP+FP+FN+TN} \tag{3}\]  
TP represents the number of true positives, FP represents the number of false positives, TN represents the number of true negatives, and FN represents the number of false negatives. The Rand Index takes values from 0 to 1, where 0 indicates that two sets do not agree on any pair of points, while 1 indicates that both sets are identical. We can interpret the Rand Index as a percentage measure of correct assignment decisions made by the clustering algorithm. To calculate the RI, a reference assignment of specific signals to groups (in this case, modulations) is required, obtained from the annotation files of the validation portion of the database. Subsequently, the hierarchical clustering of the obtained feature vectors for the spectrogram batch was performed using different threshold values \(\lambda\) to generate assignment vectors necessary for the RI calculation. The temperature coefficient \(\tau\) was initially set to 0.2. The network was trained for 50 epochs on a computer equipped with an RTX3060 GPU. The training duration for a single epoch was approximately 1 min and 23 s, resulting in a total training time of around 69 min.