# A Multi-Source Consistency Domain Adaptation Neural Network MCDANN for Fault Diagnosis
## 2 Proposed Model
### Domain Adaptation Network Based on DANN and MK-MMD  
The model proposed in this paper is based on the Domain Adversarial Neural Network (DANN) [37]. DANN is a pioneering work that uses an adversarial method to complete  
Figure 1: MCDANN architecture. domain adaptation, which is inspired by the adversarial generative network. The DANN network is divided into three parts, one is the feature extractor, which maps the source domain and the target domain into a feature space with small distribution differences; the other is the label classifier, the source domain data features is obtained through the feature extractor and classified through label classifier, the loss is calculated for the classification result, and the parameters of the feature extractor and the label classifier are updated; the third is the domain classifier, the source domain data features and the target domain data features are obtained through the feature extractor, and are input to the domain classifier, the loss is calculated for the domain classification result, and the parameters of the feature extractor and the domain classifier are updated. The feature extractor and the domain classifier form an adversarial network. The feature extractor improves the ability to confuse the domain in the confrontation, and the domain classifier improves the ability of the domain classification in the confrontation, so this loss is called the adversarial loss. At the same time, the gradient reversal layer GRL is applied in this adversarial network, so that the feature extractor and domain classifier in the adversarial network can perform parameter updates at the same time. The training process of the DANN network is shown in Figure 2.  
The loss function of the DANN network includes label classification loss and domain adversarial loss, as shown in Formula (1):  
\[E=\sum_{ \begin{subarray}{c}i=1,\dots,N\\ d_{i}=0\end{subarray} }L_{y}\Big{(}G_{y}\Big{(}G_{f}(x_{i})\Big{)},y_{i}\Big{)}- \lambda\sum_{i=1,\dots,N}L_{d}\Big{(}G_{d}\Big{(}G_{f}(x_{i})\Big{)},y_{i}\Big{)} \tag{1}\]  
where the function \(G_{f}\) represents the feature extractor, which maps the input \(x_{i}\) into a feature space. \(G_{y}\) is the label classifier, giving label predictions on the data. \(G_{d}\) is the domain classifier, used to predict the domain of the data. \(L_{y}\) is the difference between the prediction of the label classifier and the real label, and \(d_{i}=0\) means that only the source domain data is predicted. \(L_{d}\) is the difference between the predicted domain and the real domain. Figure 2: DANN training process. In addition, DANN introduces a gradient reversal layer which allows the loss function to be calculated as a whole, thereby realizing an end-to-end network structure. The Formula (2) of the gradient reversal layer and its derivative Formula (3) are as follows:  
\[R_{\lambda}(x)=x \tag{2}\]  
\[\frac{dR_{\lambda}}{dx}=-\lambda I \tag{3}\]  
Equations (2) and (3) indicate that, on the gradient reversal layer, the data does not change during the forward propagation process, but the opposite gradient direction will be obtained during backward propagation. Using this feature, a gradient reversal layer is connected before the domain classifier. During backpropagation, the gradient result from the domain classification loss function will be automatically reversed at this layer, so that the domain classification loss and the classification loss can be a whole for training. At this time, the formula of the loss function is as shown in (4):  
\[E=\sum_{ \begin{subarray}{c}i=1,...,N\\ d_{i}=0\end{subarray}