## 7 Conclusions
The study and approved by the Institutional Review Board (Ethical Committee of the School of Medicine, University of Split) under protocol number 003-08/23-03/0015, dated 17 October 2023. Patient consent was waived due to minimal risk to participants as stated in the ethical committee's review. The data collection and privacy safeguards are in compliance with GDPR (General Data Protection Regulation 2016/679), ensuring anonymity and confidentiality of all participant data. The data supporting the reported results are not publicly available due to privacy and ethical restrictions. Access to the data is restricted to authorized personnel only. The authors declare no conflicts of interest. The choice of architecture, specifically one LSTM layer followed by three dense layers, was made after evaluating multiple configurations during preliminary testing. Initialexperiments with additional LSTM layers, during which data from the initial 16 patients were exclusively used in the experimentation phase, resulted in overfitting, as indicated by the deterioration of performance on the validation dataset. Using a single LSTM layer preserved temporal dependencies without adding excessive model complexity. The dense layers allowed for progressive feature refinement, enabling the model to capture both high-level and granular features of the SpO2 signal. This configuration demonstrated the best balance between recall and generalizability, which are critical for detecting apnea events in diverse patient data. Long Short-Term Memory (LSTM) networks are a specialized type of recurrent neural network (RNN) designed to overcome issues such as vanishing and exploding gradients that typically affect traditional RNNs. LSTM networks are distinguished by their ability to store information over extended periods thanks to three main gates: the input gate, forget gate, and output gate. These gates, along with the cell state, allow the LSTM to retain and manage memory over time, preventing the degradation of data that happens in traditional RNNs [26], as visualized in Figure 11. This feature makes LSTM particularly well suited for tasks that involve learning long-term dependencies in sequential data [27]. Within each LSTM cell, a series of operations control the flow of information through the network, enabling the model to selectively keep or discard information. The following key operations occur [28]:  
* The input gate \(i(t)\) (A1) controls how the current input and the previous hidden state contribute to the memory. * The forget gate \(f(t)\) (A2) decides which parts of the previous cell state \(c(t-1)\) should be discarded. * The output gate \(o(t)\) (A3) determines which elements of the cell state will be used for the output and the next hidden state. * The cell state \(c(t)\) (A5) is updated by combining the previous state \(c(t-1)\) with the newly processed information, enabling the model to retain the relevant data over time. The operations within each LSTM cell are governed by the following equations:\[i_{(t)}=\sigma(W_{xi}^{\mathsf{T}}\cdot x_{(t)})+W_{hi}^{\mathsf{T}} \cdot h_{t-1}+b_{i}) \tag{11}\] \[f_{(t)}=\sigma(W_{xf}^{\mathsf{T}}\cdot x_{(t)})+W_{hf}^{\mathsf{T} }\cdot h_{t-1}+b_{f})\] (12) \[o_{(t)}=\sigma(W_{xo}^{\mathsf{T}}\cdot x_{(t)})+W_{ho}^{\mathsf{T }}\cdot h_{t-1}+b_{o})\] (13) \[g_{(t)}=tanh(W_{xg}^{\mathsf{T}}\cdot x_{(t)}+W_{hg}^{\mathsf{T} }\cdot h_{t-1}+b_{g})\] (14) \[c_{(t)}=f_{(t)}\otimes c_{(t-1)}+i_{(t)}\otimes g_{(t)}\] (15) \[y_{(t)}=h_{(t)}=o_{(t)}\otimes tanh(c_{(t)}) \tag{16}\]  
where the following apply:  
* \(\sigma\) represents the sigmoid activation function, which outputs values between 0 and 1. * \(W\) represents the weight matrices for both the input \(x(t)\) and the previous hidden state \(h(t-1)\). * \(b\) is the bias term for each gate. * \(g(t)\) (14) is used to update the cell state using the _tanh_ function, which outputs values between \(-1\) and \(1\).