# A Domain-Based, Adaptive, Multi-Scale, Inter-Subject Sleep Stage Classification Network
## 2 Materials and Methods  
In essence, with the given training set \(S=\left\{x_{s}^{(i)},\,y_{s}^{(i)}\right\}_{i\,=\,1,\ldots,n_{t}}\) and test set \(T=\left\{x_{t}^{(j)},\,y_{t}^{(j)}\right\}_{j\,=\,1,\ldots,n_{t}}\), which are sampled from joint distributions \(D_{s}=\left(X_{s},Y_{s}\right)\) and \(D_{t}=\left(X_{t},\,Y_{t}\right)\), respectively, the goal is to predict the labels \(Y_{t}\) of the test set when \(D_{s}\
eq D_{t}\), which leads to the poor generalization of the model. \(n_{s}\) and \(n_{t}\) are the numbers of sequences in the training set and test set. To improve the performance of classification, our proposed method, a multi-scale, inter-subject network, tries to extract multi-scale, detailed information for feature representation and to transform the feature space into a new one where \(D_{s}\approx D_{t}\) through mapping function \(\varphi(\cdot)\) to reduce domain shift. In addition, both S and T have the problem of class imbalance. The process of domain adaptation with multi-class focal loss is to learn 'hard' samples. To improve the predictive ability of the model, we also introduce historical information \(S_{it\,-\,1}=\left\{x_{s,ti\,-\,1}^{(i)},\,y_{s,\,ti}^{(i)}\right\}_{i\,=\,1, \ldots,n_{t}}\), which uses the previous 30 s sequence to predict the current state as a type of additional supervision information, where it denotes the current stage. An overview of the proposed method to optimize the above objectives is shown in Figure 1, which contains three steps. The process can be summarized as follows:  
Pre-training: The multi-scale residual feature encoder is pre-trained by the training set to be fine-tuned in the next step for domain adaptation. There are two classifiers combined to predict the sleep stage. One is updated by the multi-class focal loss to solve the class imbalance, and the other is updated by the supervised information from the previous 30 s ECG to predict the current sleep stage.  
Domain adaptation (DA): Maximum mean discrepancy (MMD) is introduced to the domain aligning layer to make the feature distributions of the training set and the test set confused during cross-iterative training.  
Figure 1: An overview of our proposed domain-based, adaptive, multi-scale network for sleep stage classification. First, the model is pre-trained on the training set. Classifier 1 makes predictions based on the current sequence, while Classifier 2 makes predictions based on the previous 30 s sequence. Next, the domain-aligning layer is utilized to adjust the high-level part of the feature encoder such that the domain gap between the training set and test set can be reduced during the process of classification. Finally, the test dataset is mapped with the adjusted feature encoder to the shared feature space and classified by Classifier 1. Dashed lines indicate fixed network parameters. The blue area indicates the part that needs to be adjusted.  
Testing: The adjusted feature encoder and Classifier 1 are frozen to predict the sleep stages of the test set. The model is evaluated by the accuracy and Cohen's Kappa metric (CK).