# Bidirectional-Feature-Learning-Based Adversarial Domain Adaptation with Generative Network
## 3 BiFLP-AdvDA
### Loss Functions  
This paper aims to reduce the gap between domains and improve the robustness of the model using a generative model with an autoencoder structure and an adversarial domain adaptation (BiFLP-AdvDA) approach based on bidirectional feature learning to extract features that can finally be learned regardless of the domain. This study also aims to perform domain adaptation to minimize the gap between domains so that characteristics of domains become similar. For these purposes, four loss functions and a total of five loss functions are used until total loss using all of them. Formulas and brief descriptions of the loss functions are presented below. Label classification loss was used to perform a classification task using data from the source domain and to minimize the difference between the actual and predicted labels. The following is the formula for label classification loss:  
\[L_{\text{cls}}(y,\hat{y}_{s})=-\sum_{i}y_{i}\cdot log(\hat{y}_{s},i) \tag{1}\]  
where \(y\) denotes actual classified class labels of the source domain, which can be binary or multi-class depending on the problem; \(\hat{y}_{s}\) denotes predicted class labels of the source domain containing probabilities for each class; \(i\) denotes an index variable representing classes, varying depending on the number of possible classes in a classification task; \(y_{i}\) denotes the value corresponding to class i in the actual label vector, the value of \(\hat{y}_{s}\); and \(i\) in the log function corresponds to class i in the predicted probability vector, representing the likelihood of belonging to that class. Domain classification loss was used to train the domain discriminator to misclassify the domain as much as possible. This helps the feature extractor to extract features that the domain discriminator will use to prevent the domain discriminator from classifying as well as possible. As a loss function, unlike label classification loss, we used binary cross-entropy loss (BCE loss) because the task was to classify into one of two domains. The following is the formula for domain classification loss:  
For the source domain,  
\[L_{\text{src}}(D_{s},\hat{D}_{s})=-\sum_{i}(D_{i}\cdot log(\hat{D}_{s},i)+(1- D_{i})\cdot log(1-\hat{D}_{s},i)) \tag{2}\]For the target domain,  
\[L_{\text{tar}}(D_{t},\hat{D}_{t})=-\sum_{i}(D_{i}\cdot log(\hat{D}_{t},i)+(1-D_{i })\cdot log(1-\hat{D}_{t},i)) \tag{3}\]  
where \(L_{\text{src}}\) indicates the source domain classification loss function; \(D_{i}\) denotes the actual classified source domain labels obtained using the domain discriminator; \(\hat{D}_{s}\) denotes the predicted source domain labels; \(i\) denotes the index variable for the elements in one batch of source data; \(L_{\text{tar}}\) denotes the target domain classification loss function; \(D_{t}\) indicates a binary value of 0 or 1 and indicates whether the domain is the source or target; \(\hat{D}_{t}\) denotes the predicted domain labels of the target domain; and i denotes the index variable for the elements in one batch of the target data. Adversarial loss was used to train the domain discriminator to not discriminate between features extracted from the feature extractor. In this way, it learns to reduce the gap between domains. Here is the formula for adversarial loss:  
For the source domain,  
\[L_{\text{adv\_src}}(L_{\text{cls}},L_{\text{src}})=L_{\text{cls}}+\alpha*L_{ \text{src}} \tag{4}\]  
For the target domain,  
\[L_{\text{adv\_tar}}(L_{\text{cls}},L_{\text{tar}})=L_{\text{cls}}+\alpha*L_{ \text{tar}} \tag{5}\]  
where \(L_{\text{cls}}\) denotes the classification loss for the source domain; \(L_{\text{src}}\) denotes the source domain classification loss; alpha denotes a hyperparameter representing the weight or importance given to the source loss in the combination; \(L_{\text{cls}}\) denotes the classification loss for the source domain, as already mentioned; and \(L_{\text{tar}}\) denotes the target domain's classification loss.