Deep Learning Based Recurrent Neural Network Model for Stress Detection in EEG Signals

ABSTRACT


INTRODUCTION
The ElectroEncephalogram (EEG) signal demonstrates exceptional temporal resolution, enabling the detection of events occurring on millisecond time scales.However, its spatial resolution is hindered by the presence of tissues, such as the skull, which envelop the electric fields generated by the brain, introducing a layer between the sources and the sensors.As a result, EEG channels frequently exhibit high spatial correlation.Addressing the source localization problem, or inverse problem, is a vibrant area of research wherein algorithms are actively being developed to reconstruct brain sources from EEG recordings.EEG finds in diverse applications, particularly in clinical settings.Changes in the brain's electrical activity are associated with various conditions, making EEG a valuable tool for monitoring disorders such as Attention Deficit Hyperactivity Disorder (ADHD), disorders of consciousness, depth of anesthesia, and more.In neuroscience and psychology research, EEG is extensively employed as a powerful tool for investigating the brain and its functionalities.Applications like cognitive and affective monitoring show great promise, offering the potential for unbiased measurements of various aspects, such as an individual's fatigue level, mental workload, mood, or psychological states like stress [1].Electroencephalography (EEG) signals represent the measurement of electric fields produced by the active brain.It illustrates a commonly employed brain mapping and neuroimaging technique extensively utilized both within and beyond the medical domain.The EEG as a complex signal requires various feature extraction methods to properly interpret it.Recently, the ability of deep learning (DL) to learn good features representations has shown promising analysis results to well understand the EEG signals, representing many states such as: epilepsy, sleep, brain-computer interfaces, cognitive and emotional monitoring.However, in some cases long time negative emotions can affect people directly with psychological diseases.A human life being can caused by stress affects.The recorded potentials mirror stress-induced neuronal activity, facilitated by the rapid propagation of electric fields.Major scientific and engineering databases were queried to identify DL design decisions which play an important part in our daily lives.Emotions are not a mood, nor even a temperament.These fleeting states, enduring for a brief duration ranging from seconds to minutes, are employed for investigating various brain processes, facilitated by the rapid propagation of electric fields.

Contributions
In this context, we focus through this work to achieve an automatic stress detection from EEG signals using deep learning algorithms.Thus, we aim to help clinician to get the early stress diagnosis at first stage.For this fact, we proposed a. RNN to be implemented on the CPU.As a first step, we realized that our RNN had to be implemented on the EEG signals available from Kaggle repository.The implementation results show the effectiveness of our goal, achieving accuracy results of 98.86%, 98.61% and 98.39% for the training, validation and test processes respectively.Then, to improve the inference results, we accelerated the process by times compared to implementation on the CPU thanks to the parallel architecture of GPUs, what's more, a real-time application was achieved with excellent class detection accuracy rising to 99.45% for training, 99.12% for validation and 99.03% for process tests, when tested on EEG signals in a short-time process with 0.002 s/signal during the process test and 0.006 s/ EEG signal during the training process.
The rest of the paper is divided as follows.Section 2 illustrates the state-of-the-art methods for automatic stress detection in EEG signals with a comparative study between various neural networks models.The next section illustrates the proposed methodology-based pre-processing and proposed neural network model.Section 4 analyses achieved EEG classification results.Section 5 discusses the achieved results.It shows clearly that the proposed detection approach surpasses the state-of-the-art algorithms in terms of detection accuracy as well as detection speed.Finally, a conclusion and future works are suggested in Section 6.

