## 2 Materials and Methods
### Handling Class Imbalances  
Standard LSTM NN models are not capable of handling imbalanced classes, as NNs are trained by calculating errors made by the model on the training splits. Therefore, model weights are updated in proportion to estimation error of training split using the backpropagation algorithm. Thus, samples from different classes are treated equally during training, and the model is trained to classify samples from the majority class, resulting in poor performance for samples from minority classes. To handle the imbalanced classes, we tested four different approaches: upsampling, downsampling, weighted training, and ADASYN [59; 60]. Upsampling minority classes is achieved by bootstrapping samples in the minority classes until the number of the training samples in all classes is balanced. In a random downsampling method, majority classes are downsampled by randomly removing samples until the training samples of all classes are balanced. In certain cases, random downsampling can result in the loss of valuable information, resulting in a loss of performance during classification. In weighted training/cost-sensitive optimization [61; 62], the optimizer and the loss function are updated to weigh samples inversely proportional to the number of the samples in each class. Hence, large weights are applied to the samples in the minority class and smaller weights are applied to the samples of the majority class. Figure 5: (**a**) The structure of a regular LSTM unit and (**b**) the architecture of an LSTM–Dense layer NN model. The size of the softmax layer was set to three units for estimating different variations of APS and PA and four units for estimating both together. \begin{table}
\begin{tabular}{l c} \hline \hline
**Variable** & **Value/Technique** \\ \hline Number of nodes in the dense layer & 40 \\ Number of nodes in the LSTM layer & 40 \\ Number of nodes in the softmax layer & 3 or 4 depending on the classification problem \\ Dropout in the LSTM layer & 20\% \\ Dropout in the dense layer & 20\% \\ Learning rate & \(10^{-5}\) \\ Optimization algorithm & Adam \\ \(\beta_{1}\) & 0.9 \\ \(\beta_{2}\) & 0.999 \\ \(e\) & \(10^{-7}\) \\ Size of batches & 10,000 \\ Activation function & ReLU \\ Number of epochs & Variant, depending on the target variable and the size of samples \\ \hline \hline \end{tabular}
\end{table} 
Table 3: The value of adjustable parameters used in the NN classifier model. The main reason for using ADASYN to balance classes is to generate synthetic samples for minority classes. Therefore, additional synthetic data are generated for minority class samples that are harder to learn compared to those minority samples that are easier to learn. ADASYN is a modified technique of synthetic minority class oversampling (SMOTE) [63; 64]; it uses density distribution to adaptively generate a number of synthetic samples, whereas SMOTE generates an equal number of synthetic samples for each minority class. The pseudocode of Algorithm 1 is provided below in order to better summarize the model training pipeline. ```
1:procedureData-preprocessing-and-model-fitting(\(BVP,Acc_{t},GSR,ST,Class_{Labels}\))
2:- Sync all biosignals of Empatica E4 with the corresponding \(Class_{Labels}\)
3:- For each subject segment \(BVP\), \(Acc_{x}\), \(Acc_{y}\), \(Acc_{z}\)\(GSR\), \(ST\), \(Class_{Labels}\) as demonstrated in Figure 2
4:for j = 1:\(N_{subjects}\)do\(\triangleright\)\(N_{subjects}\) denote the number of all subjects (datasets)
5:for\(k=1:N\)do\(\triangleright\)\(N\) denote the number of segments in dataset
6:- Filter out each segment \(Acc^{j}_{t,k^{\prime}},t\in\{x,y,z\}\) with \(4^{th}\) order bandpass filter
7:- Filter out each segment \(BVP\) with \(4^{th}\) order bandpass filter ([0.2-3.3] Hz)
8:- Upsample each segment \(GSR^{j}_{k}\) by two and extract SCL and SCR. (See [65] for more info.)