# A Collaborative Domain Adversarial Network for Unlabeled Bearing Fault Diagnosis
## 3 Collaborative Domain Adversarial Network
### Forward Propagation of Network Models
The function of a feature extractor is to map the sample features of the source and target domains to the same distribution space as much as possible, reducing distribution differences. CDANs use Multi-Kernel Maximum Mean Discrepancies (MK-MMD) [29] to measure the distance between feature distributions and achieve the goal of predicting the labels of target domain samples. The loss calculation method of MK-MMD is as follows:  
\[L_{\text{mmd}}=\frac{1}{N_{S}N_{S}}\sum_{i=1}^{N_{S}}\sum_{j=1}^{N_{S}}\kappa \left(v_{i}^{S},v_{j}^{T}\right)-\frac{2}{N_{S}N_{T}}\sum_{i=1}^{N_{S}}\sum_{j =1}^{N_{T}}\kappa\left(v_{i}^{S},v_{j}^{T}\right)+\frac{1}{N_{T}N_{T}}\sum_{i =1}^{N_{T}}\sum_{j=1}^{N_{T}}\kappa\left(v_{i}^{S},v_{j}^{T}\right) \tag{7}\]  
However, due to the lack of labels in the target domain data, the parameters of the last fully connected layer cannot be trained. To solve this issue, a pseudo-label learning strategy is introduced. The core idea of the pseudo-label strategy is to use the label with the highest predicted probability as the true label and to make the pseudo-label infinitely close to the true label through network iterative training. Laboratory samples and real samples are clustered, and pseudo-labels are created for real fault samples based on the probability of laboratory sample labels. The softmax function in the last layer calculates the probability distribution of the sample labels, and based on this probability distribution, it converts it into the final label of the sample. The label \(y_{j}^{T}\in Y_{T}\) prediction method for target domain samples \(x_{j}^{T}\subset X_{T}\) is as follows:  
\[y_{j}^{T}=\underset{y_{i}^{S}}{\text{argmax}}\Big{(}\Big{(}\sum_{y_{i}^{S}=k }B\Big{(}x_{i}^{S}\rightarrow\Re,y_{i}^{S}\Big{)}\Big{)}|_{k=1}^{k=K}\Big{)} \tag{8}\]  
where \(y_{i}^{S}\) is the fault label of the source domain sample \(x_{i}^{S}\), \(\Re\) represents the set clustering range, and \(B(\cdot)\) represents Boolean operation, which means that if the sample features are mapped to the set clustering range, its value is taken as 1, and if they are not within the set clustering range, its value is taken as 0. \(K\) represents the number of all fault types. Using clustering to preliminarily predict the fault types of target domain samples and labeling them facilitates the training of a state classifier using target samples with predicted labels. The loss function of the discriminator is defined as follows:  
\[L_{D}\big{(}\theta_{G}^{S},\theta_{G}^{T},\theta_{D}\big{)} = \frac{1}{n_{S}}\sum_{i=1}^{i=n_{S}}\left(-d_{i}\log\left(D\big{(} f_{i}^{S}\big{)}\right)-\left(1-d_{i}\right)\log\left(1-D\big{(}f_{i}^{S} \big{)}\right)\right)\] \[+ \frac{1}{n_{T}}\sum_{j=1}^{j=n_{T}}\left(-d_{j}\log\left(D\big{(} f_{j}^{T}\big{)}\right)-\left(1-d_{j}\right)\log\left(1-D\Big{(}f_{j}^{T} \Big{)}\right)\right)\]  
In this equation, \(n_{S}\) and \(n_{T}\) represent the number of laboratory samples (source domain) and real samples (target domain), respectively. Here, \(d_{i}\) and \(d_{j}\) denote the labels of domain for the laboratory samples and real samples. The domain label for a source sample is \(d_{i}=0\), while for a target sample it is \(d_{j}=1\). \[L_{D}\Big{(}\theta_{G}^{S},\theta_{G}^{T},\theta_{D}\Big{)}=-\frac{1}{n_{S}} \sum_{i=1}^{i=n_{S}}\left(\log\left(1-D\Big{(}f_{i}^{S}\Big{)}\right)\right)- \frac{1}{n_{T}}\sum_{j=1}^{j=n_{T}}\left(\log\left(D\big{(}f_{j}^{T}\big{)} \right)\right) \tag{10}\]The mapped source domain feature \(f_{S}^{i}\) is input into the state classifier \(C\) to obtain the predicted label for the sample. Since the real fault samples in this paper are unlabeled, only the source domain samples are used to train the state classifier \(C\). The calculation formula for the state classifier \(C\) is defined as follows:  
\[\hat{y}_{i}^{S}=C\Big{(}flatten\Big{(}G_{S}\Big{(}x_{i}^{S},\theta_{G}^{S} \Big{)}\Big{)},\theta_{C}\Big{)} \tag{11}\]  
The state classifier uses the cross-entropy loss function, defined as follows:  
\[