STATE OF THE ART
Emotions constitute human responses to events, influencing the entire body.Given their integral role in daily life and significant contribution to nonverbal communication, psychologists have dedicated decades to their study.Every encountered object serves as a stimulus eliciting emotional reactions, with the nature of the emotion being positive if the stimulus is favorable.Irrespective of the specific emotion, human emotions can be conveyed through various forms of emotional expressions, including psychophysiology, facial expressions, gestures, or biological responses.Researchers have dedicated substantial efforts to the development of intelligent emotion recognition systems, with some relying on non-physiological signal groups [2][3][4].The brain's reaction to various stimuli is typically assessed by segmenting EEG signals into distinct frequency rhythms, including delta (0.5-4Hz), theta (4-8Hz), beta , and gamma (32Hz and above).These frequency bands are prevalent in different regions of the brain [5].Nandini et al. [6] introduced an emotion recognition model based on the DEAP and AMIGOS database.In discerning emotions, the authors employed a hybrid neural network based on GRU-RNN.For accuracy reporting, the authors focused the use of new hyper parameter called hyperopt to improve accuracies results, achieving more than 99%.Thus, the robustness of RNN to improve classification EEG signals.In their methodology, Agrawal et al. [7] explored emotions such as sadness, fear, happiness, and disgust.They utilized spectral features to extract emotions from 15 subjects, concentrating on the alpha and beta wave bands.The evaluation of system performance involved the consideration of Fp1, Fp2, F3, and F4 channels.Additionally, Sallam et al. [8,9] [10] have proposed a hybrid neural network model to automatically predict stress in EEG signals, the first represent a combined LSTM with PSO, achieved results have yielded 97%.Moreover, various neural networks models have been proposed such as Stress Net where the model exceeds the accuracy of human stress detection, reaching 97.8% accuracy [11].Temporal Attention module has been implemented for stress detection achieving an accuracy going to 85.1% [12].Physionet EEG data records are used to determine stress levels for mental arithmetic tasks.Multichannel EEG signals (recorded from 19 channels) underwent denoising and were decomposed into four levels through the discrete wavelet transform (DWT).In addition, the neural organization (NN) as ANN deep learning model has been put forward associating fractal aspects with measurable elements where four levels of stress can be perceived with a typical accuracy of 96.06% [13].Whereas, RNN models including LSTM have been implemented to classify stressed and no stressed reaching a maximum of accuracy equal to 93.17% in the study [14].Subsequently, the classification of stress levels was performed using Bidirectional Long Short-Term Memory (BiLSTM) as a Recurrent Neural Network (RNN) model.The accuracy of the proposed model is evaluated in comparison to a CNN-based Long Short-Term Memory (LSTM) model and previous studies.The findings demonstrated that the hybrid model outperformed others, achieving a higher classification accuracy of 99.20%.In addition, authors [15] have combined a convolutional neural network CNN with Bilateral Long Shot term Memory (BiLSTM) model getting the highest emotion detection accuracy of 88.03% and outperformed the conventional shallow learning approaches [16].State of the works, has significantly proved the importance of RNN in the detection of stress with high accuracies results, high F1-score, excellent sensitivities and specificities.It has been explained by the light weighted architecture of such RNN model and then less complexity and less computational operations.Moreover, RNN models have the advantages to be.
The RNN performances achieved by state of the art has been explained by its specificity which lies in the fact that weights are equal for all layers.This reduces the number of parameters in the model, and thus its complexity.In this context and given the crucial role played by RNN models, we opt through this work to propose a RNN light weighted architecture base GRU for early stress detection.

PROPOSED CNN METHOD
The proposed solution for ECG classification as illustrated by Figure 1 2. The database comprises physiological signals gathered from 32 participants and was curated with the goal of establishing an adaptive music video recommendation system that takes into account the user's present emotional state.The DEAP database has been utilized in various studies, proving its suitability for testing novel algorithms.In assessing our proposed classification method, we employed the preprocessed EEG dataset from the DEAP database.The original recorded data, with a sampling rate of 5 Hz, underwent downsampling to 128 Hz.Additionally, a frequency filter bandwidth of 4.0 to 45.0 Hz was applied, and EEG artifacts were meticulously removed from the signals.

