# A Domain-Based, Adaptive, Multi-Scale, Inter-Subject Sleep Stage Classification Network
## 4 Discussion  
In this paper, we propose a model structure, training method, and loss calculation to improve the generalization of the model. The multi-scale residual module extracts multi-scale detailed information to enhance the representation ability of the feature encoder. Multi-class focal loss with the additional classification loss that computes the loss between the prediction stages using the previous 30 s ECG and true labels solves the inadequate learning of the model caused by class imbalance and provides the learning of sleep stage transitions based on the previous period of ECG. Because the model's experience learned on the training set is biased on the test set due to subject-specific problems [43] between the training set and the test set, we implemented domain adaptation via the iterative optimization of MMD and classification losses to improve the generalization on the test set [22]. In the above results, we have verified that the proposed method has outstanding performance on subject-specific sleep staging in the three datasets. In this part, we will discuss the test results of the proposed method across datasets and analyze the impact of different loss calculations on the model's performance, which aims to verify that the contributions have a key effect on the model's performance. The model was trained on a dataset and then tested on another dataset to obtain the cross-dataset evaluation results. We tested a total of four cases, namely SHHSI to MESA, SHHS2 to MESA, SHHS2 to SLPDB, and SHHS2 to SHHS1, as shown in Table 6. The table shows that both the accuracy rate and Kappa achieve a significant improvement across datasets compared to pre-DA and post-DA. We used different datasets (source domain) as the training set and tested the same dataset (target domain), which led to different results. For example, when SHHS1 and SHHS2 were used as the training set to train the model, respectively, the accuracy (Kappa) of MESA is 0.851(0.803) and 0.857(0.809) after adjusting the distribution. This may be related to the degree of distribution difference between different datasets, resulting from the collection environment and operation. According to the results in Table 3, the test result of MESA is 0.868 (0.840), which exceeds the result in the cross-dataset mode, which supports the notion that different acquisition conditions may also cause data distribution. Table 5 also shows the results of different feature encoders in the cross-dataset test. The proposed multi-scale residual module outperforms other feature encoders. The information at multiple scales provided by the multi-scale residual module can promote the performance of the model, whether it is on the data or across the data. When the training set comes from SHHS2, and the test set comes from SLPDB, the confusion matrix under different feature encoders is as shown in Figure 8. The multi-scale residual module achieves the highest accuracy for wake and REM. However, the accuracy for light sleep is the highest on the CNN block module, and the accuracy for deep sleep is the highest on the residual module with a kernel size of 11. However, the multi-scale residual module has the best overall performance in each class. We compared the multi-class focal loss (MF) and the additional loss of sequence prediction with the cross-entropy loss (CE) to discuss the role of the proposed loss in training and domain adaptation, as shown in Table 7. We set the classifier loss to CE, MF, and MF with the additional loss, which computes the loss between the prediction based on the previous 30 s ECG and ground truth, respectively. For domain alignment, the performance of the model whose classifier uses MF far exceeds the performance of the model whose classifier uses CE. The problem of class imbalance causes the model to overfit for the head class with a large sample size. It is difficult to learn the true distribution of the samples, which affects the effect of domain adaptation.