## 2 Materials and Methods
### Models  
CNNs have become ubiquitous in the DL literature for the capability to automatically perform feature extraction effectively due to their inherent translation-invariance characteristics. More specifically, CNNs capture local conjunctions of features, namely sub-samples (either spatially or temporally) to reduce data dimensionality, detect semantic similarities, and utilize a shared-weight architecture to provide generalizability. We employ 1D CNNs, which are appropriate for one-dimensional inputs such as physiological signals. A standard CNN structure is composed of a set of layers, where each layer narrows down different aspects of the input data through local receptive fields. A series of simultaneous and then successive convolutional filters operate in tandem to extract relevant features and consolidate a learned representation of the input data in the form of feature maps/vectors. For a single convolution \(c_{i}\) of a signal \(S_{i}^{0}=[s_{1},s_{2},\ldots,s_{n}]\), where \(n\) is the 1500 sampling points (30-second waveform at a frequency of 50 Hz), the following equation applies:  
\[c_{i}^{lj}=h\left(b_{j}+\sum_{m=1}^{M}w_{m}^{j}x_{i+m-1}^{j}\right) \tag{1}\]  
In Equation (1), \(l\) is the current layer index, \(h\) is the activation function, \(b\) is the bias of the \(j\)th feature map/vector, \(M\) is the kernel size, \(m\) is the filter index, and \(w_{m}^{j}\) is the weight of the corresponding feature map/vector. Recurrent neural networks, particularly LSTMs, have proven their efficacy in many applications such as speech recognition, language modeling, and time series forecasting. Their ability to focus on sequential patterns in the data serves the purpose of capturing long-term temporal dependencies to a considerable extent. A single LSTM cell is made up of the cell state, the hidden state,e and multiple gates, titled input \(i\), output \(o\), and  
Figure 2: Examples of OSA-Depression labels transformed into hypnodensity graphs and hypnograms. (**a**) Hypodensity plot for Patient 65492 with high OSA and depression; (**b**) Hypnogram plot for Patient 65492 with high OSA and depression; (**c**) Hypodensity plot for Patient 98255 with low OSA and depression; (**d**) Hypnogram plot for Patient 98255 with low OSA and depression. Color scheme for stages: Wake: White; N1: Gold; N2: Light Blue; N2: Dark Blue; N3: Green; REM: Red. forget \(f\) gates. The gates themselves are composed of a sigmoid layer and a point-wise multiplication operation and regulate the flow of specific gradients to the cell state. The cell state essentially aggregates the information accumulated from the preceding time steps, whereas the hidden state encodes the information from the immediate previous timestep. The functional output of the LSTM cell \(C\) at any point in time can be defined as  
\[C_{t}=f_{t}C_{t-1}+i_{t}c_{t} \tag{2}\]  
In Equation (2), \(f_{t}\) is the activation of the forget gate, \(i_{t}\) is the activation of the input gate, and \(c_{t}\) is the input to the main cell. With the output gate activation \(o_{t}\), the hidden-unit activations for a single cell are given by Equation (3):  
\[h_{t}=o_{t}\tanh(c_{t}) \tag{3}\]  
To address the unidirectional limitations of standard LSTM architectures in terms of being restricted to the previous context only, the solution proposed in [20] relating to the processing of data in both the forward and the backward directions is adopted. Let the forward layer consisting of \(T\) cells be indicated by \(h_{t}^{f}\), and the backward layer consisting of the same \(T\) cells be denoted by \(h_{t}^{b}\). The former processes the inputs in the fashion \([t_{0},t_{1},\dots t_{T}]\), while the latter processes in the opposite direction \([t_{T},t_{T-1},\dots t_{0}]\).