FFT application
However, EEG is challenged by limited spatial resolution, as the electric fields produced by the brain are obscured by intervening tissues, such as the skull, situated between the sources and the sensors.Consequently, EEG channels frequently exhibit high spatial correlation.Within the domain of stress detection using EEG signals, a crucial technique involves incorporating the Fast Fourier Transform (FFT) into a Recurrent Neural Network (RNN) model based on Deep Learning.FFT plays a crucial role in unveiling the frequency characteristics embedded in EEG signals, allowing for a more nuanced understanding of the brain's response to stress.This integration enhances the model's capacity to capture intricate patterns in the frequency domain and effectively contributes to the development of robust stress detection models.Before delving into the role of FFT, the raw EEG signals undergo preprocessing.This step involves filtering, detrending, and normalization to ensure the removal of artifacts and enhance signal quality.Subsequently, the EEG signals are subjected to FFT, transforming them from the time domain to the frequency domain.This transformation is essential for extracting relevant frequency features that convey crucial information about stress states.
The Fast Fourier Transform is a computational algorithm that efficiently calculates the discrete Fourier transform (DFT) of a sequence.In the context of stress detection in EEG signals, FFT plays a central role in decomposing the signals into their constituent frequency components.This transformation enables the extraction of features such as power spectral density (PSD) and dominant frequencies, providing a comprehensive representation of the frequency content inherent in stress-related EEG patterns.The equation for the Fast Fourier Transform (FFT) algorithm can be expressed as follows: where: • X[k] is the complex value representing the frequency.content at the k-th discrete frequency.• x[n] is the discrete signal in the time domain.
• N is the length of the signal.
• j is the imaginary unit.
The performance of the integrated FFT and RNN model is rigorously evaluated using standard metrics such as accuracy, precision, recall, and F1 score.This evaluation assesses the model's ability to accurately classify stress levels based on the intricate patterns revealed through FFT.The integrated approach proves valuable in providing a holistic and detailed analysis of EEG signals, showcasing its potential for real-world applications in stress detection and management.The integration of FFT within a Deep Learning-based RNN model establishes a synergistic approach for stress detection in EEG signals, combining the strengths of frequency analysis and temporal modeling to achieve enhanced accuracy and interpretability in stress-related pattern recognition as presented by Figure 2.

GRU architecture
The proposed RNN architecture is as depicted in Table 3.As presented in Figure 3, The Gated Recurrent Unit (GRU) Network architecture involves vectors, representative of weights and biases.It consists of a reset gate, an update gate.The reset gate decides how much information to be forgotten, however the update gate decides how much of future information should be passed.Compared to LSTM, GRU is simpler to implement, requires fewer parameters, and exhibits superior performance in many scenarios.As illustrated by Figure 3, the input EEG dataset raw has been fed-up through the reset gate, as inputs defined by (Xt) at time t, where we have applied an activation function represented by (σ, tanh).Using various input weights such as Wα, WZ and output weights of the model such Wĥ, Wo.Then passing through the update gate, where αt update (Zt) and output (ht) at time t.The outputs of gates ĥt and ĥt−1 represent the EEG outputs at times t and t-1 respectively using y t to denote the training sample output at time t.Following the GRU layer, the output features undergo processing through a flatten layer.Subsequently, prior to entering the fully connected layer, the data undergo softmax activation, and all activation functions are reset.For optimization, the Adam technique is employed with 10 epochs and 38 iterations.A learning rate of 0.0001 is set to expedite the training of the neural network as depicted in Table 4.

Experimental parameters
To implement our proposed RNN algorithm, python, Keras and tensor flow library have been used with 4GBRAM, i7 processor, Geforce 250 GPU.The EEG dataset, available for free from Kaggle, has been split into three sets: 70% for the train, 20% for the validation and 10% for the test, using a batch size equal to 32.
Adam is an adaptive algorithm designed to expedite the learning phase of various parameters [9].It utilizes the mean and variance of the data to dynamically adjust the learning rate for each weight in the neural network.
SGD optimizer: The stochastic gradient algorithm is an iterative gradient descent method used to minimize an objective function written as a sum of differentiable functions.

