## 5 Materials and Methods
### Contrastive Semantic Alignment  
The Stage 4 alignment of our proposed model is the contrastive learning and separation of the semantic probability distributions of paired source and target data features near to the critical decision boundaries. This semantically aligned yet maximally separated mapping of the embedded subspace effectively generalizes distinct domains with an extremely low number of labeled target training samples, as demonstrated by the study of [78]. However, our proposed approach is based on an unsupervised adaptation technique that does not have target label observations. Therefore, our first step is to pre-label target samples. The previous three stages of alignment steps have improved our model by increasing confidence in target label predictions. We utilize this setup to generate pseudo-labels on target samples from each of the domain-specific classifiers and leverage them to minimize the intra-class discrepancy from their counterpart paired source samples so as to reduce the distance between the samples within the same classes of source and target domains. At the same time, we maximize their inter-class differences so as to push the samples belonging to the dissimilar classes of source and target domains apart. This two-way optimization of intra-class and inter-class discrepancies is helpful to improve the domain generalization process using contrastive semantic alignment loss, another type of distance minimization method that is added with the other losses of the model and jointly helps in the adaptation strategy. Finally, an average of the multiple classifiers' outputs increases the model performance in the recognition task. Mathematically, we can define it as  
\[\mathcal{L}_{CSA}=\frac{1}{2}(1-Y)\Big{[}D(x_{i_{t}}^{j},x_{t}^{j})\Big{]}^{2} +\frac{1}{2}(Y)\max\Big{[}0,margin-D(x_{i_{t}}^{j},x_{t}^{j})\Big{]}^{2} \tag{15}\]  
Figure 4: Architectural details of domain-specific classifiers. where \(D\) is the pairwise distance between source and target embeddings, \(Y\) shows the similarity between the source label and the target pseudo-label with a value of 0, and in the case of dissimilar pairs, it acquires a value of 1, the margin is declared as 1, and if the distance between dissimilar pairs goes beyond this margin, the loss of these pairs become 0 to avoid unnecessary separation. Figure 5 shows the proposed architecture with the four stage alignment losses combined together as the overall loss for backpropagation of the model. It shows the overall architecture of the proposed model, with the three blocks having been separately explained in their layout design in the previous discussions of Figures 2-4. Additionally, it introduces all the domain generalization losses used at different stages of model training. Also, Algorithm 1 explains all the training steps of our presented model. The total loss of the proposed architecture after the four-stage alignment technique is formulated as  
\[\mathcal{L}_{total}=\mathcal{L}_{classification}+\alpha\mathcal{L}_{Distance \_Minimization}+\beta\mathcal{L}_{discrepancy}+\gamma\mathcal{L}_{ Contrastive\_Alignment} \tag{16}\]  
where \(\alpha\), \(\beta\), and \(\gamma\) are weights used to emphasize different losses. We fixed \(\gamma=0.02\) during the model training and exponentially decreased \(\alpha\) and \(\beta\) using the formula \(\frac{2}{1+\exp(-10*p)}-1\), which progressively schedules these weights with a gradual change in \(p\) as the model training progresses [83].