## 2 Methodology
### Emotion Recognition Method Based on Sparse Auto-Encoder and Support Vector Machine
#### 2.2.1 Feature Selection of Respiration Signals Based on Sparse Auto-Encoder  
An SAE is a deep-learning method used to automatically learn features from unlabeled data. As a fundamental element of an SAE, an autoencoder (AE) transforms input data into hidden representations or extracts features through an encoder (Figure 10). The AE learns to map these features back to the input space using a decoder. Despite the presence of minor reconstruction errors in the training examples, the goal was to match the reconstructed input data to the original input data as closely as possible. The entire structure uses the features extracted by one AE as the input for another AE, thereby hierarchically determining general representations from the input data [40]. Figure 10: Structure of an auto-encoder. Figure 9: Structure of SAE-SVM classification system. Therefore, the SAE pre-trains the AE and uses it as its first hidden layer. These techniques can also be applied to train subsequent hidden layers. Once pre-training is complete, the first layer remains unchanged, while the other hidden layers are trained. Generally, the encoder maps the input example \(x\in R^{n}\) to the hidden representation \(h(\mathbf{x})\in R^{m}\) as follows:  
\[\mathrm{h}(\mathbf{x})=\mathrm{f}(\mathbf{W}_{1}\times\mathbf{x}+\mathbf{b}_{1 }), \tag{4}\]  
where \(\mathbf{W}_{1}\in R^{m\times n}\) is a weight matrix, \(\mathbf{b}_{1}\in R^{m}\) is a bias vector, and \(f(z)\) is a nonlinear activation function, typically a sigmoid function \(f(z)=1/(1+\exp(-z))\). The decoder maps the hidden representation back to the reconstructed input \(\widetilde{\mathbf{x}}\in R^{n}\):  
\[\widetilde{\mathbf{x}}=\mathrm{f}(\mathbf{W}_{2}\times\mathrm{h}(\mathbf{x}) +\mathbf{b}_{2}), \tag{5}\]  
where \(\mathbf{W}_{2}\in R_{m\times n}\) is a weight matrix, \(\mathbf{b}_{2}\in\mathbf{R}_{n}\) is a bias vector, and \(f\) is the same function used in the encoder. To minimize the difference between the original input xxx and reconstructed input x\(\sim\)\(\mathrm{i}\)lide\(\{\mathbf{x}\}\)x\(\sim\), we consider reducing the reconstruction gap \(\sum_{i=1}^{D}\left\|\mathbf{x}^{(i)}-\widetilde{\mathbf{x}}^{(i)}\right\|\). Given a training dataset \(\mathbf{x}^{(i)},\ i=1,\cdots,D\) with \(D\) examples, we adjust the weight matrices \(\mathbf{W}_{1}\) and \(\mathbf{W}_{2}\) as well as the bias vectors \(\mathbf{b}_{1}\) and \(\mathbf{b}_{2}\) through backpropagation. In addition, we impose a sparsity constraint on the expected activation of the hidden units by adding a penalty term. This leads to the following optimization problem:  
\[\mathrm{min}\sum_{i=1}^{P}\left\|\mathbf{x}^{(i)}-\widetilde{\mathbf{x}}^{(i) }\right\|^{2}+\beta\sum_{j=1}^{m}\mathrm{SP}\left(\rho\left\|\hat{\phi}_{j} \right.\right). \tag{6}\]  
The sparse penalty term is  
\[\mathrm{SP}\left(\rho\left\|\hat{\phi}_{j}\right.\right)=\rho\mathrm{log}\, \frac{\rho}{\hat{\phi}_{j}}+(1-\rho)\mathrm{log}\,\frac{1-\rho}{1-\hat{\phi}_ {j}}, \tag{7}\]  
where \(\hat{\phi}_{j}=\frac{1}{D}\sum_{i=1}^{D}h_{j}\left(\mathbf{x}^{(i)}\right)\) is the average activation of hidden unit, \(j\), \(\rho\) is the sparsity level, and \(\beta\) is the weight of the sparsity penalty term. By minimizing the cost function using the L-BFGS (Limited-memory BFGS) algorithm [41], we obtain the optimal \(\mathbf{W}_{1}\) and \(\mathbf{b}_{1}\) to determine the internal features \(h(\mathbf{x})\). We trained the SAE to extract features from the RSP signals and emotional states present in the dataset. Through preliminary experiments with one- and two-layer SAEs and by testing with 20 neurons in each hidden layer, we selected the topology of the AE. After pretraining each layer of the SAE, we fine-tuned the deep learning framework to obtain the optimal SAE configuration with two hidden layers. The first and second hidden layers contained 200 and 50 neurons, respectively. To demonstrate the reconstruction capability of the SAE, we inputted the same RSP signal (shown in blue) from Figure 8 into the SAE.