Loss functions
Every neural network design must comprise a loss function that computes the mistake percentage during the training and validation stages.The widely used loss functions are binary and sparse categorical cross entropy functions, where the former is appropriate for two-class classification problems and the latter for multiclass problems.In our RNN implementation, we have used the categorical cross entropy function given the classification of EEG into three classes.The categorical cross entropy function is outlined by Eq. (1).It evaluates the effectiveness of the neural network in modeling the training data.Our objective during training is to curtail this loss between the predicted and target outputs.

Experimental results
To implement our proposed RNN algorithm based GRU model, python, Keras and tensor flow library have been used with 4GBRAM, i7 processor, Geforce 250GPU.The EEG dataset has been split into three sets: 70%for the train, 20% for the validation and 10%for the test, using a batch size equal to 32.The obtained results demonstrate outstanding accuracies in both the training and validation phases, reaching 99.53% and 99.54%, respectively, when utilizing different optimizers like Adam.Table 4 and Table 5 provide a detailed overview of the performance, including an accuracy of 97.23% with the SGD optimizer.Table 4 represents precision and F1 score results, described by the following Eqs.( 2) and ( 3), that have proven to be excellent parameters for the proposed model evaluation, where precision results are going to 98%, 99% and 75% for the three classes respectively stress, neutral and positive.
Tables 6 and 7 have demonstrated the achieved results in terms of accuracies and loss, presented by the following Eq.( 4) through the implementation of the proposed GRU model based Adam and SGD optimizers.

Figure 4. Confusion matrix
The evaluation of a classification system's performance often involves utilizing a confusion matrix, which categorizes outcomes into four groups: True Positive (TP), True Negative (TN), False Positive (FP), and False Negative (FN).In Figure 4, the confusion matrix highlights FP results in the last row and FN results in the last column.This matrix offers a comprehensive overview of prediction outcomes in a classification task, specifically in assigning each signal to a particular class.Represented by an n x n matrix associated with a classifier, it illustrates the predicted and actual classifications, with n denoting the number of distinct classes.

Accuracy and loss curves results
Furthermore, the utilization of GPU for RNN implementation has significantly accelerated the processing speed during training epochs, influencing the direction in which the networks learn.The loss curves as depicted in Figure 5, employing Adam and Adadelta optimizers for both the validation and training processes, depict outstanding accuracy results.The accuracy curves as depicted in Figure 6, during the training and validation processes as presented in Figure 6 reveal a minimal gap between training and validation across epochs.The two curves have demonstrated.

Processing time
The experimental findings from the EEG database indicate a substantial enhancement in system processing time efficiency when employing a GPU over a conventional CPU.The real-time classification of EEG signals using the CPUbased algorithm took 0.015 seconds per signal.However, the implementation on a GPU demonstrated further refinement, achieving higher accuracy with shorter processing times, reducing it to 0.002 seconds per EEG signal during the test process.As depicted by the following histogram by Figure 7, the implementation of GRU Recurrent Neural Network has shown promising accuracies for both GRU using Adam and SGD optimizers.However, GRU-Adam has outperformed GRU-SGD with a small gap equal to 0.2%.This phenomenon has been explained by the huge role that plays Adam to eliminate fluctuations.However, SGD can exhibit noise, implying that it may not consistently move towards the optimal direction for reaching the global minimum of the loss function and improving accuracies.Moreover, the GRU with its light weighted architecture has proved to be efficient in terms of achieved classification results.Therefore, there is a potential risk of becoming trapped in local minima instead of converging to the actual global minimum.The choice of optimizer depends on the specific dataset we work with, and experiments using different optimizers leads us to find the best for our proposed model network.

