# Efficient Sleep-Wake Cycle Staging via Phase-Amplitude Coupling Pattern Classification
## 2 Material and Methods
### Multilayer Perceptron Artificial Neural Network  
A feedforward multiclass neural network known as the multilayer perceptron (MLP) was used in this work to classify the sleep stages, namely, WK, SWS, and REM, based on the information extracted from the set of \(MI\) values (Figure 1B). The MLP architecture was shallow and comprised three layers: input, hidden, and output. The input layer receives features extracted from the set of \(MI\) values (or PAC patterns), while the hidden layer performs computations and transformations to learn complex relationships within the data. The output layer yields the final predictions as binary classifiers of each stage based on the learned representations from the preceding layers. Thus, the number of neurons in the output layer was always three, one for each of the stages of interest, while the number of input and hidden neurons varied in search of the best architecture. The number of input neurons depended on the choice of the input dataset (see Section 2.4.1). To determine the number of neurons in the hidden layer, empirically established guidelines were considered. The widely employed rule of thumb for this case suggests that the optimal size of the hidden layer typically lies between the dimensions of the input and output layers (Figure 1B, but see Section 2.4 for more details). For training the network, information was processed using the logistic sigmoid activation function in the hidden-layer neurons and the softmax activation function was employed in  
Figure 1: The experimental design: an assessment of the network architectures was performed in phase 1 of the experiments, which is depicted in panels A to C, and simulation of the application of the network with novel data with decreasing ratios of the train to test dataset extrapolations were performed in phase 2, depicted in panel D. (**A**) The input data: four different protocols were used for the construction of the input data, frequency points, frequency ranges, full comodulogram, and first (1–10 Hz) half of the comodulogram (left panels); the values were computed for each 30 s time window for all the animals and all the days and, thus, the input data were N (_M1_ values) \(\times\) 480 (time windows) \(\times\) 10 (animals) \(\times\) 5 days. (**B**) The multilayer perceptron (MLP) architecture consisted of an input layer (number of neurons equals to number of _M1_ values), a hidden layer (number of neurons varied), and an output layer with three neurons, one for each sleep stage. (**C**) The ROC curve for all possible combinations of inputs and networks were computed and the AUC values obtained to determine the best performing choice. (**D**) Using the best performing network architecture, four different extrapolation strategies were tested in order to simulate usage in a lab scenario, from left to right: train with 70% and test 30% of the dataset; train with the first day of all the animals to test on all the other days; train with all the days of the first animal and test with all the other animals; and train with one day of one animal to test on the rest of the dataset. the neurons of the outer layer to generate the final output. As a shallow network, issues like gradient vanishing are unlikely to occur and thus more sophisticated (and complex) algorithms such as ReLU (Rectified Linear Unit) are not needed. The error obtained at each parsing of the data was then used to update the network's weights using the scaled conjugate gradient (SCG) algorithm. This algorithm, a second-order optimization method, was chosen due to its efficiency in handling large-scale machine learning problems [35; 36; 37]. Here, the SCG optimized the Binary Cross-Entropy loss function, which is highly applicable to multi-label classification problems such as this. It is also the default when using Matlab(r) 2023b libraries. A total of 1000 epochs were employed in the training process to ensure adequate learning while preventing overfitting.