Multi-Class Sleep Stage Analysis and Adaptive Pattern Recognition

: Multimodal signal analysis based on sophisticated sensors, efﬁcient communication systems and fast parallel processing methods has a rapidly increasing range of multidisciplinary applications. The present paper is devoted to pattern recognition, machine learning, and the analysis of sleep stages in the detection of sleep disorders using polysomnography (PSG) data, including electroencephalography (EEG), breathing (Flow), and electro-oculogram (EOG) signals. The proposed method is based on the classiﬁcation of selected features by a neural network system with sigmoidal and softmax transfer functions using Bayesian methods for the evaluation of the probabilities of the separate classes. The application is devoted to the analysis of the sleep stages of 184 individuals with different diagnoses, using EEG and further PSG signals. Data analysis points to an average increase of the length of the Wake stage by 2.7% per 10 years and a decrease of the length of the Rapid Eye Movement (REM) stages by 0.8% per 10 years. The mean classiﬁcation accuracy for given sets of records and single EEG and multimodal features is 88.7% ( standard deviation, STD: 2.1) and 89.6% (STD:1.9), respectively. The proposed methods enable the use of adaptive learning processes for the detection and classiﬁcation of health disorders based on prior specialist experience and man–machine interaction.


Introduction
Polysomnography (PSG) represents a diagnostical tool of sleep medicine based on biophysiological changes that occur during the sleep.Multimodal data acquired in sleep laboratories form multichannel records that require wire attachments to the patients in most cases.Selected physiological signals are simultaneously monitored by specific sensors [1][2][3] and they form time series that are recorded with different sampling frequencies and often combined with videosequences acquired by infra and thermographic imaging cameras.Figure 1(a1,a2) present an example of a multichannel PSG record 5 s long used for diagnosis and classification of sleep disorders either by an experienced neurologist or by an automatic classification model.
The segmentation and pattern recognition process is based either on the analysis of the whole set of multimodal and multichannel PSG data or on the processing of data acquired by selected sensors only.The recorded PSG signals include an electroencephalogram (EEG), electro-oculogram (EOG), electrocardiogram (ECG), electromyogram (EMG), sound, movement, and breathing records (Flow), among others.Features detected by specific computational methods [4][5][6][7][8] are then used to help neurologists to make a diagnosis and propose the appropriate treatment.Sleep features are very specific and there exist many studies proposing machine learning [9,10] for the automatic detection of sleep stages [11][12][13][14].A specific interest is devoted to the use of hidden Markov models for automatic sleep staging [15][16][17], to the relation between the adjacent sleep segments, and to deep convolutional neural network [18,19] as well.Figure 2 presents the rapidly growing interest in the PSG data analysis as illustrated by the number of papers registered in the Web of Science (WoS) database.This increase can be observed both in the area of sleep stages classification (Figure 2a) and machine learning for detection of sleep disorders (Figure 2b).The mostly cited papers (according to the WoS) published recently and devoted to PSG include those of sleep stages classification [20] and machine learning for sleep disorders detection [21,22] with detail comparative reviews of methods and results achieved.The present paper is devoted to the statistical distribution of sleep stages related to age and diagnosis [23] and to their classification, using neural networks [24][25][26][27] with sigmoidal and softmax transfer functions.The mathematical features of each segment are summarized in the pattern matrix and associated with target classes specified by an experienced neurologist.The classification system is presented in Figure 1b.The proposed adaptive process incorporates the prior experience of a neurologist into the decision process using man-machine interaction.
The proposed algorithm was applied for the adaptive recognition and classification of sleep stages [20,[28][29][30][31][32] using both EEG data [13,33] and PSG signals, using their spectral components for the estimation of sleep features.Sleep scoring assumes the knowledge of the Flow, EMG, and EOG records in addition to EEG signals but they affect EEG records as well.This fact has motivated some authors to use EEG channels only [21] to classify sleep stages.
The training process analysed in the present paper results in the evaluation of the coefficients of a mathematical model for multiclass pattern recognition [34][35][36][37].The classification accuracy and cross-validation error were then used for comparing the results.The resulting mathematical model can be further updated using expanded databases of individuals and visual sleep scoring as well as the experience of a neurologist in the associated interactive process.
The proposed mathematical model forms a contribution to further automatic systems of sleep stages classification and data analysis for the evaluation of proportion of Wake and REM segments associated with the age of an individual.These information can provide an additional diagnostic tool in the clinical environment.
The present paper is organized as follows.Section 2 presents PSG data acquisition, pattern matrix construction and the methodology of machine learning for pattern recognition of sleep stages.Section 3 describes results of the age analysis of sleep stages and their classification using both multimodal and EEG features of individuals with different diagnosis.The final Section 4 is dedicated to the discussion and conclusion.

PSG Data Acquisition
The data studied include the own database of 184 polysomnography overnight observations [38][39][40] of patients recorded, diagnosed and classified by the authors in the sleep neurological laboratory.Table 1 presents a summary of the data for (i) 63 healthy individuals (36 males, 27 females); (ii) 77 individuals with sleep apnea (M = 48, F = 29); (iii) 16 individuals with restless leg syndrome (M = 8, F = 8); and (iv) 28 individuals with the restless leg syndrome combined with sleep apnea (M = 19, F = 9).Each of these records is about 8 hours long, segmented and classified into 5 sleep stages:  A selected EEG data segment 2 h long of a chosen individual together with its manual classification into 5 classes is presented in Figure 3a.The time localization of these classes specified by an experienced neurologist is shown in Figure 3c.

Pattern Matrix Construction
The classification of sleep stages was based on time segments 30 s long with the corresponding target classes specified by the neurologist during the learning process after the preceded signal preprocessing stage.This initial process included digital filtering for noise rejection and artefact removal [41,42].
Common preprocessing methods include the rejection of noise components present in each individual channel.Denoting a channel signal by {x(n)} N−1 n=0 , it is possible to use a selected digital filter with specified cutoff frequencies to define a new sequence {y(n)} N−1 n=0 .Finite impulse response (FIR) band pass filters of the 30th order were used in this case.Their cutoff frequencies corresponded with the frequency ranges of specific PSG channels used for classification.The selection of these frequencies was related to the physiological background of these signals and it included frequency ranges 0.5, 30 Hz for EEG channels, 0.05, 0.8 Hz for the flow channel, and 4, 40 Hz for the EOG channel.
A selected spectral feature FS of a signal segment was evaluated by the discrete Fourier transform as a relative power in the specified frequency band f c1 , f c2 by relation where Φ is the set of indices for which frequency values The construction of the pattern matrix P R,Q presented in Figure 1b assumes the evaluation of R features for each signal segment for As the length of each PSG segment is 30 s, the whole overnight record about 8 h (480 min) long includes on average Q = 960 segments for each individual.Each segment is described by R features that represent characteristics evaluated mostly in the time or frequency domains for one or more observed variables.Figure 3b presents an example of a distribution of EEG features evaluated from one EEG channel only, specifying the average power in selected frequency bands (1-4 and 4-8 Hz).For each feature vector, the associated sleep stage (class) is specified by the neurologist, thus forming the target class for the following classification process as specified in Figure 3c.

Machine Learning for Pattern Recognition
The pattern matrix P R,Q formed an input for the two-layer neural network presented in Figure 1b having R inputs, S1 neurons in the first layer and S2 neurons in the second layer.The outputs of individual layers included the values where define the arguments of the transfer functions F1, F2.
An associated matrix of target values T S2,Q with S2 = 5 rows was defined by the corresponding sleep stages specified by a neurologist in the learning stage (as presented in Figure 1b).For each column vector in the pattern matrix, the corresponding target vector has one unit element in the row pointing to the correct target value.The network coefficients included elements of the matrices W1 S1,R , W2 S2,S1 and associated vectors b1 S1,1 , b2 S2,1 .The proposed model used the sigmoidal transfer function F1 in the first layer and the probabilistic softmax transfer function F2 in the second layer.The values of the output layer, based on the Bayes theorem [43], using the function provided the probabilities of each class.Figure 1c,d present an example of estimated and target probabilities for selected sleep pattern vectors.Each column of the output matrix presents class membership to individual classes.
The training of the neural network was performed in the MATLAB (R2017b, The MathWorks, Inc., Natick, MA, United States, 2017) environment using 70% of pattern vectors for training, 15% for validation, 15% for testing, and random initial conditions.Model coefficients were updated for each new sleep record that decreased (with the upper 3% limit) the performance value calculated as the average squared error between the network outputs and target values.The optimization process was done by a single PC with the i7-6500U CPU (2.5 GHz), 16 GB RAM and the 64-bit operating system (Windows 10 Pro).
The evaluation of the classification results was performed by the analysis of the multi-class Receiver Operating Characteristic (ROC) [44,45] to illustrate the performance of the classifier system, and by a confusion matrix presented in Table 2 for classification into S classes.The associated common performance metrics are summarized in Table 3.The ROC analysis was performed on the basis of a pairwise comparison of one class against all other classes [46]...
Probability of global correct classification

Results
Figure 3a presents the results for a two hour long sleep record selected from the observation of an entire night in the sleep laboratory.The target sleep stages (input classes) associated with 30 s long EEG data windows diagnosed by the experienced neurologist are presented in Figure 3c.The adaptive system was constructed as a two layer neural network with the sigmoidal and softmax transfer functions.Figure 3d presents the evaluated probabilities of the individual classes.The estimated sleep stages pointing to sleep stages with the highest probability are presented in Figure 3e.
The classification results obtained by the neural network system were compared with those achieved with the k-nearest neighbour and decision tree methods (Table 4).The process of class selection and evaluation of class boundaries of the sleep stages is illustrated in Figure 4 for the two features and their classification.The classification accuracies and cross-validation errors evaluated by the leave-one-out method for a sample two-hour long EEG record are presented in Table 4. Input features include relative power in 4 frequency bands (1-4, 4-8, 8-12, 12-20 Hz).For the given set of features, the neural network model provide classification results with higher accuracy and lower cross-validation error than did the k-nearest neighbour and decision tree methods.
The methodology of sleep stages processing verified for short records was then applied for an extensive set of 184 individuals specified in Table 1.The results of its analysis with statistical distribution of sleep stages related to age is presented in Figure 5. Linear approximation of these values together with estimation of 95% confidence bounds were evaluated.Resulting regression coefficients point to an average increase of the length of the Wake stage by 2.7% per 10 years and a decrease of the length of the REM stage by 0.8% per 10 years.
Figure 6 presents more detail analysis of the resulting lengths of the sleep stages [47] related to the age for the whole set of 184 individuals divided according to their diagnosis as determined by experienced neurologists.A well documented increase of the Wake stages and decrease of REM stages related to age is confirmed for healthy individuals and patients with sleep apnea.For patients with restless leg syndrome, no such distribution was observed.The summary of associated regression coefficients with their 95% confidence bounds are presented in Table 5.Table 6 presents the summary of the results for the individuals specified in Table 1 with 4 different diagnoses and their classification into three classes (C1: Wake, C2: NonREM, C3: REM).The learning performance was evaluated by the cross-entropy for given targets and network outputs.The last column of Table 6 presents cross-validation errors evaluated by the K-fold cross-validation method (for K = 10).A comparison of the classification results was performed using 1. the EEG channels only, with patterns evaluated as mean energies in 5 selected frequency bands The values in Table 6 show nearly no difference between males and females and a slight improvement of the performance and accuracy of the neural network model using multimodal features consisting of 12 items instead of 5 EEG features associated with each segment.

Diagnosis (Male)
Precission (%) Recall (%) Acc.Perf.An analysis of the features in each 30 s long PSG segment was then performed for spectral components in selected regions for the EEG, Flow and OCG channels for all 184 individuals.This resulted in the specification of the pattern matrix for the adaptive classification by the two layer neural network after the learning process based on associated target values.Results for the training, validation and test sets for healthy individuals (after about 15,000 training epochs) are presented in associated confusion matrices presented in Table 7 for classification into three classes using 12 (F12) multimodal (EEG, Flow and ECG) features.The highest true-positive rate was achieved for the second (NonREM) class and all these sets.The final results including the accuracy and the performance of neural network models for different sleep disorders and male/female sets of individuals are presented in Figure 8.The results show the similarity in the accuracy for features evaluated from the single EEG channel (F5) and different multimodal (EEG, Flow and OCG) channels (F12).The slightly lower accuracy achieved for females in this case can be explained by the higher deviations of the associated features.The mean classification accuracy is 88.7% (STD: 2.1) and 89.6% (STD: 1.9), respectively, for the given sets of records and classification using single (F5) and multimodal (F12) features.This result can be explained by the presence of additional attributes in the EEG channel.The accuracy achieved corresponds with that published in [25] for a smaller group of individuals and different feature sets.
Table 8 presents the summary of both the achieved global classification accuracy, the K-fold cross-validation errors (for K = 10) and the precision of classification into three classes over all sleep disorders with associated detailed values summarized in Table 6.

Conclusions
This paper presents a method involving multi-class classification applied to the recognition of sleep stages using a two layer neural network with the sigmoidal and the softmax transfer functions to evaluate the probabilities of the output classes.The training set includes overnight PSG records of 184 individuals forming an own database acquired and classified by the authors.
The proposed method allows the construction of a neural network and its training to recognize sleep stages with a mean classification accuracy of 88.7% (STD: 2.1) specified in Tables 6 and 8 for selected spectral features of the single EEG channel.The accuracy increased to 89.6% (STD: 1.9) for multimodal features obtained from EEG, flow and EOG channels was not too high, probably owing to the presence of corresponding artifacts in the EEG channels.The mean 10-fold cross-validation error decreased from 0.16 (for 5 EEG features) to 0.12 (for 12 multimodal features).
The novel approach of the proposed method is the possibility of constructing a mathematical model incorporating the individual experience of a neurologist, allowing a data classification close to his previous strategy and an adaptive modification of model coefficients.Results obtained are compared with selected existing methods in Table 9.The accuracy of sleep stages classification is generally between 70% and 92% [22] and the accuracy of the current model is close to the upper limit of this range.It is projected that the neural network model will be further used for more extensive datasets and adaptation of the results to the experience of the neurologist to reduce the time necessary for manual classification.A special attention will be paid to deep convolutional neural networks [17,18] that allow row data processing without specification of separate features.

Figure 1 .
Figure 1.Principle of sleep feature classification using a two-layer neural network with sigmoidal and softmax transfer functions presenting (a1,a2) a sample record of multichannel data 5 s long recorded with the sampling frequency of 200 and 10 Hz, respectively; (b) neural network structure for pattern recognition estimating probabilities of individual classes and evaluating the most probable class for each column vector of input features; and (c,d) evaluated and target probabilities (%) of output classes for selected patterns (detail of Figure 3d and S2 = 5).

Figure 2 .
Figure 2. The time evolution of number of journal papers devoted to analysis of (a) sleep stages and their classification and (b) sleep disorders and machine learning according to the Web of Science.

Figure 3 .
Figure 3. Two-hour long analysis presenting (a) EEG signal segmented into 5 classes and (b) features standing for the mean power in selected frequency ranges (1-4 Hz, 4-8 Hz) in subsequent 30 s long windows forming neural network pattern values; (c) target sleep classes forming desired neural network output; (d) probabilities of evaluated classes by the two layer neural network; and (e) resulting classes with the highest classification probability.

Table 2 .
The confusion matrix for the evaluation of a model classifying pattern vectors belonging to true (target) classes and estimating their (predicted) classes for the multi-class classification into S categories.

Table 3 .
Common performance metrics of the confusion matrix for the multi-class classification.Characteristics Definition CommentPPVPrecision of class k (pos.predict.value) TP(k) TP(k) + FP(k) Probability of correct classification of class k related to the number of instants classified to class k TPR Sensitivity of class k (True positive rate, recall) TP(k) TP(k) + FN(k) Probability of correct classification of class k related to the number of instants belonging to class k TNR Specificity of class k (True negative rate) TNK TNK + FPK TNK=∑ TP(j) , FPK=∑ FP(j), j =k Probability of incorrect classification of class k related to the number of instants not classified to class k FPR False positive rate FPK TNK + FPK Probability of positive classification for the negative set (1-specificity)

Figure 4 .
Figure 4. Classification of sleep stages presenting (a) class selection for the 5-nearest neighbour method and (b) class boundaries of the computational model and two features evaluated as the mean power in selected frequency ranges (1-4 Hz, 4-8 Hz).

Figure 5 .
Figure 5.The distributions of the lengths of the Wake and REM sleep stages related to age for the whole set of 184 individuals under study.

Figure 7
Figure 7 presents the target and predicted classes of three selected patients with sleep apnea classified into three classes, including (a) class 1 (Wake), (b) class 2 (NonREM), and (c) class 3 (REM).The associated ROC characteristics in Figure 7d show the true positive rate of each class against the false positive rate of all other classes.The final results including the accuracy and the performance of neural network models for different sleep disorders and male/female sets of individuals are presented in Figure8.The results show the similarity in the accuracy for features evaluated from the single EEG channel (F5) and different multimodal (EEG, Flow and OCG) channels (F12).The slightly lower accuracy achieved for females in this case can be explained by the higher deviations of the associated features.The mean classification accuracy is 88.7% (STD: 2.1) and 89.6% (STD: 1.9), respectively, for the given sets of records and classification using single (F5) and multimodal (F12) features.This result can be explained

Figure 7 .
Figure 7. Target and predicted classes of three selected patients with sleep apnea classified by the adaptive neural network model into three classes including (a) class 1 (Wake); (b) class 2 (NonREM); and (c) class 3 (REM) together with (d) associated ROC characteristics.

Figure 8 .
Figure 8. Results of the training process presenting (a) the accuracy and (b) the performance of the resulting model for different sleep disorders for sets of male and female individuals using EEG (F5) and multimodal EEG, Flow and OCG (F12) features.

Table 1 .
Specification of the set of 184 individuals under study (M: number of males, F: number of females) with their age distribution, including (i) healthy individuals; (ii) individuals with sleep apnea (SA); (iii) individuals with the restless leg (RL) syndrome; and (iv) individuals with RL syndrome and sleep apnea syndrome

Table 4 .
Comparison of the accuracy and cross-validation for classification of sleep features evaluated during the two-hour long observation and 30 s long time windows by the neural network, nearest neighbour, and decision tree models.

Table 5 .
The summary of regression coefficients (RC) of the age dependence of Wake and REM sleep stages with their 95% confidence bounds.

Table 7 .
Confusion matrix of the classification neural network model for the training, validation, and test sets of sleep stages (for healthy individuals) with true positive values on the matrix diagonal (in the bold).

Table 8 .
Classification accuracy and the 10-fold cross-validation errors of the sets of males and females and precision of individual classes over all sleep disorders for 5 (F5) mean EEG power features and 12 (F12) features with an additional 4 features evaluated from the flow and electro-oculogram channels.

Table 9 .
A comparison of the proposed method with further published results.