Comparative study with the related works
Furthermore, the confusion matrix results highlight the superior classification accuracy of our proposed RNN compared to previous studies employing similar approaches.In a related study, Liao et al. introduced an ontological model for representing and integrating EEG data [12].Their approach involved utilizing an ontology to model low-level biometric features and mapping them to high-level human emotions, evaluated using the DEAP database.Despite employing the same dataset and extracted features, their model achieved an average recognition rate of 75.19% for valence and 81.74% for arousal across eight selected participants, indicating the enhanced performance of our proposed RNN classification method.Phutela et al in the study [17], have used the BLSTM to classify stress levels.The results indicate that the hybrid model we propose attained a superior classification accuracy of 99.20% compared to others models.Temporal Attention module has been implemented for stress detection achieving an accuracy going to 85.1% [12].Moreover, we have surpassed deep neural networks state of the art models by a gain in terms of accuracy, sensitivity and specificity [18][19][20] with a gain more than 2.5%.

CONCLUSIONS
In this paper, a RNN based GRU model has been implemented for stress from EEG signals, where we used the preprocessed DEAP Dataset.Two optimizers networks including Adam and SGD have been introduced for accuracy results improvement.Furthermore, excellent F1 score, precision and accuracy have been achieved.The outcomes of our study indicate superior classification performance with the RNN method compared to other state-of-the-art approaches.This suggests the successful applicability of this method to 2D-RNN-based EEG systems dealing with large datasets.Finally, our application can be a good candidate to be used in hospitals and clinics.As future work, we think to more speed up time execution process by the implementation of our application on embedded system such as Pynq-FPGA, using more EEG dataset.
, to detect stress signals.We have put forward a preprocessing step combined with a RNN algorithm based GRU model Two experiments have been done.The first consists of the implementation of the proposed RNN architecture using SGD optimizer network.The second consist of the implementation of RNN based Adam optimizer.

Figure 1 .
Figure 1.Synoptic flow of the proposed method 3.1 Dataset preparation DEAP stands as a benchmark affective EEG database utilized for the examination of spontaneous emotions, curated by Queen Mary University of London as depicted in Table2.The database comprises physiological signals gathered from 32 participants and was curated with the goal of establishing an adaptive music video recommendation system that takes into account the user's present emotional state.The DEAP database has been utilized in various studies, proving its suitability for testing novel algorithms.In assessing our proposed classification method, we employed the preprocessed EEG dataset from the DEAP database.The original recorded data, with a sampling rate of 5 Hz, underwent downsampling to 128 Hz.Additionally, a frequency filter bandwidth of 4.0 to 45.0 Hz was applied, and EEG artifacts were meticulously removed from the signals.

Figure 4
Figure 4 represents the confusion matrix results for stress detection in EEG signals.As illustrated in the images below, our GRU model achieved outstanding confusion matrices for the test sets.On the test set, the model accurately classified 201 EEG stress signals, 231 positive signals, and 208 neutral with a total of 566 well classified signals against 71 false classified signals.These results, which are represented in the matrices in Figure 4, confirm the accuracy and reliability of the model in distinguishing between stress, neutral and positive EEG signals.

Figure 5 .
Figure 5. Loss curves through train and validation processing

Figure 6 .DISCUSSIONS 5 . 1 Figure 7 .
Figure 6.Accuracy curves through train and validation processing contributed to this area.As depicted in Table 1, various neural networks models such as Artificial Neural Networks (ANN), Convolutional Neural Networks CNN and Recurrent Neural Network (RNN) that include BiLSTM, LSTM and GRU.These deep learning algorithms have shown a big interest in early stress detection from EEG signals.As summarized in Table 1, Recurrent Neural Networks models have shown to be superior than CNNS, LSTMs and ANNs in terms of yielded accuracies results.Kamakshi et al in the study

Table 1 .
State of the art works for stress detection

Table 4 .
Training parameters

Table 6 .
Accuracy and validation with SGD optimizer

Table 7 .
Accuracy and validation with Adam optimizer