EEG-Based Closed-Loop Neurofeedback for Attention Monitoring and Training in Young Adults

Attention is an important mechanism for young adults, whose lives largely involve interacting with media and performing technology multitasking. Nevertheless, the existing studies related to attention are characterized by low accuracy and poor attention levels in terms of attention monitoring and inefficiency during attention training. In this paper, we propose an improved random forest- (IRF-) algorithm-based attention monitoring and training method with closed-loop neurofeedback. For attention monitoring, an IRF classifier that uses grid search optimization and multiple cross-validation to improve monitoring accuracy and performance is utilized, and five attention levels are proposed. For attention training, we develop three training modes with neurofeedback corresponding to sustained attention, selective attention, and focus attention and apply a self-control method with four indicators to validate the resulting training effect. An offline experiment based on the Personal EEG Concentration Tasks dataset and an online experiment involving 10 young adults are conducted. The results show that our proposed IRF-algorithm-based attention monitoring approach achieves an average accuracy of 79.34%, thereby outperforming the current state-of-the-art algorithms. Furthermore, when excluding familiarity with the game environment, statistically significant performance improvements (p < 0.05) are achieved by the 10 young adults after attention training, which demonstrates the effectiveness of the proposed serious games. Our work involving the proposed method of attention monitoring and training proves to be reliable and efficient.


Introduction
Attention can be characterized as a cognitive process in the brain that selectively focuses on some part of the available information [1]. Nevertheless, excessive media multitasking poses a serious issue with respect to the attention function of young adults, resulting in distraction and poor attention control.
erefore, there is an increasing demand for attention monitoring and training for young adults [2].
Numerous methods have been developed for attention training, meditation [3], and computer-based exercises [4], but these approaches may contribute to mental fatigue. In recent years, several researchers have explored methods with fewer side effects. For example, Putri et al. [5] proposed the method of regular high-intensity circuit training (HICT), which can improve attention function in young male adults.
In the same year, Luo and Zhang [2] conducted experiments to validate that noninvasive tactile training has an excellent effect on sustained attention in young adults. e main purpose of this paper is to investigate a method of attention monitoring and training based on closed-loop neurofeedback. We use brain-computer interface (BCI) technology, which utilizes recorded brain activity, primarily measured by electroencephalography (EEG), to execute communications between the brain and computers to manipulate the environment in a manner that is compatible with the intentions of humans [6]. Notably, EEG signals are the most frequently used. In contrast to the previously developed methods in [3,4,7], an EEG-based system can be used as a noninvasive neurofeedback platform to enhance individual attention and cognitive abilities [8]. Furthermore, a neurofeedback-based attention training system not only helps young adults but also is suitable for children, especially those with attention deficit hyperactivity disorder (ADHD) [9].
BCI-based technology can be used to identify subtle shifts in individual attention [10]. Chiang et al. [11] developed an attention monitoring technique that integrates the minimum entropy principle approach (MEPA) and an associative Petri network (APN). Using a 14-electrode EEG device, a two-class classification accuracy of 90.4% was achieved based on 10 subjects in an online experiment. Hu et al. [12] compared the correlation-based feature selection (CFS) algorithm with other classification algorithms to evaluate attention at 3 levels (high, neutral, and low) and concluded that combining CFS and the K-nearest neighbors (KNN) data mining algorithm, which was used with a single valence resulted in the best performance. Six electrodes (C3, C4, Cz, P3, P4, and Pz) were used, and 10 subjects achieved an accuracy of 80.84% in their online experiment. In another study, Mohammadpour and Mozaffari [1] adopted an artificial neural network (ANN) to classify attention into four levels by using EEG signals from Fp1, Fp2, F3, F4, F7, F8, and Fz electrodes. An online experiment involving 5 subjects was conducted and an average accuracy of 79.75% was obtained. However, there have been two major issues to be further investigated. One issue is that the accuracy of attention monitoring needs to be improved, which may be related to the numbers of attention levels, detection algorithms, and types of feedback. e other issue is that more attention levels (i.e., ≥5) and fewer electrodes (i.e., ≤4) need to be explored in online attention monitoring, especially for EEGbased practical application.
Neurofeedback is an effective training technique based on brain waves and computer processing [13], and EEGbased neurofeedback training can provide real-time information to individuals regarding their brain function through BCI devices. Bettencourt et al. [14] used closed-loop neurofeedback from multivariate pattern analysis (MVPA) as a type of cognitive prosthetic to provide a neural error signal so that individuals could learn to properly evaluate the state of their attention. Mohammadi et al. [13] designed a computer game to train individual attention based on neurofeedback, and they summarized that the neurofeedback game not only helps individuals increase the possibility of success in controlling their attention but also decreases the time required for the training process. Although EEGbased neurofeedback training plays an important role in attention improvement, one should note that the abovementioned training methods are not suitable for all the different mechanisms of attention, such as sustained attention, selective attention, and focus attention.
To address these above issues, we focus on EEG-based attention monitoring and training with closed-loop neurofeedback in this study. On one hand, we propose an improved random forest-(IRF-) algorithm-based monitoring method, which uses grid search optimization and multiple cross-validation to classify attention into five levels.
e Personal EEG Concentration Tasks dataset involving 80 subjects was used to verify the effectiveness of the proposed attention monitoring method in the offline analysis. On the other hand, along with closed-loop neurofeedback, we provide three serious game-type training modes based on sustained attention, selective attention, and focus attention, which might be promising in terms of self-regulated attention training. Four primary indicators, including the Schulte times, win times, game scores, and skill times, were evaluated in an online experiment. e rest of this paper is organized as follows: Section 2 offers additional details on various methods, such as EEG data processing, classification algorithms, and game design. e succeeding section illustrates the process of the experiments and analyzes the results, followed by a discussion and our conclusions.

Materials and Methods
is section provides an overview of the utilized methods, as shown in Figure 1, which are separated into two modules: EEG-based attention monitoring and EEG-based training.
e first module commences with attention monitoring workflows based on EEG signals. en, EEG data processing and feature extraction are performed. Finally, the output classification obtained based on the IRF algorithm is presented. In the second module, we illustrate the principle of attention training and describe the implementation of serious games with closed-loop neurofeedback.

EEG-Based Attention Monitoring.
In the attention monitoring module, an OpenBCI headset with 8 channels was used to collect EEG signals, and a wavelet transform algorithm was used to analyze and extract features for the preprocessed EEG data. en, we utilized the IRF algorithm to classify attention.

EEG Data Preprocessing and Feature Extraction.
Previous related studies have shown that the power spectral densities (PSDs) of delta, theta, alpha, beta, and gamma have certain correlations with human attention. To this end, we selected and extracted EEG features based on these findings. An OpenBCI headset was used to capture the EEG data. Additionally, in terms of EEG data processing and attention monitoring, there are two factors to be considered. First, the most active sites of attention need to be given priority because the response is not evenly distributed across the electrodes. Second, if the algorithm is time-consuming, the time delays will not conform to the real-time constraints, rendering the feedback meaningless. Given the complexity of all kinds of data processing and the activity of positions, this paper selected the relatively active and attention-relative channels located in the frontal and temporal lobes, that is, TP9, AF7, AF8, and TP10, following the research of Castillo et al. [15] and Taillez et al. [16]. e wavelet transform algorithm was then applied to extract the PSD features of the EEG signals.
Wavelet analysis involves a combination of the time domain and frequency domain and is suitable for multiscale time-frequency analyses.
e wavelet basis is defined as follows: In (1), ψ s,a (t) represents the displacement and scale expansion of the basic wavelet, which can be used to decompose signals at different times. s denotes the translation factor, a indicates the scale parameter, and 1/ � � a √ is the normalization factor, which is proportional to ψ s,a (t): In equation ( e continuous wavelet transform (CWT) is used for extracting the PSD features of EEG signals. In this study, we used Daubechies coefficients for the wavelet transform, as they are characterized by excellent time localization performance and a maximal number of vanishing moments for a given support set. Daubechies 4 enjoys compact support and an orthonormal wavelet with smoothness.
us, an improved effect can be achieved through the analysis of nonstationary EEG signals. It is necessary to select a suitable number of decomposition levels to analyze an EEG signal; thus, we selected a decomposition level of 5 (L � 5). In addition, the sampling frequency was 256 Hz, and the bandlimited EEG was then subjected to a five-level decomposition coefficient of six subband signals through CWT. As shown in Figure 2, six subbands, including xD1, xD2, xD3, xD4, xD5, and xA1, represented the frequency range of the band-limited EEG signal [17], where xA is the decomposition approximation coefficient and xD is the decomposition detail coefficient.
Four wavelet thresholding methods were used in [18] to select an accurate threshold. We adopted the SURE threshold, which is an adaptive soft thresholding method. Once the threshold coefficients were extracted from each level, the effect of the noise on the EEG signals was removed.
We then used the inverse CWT to reconstruct the signals at each level. e first reconstructed detail D1 was regarded as the noise component of the EEG signal, and the reconstruction details of the other four subband signals D2-D5 and the reconstruction approximation of the subband signal A5 yielded signal information relevant to each EEG frequency band. Furthermore, 5 PSD features were extracted for classification: the delta (0 Hz < f < 4 Hz), theta (4 Hz < f < 8 Hz), alpha (8 Hz < f < 16 Hz), beta (16 Hz < f < 32 Hz), and gamma (32 Hz < f < 64 Hz) bands.

Improved Random Forest Classifier.
Compared with the correlation classification method, random forest classification removes noise more effectively and accurately, which contributes to the higher accuracy during the classification of noise-containing EEG signals. In addition, the random forest method offers stability, running efficiency, and reducing errors for imbalanced datasets. On this foundation, Belle et al. [19] compared the random forest and regression techniques for attention classification based on EEG signals, determining that random forest seems to work best for both modalities, which obtained an average accuracy of 85.7% for EEG. us, we choose the random forest algorithm to classify the attention level and propose the IRF method with higher accuracy. e workflows of the IRF algorithm used for attention monitoring are shown in Figure 3. A random forest is a set of multiple decision tree classifiers h(x, ϕ k ), k � 1, . . . , and the parameter set ϕ k is an independent and identically distributed random vector. e input feature variables X are classified separately by each decision tree, and the results are relied on to make predictions. After that, the classification results with the most votes are attained as the output.
(1) Decision Tree. e random forest algorithm takes multiple samples from the original data through bootstrap resampling and generates multiple decision tree classification models. ree steps are involved in the establishment of a decision tree.
Step 1. Select a random bootstrap sample across N original training sets by using the sampling with the replacement method, and repeat k times.

Journal of Healthcare Engineering
Step 2. Train a decision tree with a training set including each bootstrap sample and recognize it as the root node of the sample. When each node is split, the feature variables x(x ≪ X) are extracted from the X total feature variables at random for calculation purposes, and the best feature obtained from the x feature variables is selected as a branch of the node to achieve minimal node impurity.
Step 3. Split each node as before without a pruning operation in the course of establishing the decision tree.
To achieve stable accuracy, two random factors are introduced during the establishment of the decision tree. One is the bootstrap samples drawn from the N original training sets. e other is the stochastic feature variable selected from the node of the decision tree.
(2) Voting. To enhance the mutual influence between the classification models and improve their prediction ability, diverse decision trees are constructed by using different samples. After k rounds of training are conducted, the optimal classification models h 1 (X), h 2 (X), . . . , h k (X) are obtained and combined in a sequence to acquire the ultimate classification results by using the simple majority voting method. Equation (4) presents the classification decision: where H(x) is the classification model after the combination and h i (x) is one of the decision tree classification models. Y is the target variable, and the characteristic function is  (3) Grid Search Optimization. e random forest algorithm has high precision and runs fast. However, a large number of hyperparameters are generated in the course of operation. To obtain attention monitoring results with high accuracy, a grid search is used to optimize the parameters. e grid search algorithm involves meshing the variable regions, traversing all the grid points, solving for the objective function values that satisfy the constraint conditions, and selecting the optimal values [20]. Figure 4 shows the workflow of the optimization process.
To the best of our knowledge, it takes considerable time to traverse all the parameters, which decreases the training speed to some extent. In this paper, we use an improved grid search to increase the training speed. First, we use a large step size for a rough search over a wide range. e mesh built on the coordinate system consists of penalty parameters, the numbers of decision trees, and split features, n_estimators, max_features, and min_sample_leaf. When a set of parameters meets the set requirements, the optimal parameters and accuracy are output. In a case where more than one set of parameters meets the requirements, the set of parameters with the smallest penalty parameter is output as the best selection object. en, the search range and step size are reduced to search the parameter set more accurately. e above steps are repeated with a step size of 2 to find the global hyperparameters.
(4) Multiple Cross-Validation. e accuracy of the proposed method is closely related to the ratio of training data to test data. To address this problem, S-fold crossvalidation is conducted by randomly dividing the data into S subsets without repetition, of which S − 1 subsets are used for training and the remaining subset is used for testing: is process is repeated S times, and S accuracies are obtained. After each round, S − 1 subsets are selected at random to be retrained. In our paper, we use 10-fold crossvalidation, which mitigates the situation of overfitting and yields reliable results. e training set is split into 10 subsets, of which one subset is used for testing and the remaining subsets are used as the training set.

Neurofeedback-Based Attention Training.
ree types of attention mechanisms and closed-loop neurofeedback were adopted to implement the attention training function. Closed-loop neurofeedback technology involves the selfregulation of an individual's brain activity by relying on realtime visual and auditory feedback regarding his/her brain patterns. is technique can maintain specific conditions in the brain states of young adults and improve their cognitive function through training.
We proposed an attention training method based on closed-loop neurofeedback technology that increases individual interest through the use of serious games and improves attention in a relaxing atmosphere without adverse reactions. At the same time, impaired concentration is associated not only with psychology but also with the three previously mentioned attention mechanisms: sustained attention, selective attention, and focus attention. According to the persistence, selectivity, and focus of attention, we designed three serious games (as shown in Figure 5), named Tug of War ( Figure 5(a)), Adventures of Birds ( Figure 5(b)), and Greedy Jelly ( Figure 5(c)) in this study.

Serious Games with Closed-Loop Neurofeedback.
e young adults controlled each game by their attention levels; the specific implementation process is as follows: first, EEG signals were obtained from the young adults through OpenBCI. en, their attention function was monitored by the IRF algorithm, and the results were quantified as young adults' attention levels during the games. e value of "high attention" was quantified as 1, the value of "medium-high attention" was quantified as 0.75, the value of "medium attention" was quantified as 0.5, the value of "medium-low attention" was quantified as 0.25, and the value of "low attention" was quantified as 0. In the sustained game, only when the young adults' attention levels were higher than a certain threshold would the strength of the character in the game be greater than that of the enemy. During the selective game, the bird's direction (upward, downward, or horizontal flight) was manipulated by the young adults' attention levels. For the focus game, the character, who was equipped with a special skill, would release his skill when the young adults' Journal of Healthcare Engineering attention was focused and reached the maximum level. In Figure 5(d), a subject is shown playing a serious game with closed-loop neurofeedback.
To increase the efficiency of attention training, we optimized the graphical user interface (GUI) of the games as follows: (1) We designed various game environments and characters by taking young adults as the basis to increase their interest in the GUI.   Journal of Healthcare Engineering Closed-loop neurofeedback technology can be an additional option for enhancing attention, which means that young adults could control the characters in the games with their attention; at the same time, they could also receive attention feedback from the games. Furthermore, young adults could increase their focus by actively concentrating after becoming acquainted with their attention function.

Offline Analysis.
In offline analysis, the Personal EEG Concentration Tasks dataset involving 80 subjects was used to verify the effectiveness of the proposed attention monitoring method. We selected 70% of the samples as the training set and 30% of the samples as the test set at random. Different algorithms were utilized to divide attention into the abovementioned five levels.
e results are shown in Table 1.
Among the five algorithms, the IRF achieved an accuracy of 79.34%, with a loss rate of 21.76%, a recall rate of 76.18%, and a precision of 82.60%. e results show that the attention monitoring method based on the IRF algorithm obtained the highest accuracy rate.

Online Analysis.
In the online experiment, we used an OpenBCI headset at 256 Hz to record the EEG data. Ten healthy subjects participated in the experiment, including 5 males and 5 females. e ages of the subjects ranged from 8 to 20 years old (mean � 15.95, std. � 4.63). e study was approved by the Ethics Committee of South China Normal University and complied with the Code of Ethics of the World Medical Association (Declaration of Helsinki). Before the experiment started, the subjects sat on a comfortable chair without blinking or moving their bodies, and they completed the entire experiment according to the provided instructions. ere were two sessions during the experiment: a calibration session and an evaluation session.
In the calibration session, each subject performed 20 trials, which took the subjects approximately one hour to complete. Furthermore, each subject was asked to enter their personal information on a computer at the start of the experiment for the purpose of extracting the EEG data and labeling them conveniently. At the beginning of each trial, the computer screen showed a 10-second countdown to help subjects adjust their attention. After that, a calculation task, a minesweeping game task, or an article task was presented on the computer screen, and subjects needed to select an option or read. We induced the attention of subjects through the assigned task and recorded their EEG data simultaneously. After clicking the finish button, the subjects were asked to fill in the valence of self-assessment manikins (SAMs) to report their attention states, that is, high attention, medium-high attention, medium attention, medium-low attention, and low attention. e overall process of this experiment is illustrated in Figure 6.
In the evaluation session, we used similar experimental trials to evaluate the model. In each trial, 6 algorithms (SVM, KNN, AdaBoost, ET, RF, and IRF) were applied to detect attention. Ultimately, we calculated the accuracy of each approach by comparing the predicted attention levels and the actual labels. Figure 7 reveals the accuracy of the attention monitoring results for the 10 subjects, obtained by using the abovementioned five algorithms during the experiment. P values were calculated using a t-test to evaluate the accuracy differences between IRF and other algorithms with the SPSS tool, and the results are shown in Table 2, which were corrected for false discovery rate of p < 0.01. e average accuracy rates of the various algorithms are displayed in Table 3, from which we can find that the accuracy of the IRF is significantly better than the accuracies of the other methods during the online attention monitoring experiment.

Results.
ere is a significant difference (p � 0.016) between the IRF algorithm and ET algorithm.

Workflow of the Attention Training Experiment.
Ten healthy subjects participated in this experiment, including 5 males and 5 females; these subjects were different from those who participated in the online experiment. e ages of the subjects ranged from 8 to 18 years (mean � 12.5, std. � 4.32). We performed a self-controlled study to validate the effectiveness of the training method, which offers good comparability and high reliability. During the course of the experiment, each subject sat quietly on a chair to avoid excessive movements that would affect the results.
Each subject performed 3 experiments. Before Experiment I and after each experiment, the subjects were required to complete a 5 × 5 grid of a Schulte table while recording the observed completion time and EEG signals.
ere were 3 phases in each experiment: a preparation phase, a training phase, and a rest phase. e preparation phase, which lasted for 3 seconds, required subjects to actively refrain from noticing the game on the screen. During the training phase, the sustained game was presented, and the completion time was recorded. Afterwards, the selective game was carried out, and the scores were recorded when the subjects failed. Finally, the subjects performed the focus game and recorded the times at which they released the special skill. In addition, the resting phase provided a 5-

Effectiveness. Four primary indicators, including the
Schulte times, win times, game scores, and skill times, are proposed as follows: (1) Schulte times, which represent the times(s) required to complete the Schulte table.
(2) Win times, which denote the times(s) required to win a sustained game. (3) Game scores, which indicate the scores obtained by each subject upon losing the selective game. (4) Skill times, which denote the times at which the special skill was released during the focus game.
e Schulte times of the 10 subjects before Experiment I and after each experiment are shown in Figure 8. Figures 9(a)-9(c) show the win times, game scores, and skill times, respectively.
In the above four figures, all indicators underwent remarkable changes (p < 0.05).
e Schulte times and win times were obviously reduced. In contrast, the game scores and skill times increased significantly. ese can be attributed to two reasons: (i) the familiarity of the subjects with the game environment after much practice and (ii) the effectiveness of neurofeedback. To explore the impact of the neurofeedback on the 3 experiments, we conducted an additional experiment without neurofeedback on the same subjects. We removed the neurofeedback elements from the three games in experiment III, such as the progress bar and the background sound effects used to display the subject's attention level in the GUI. e average results of the four indicators for each experiment are presented in Figure 10. For comparison purposes, we reduced the values of the win times by a factor of 10.
As the subjects became more familiar with the game, even without neurofeedback, their attention was improved to a certain extent. However, the rates of change of the four indicators without neurofeedback were much lower than those observed when using neurofeedback.
Moreover, to verify the accuracy of the control parameters, the Schulte times and the EEG signals input into the Schulte table before the experiment and after each experiment were analyzed.
e Schulte times are often inversely proportional to the concentration and attention levels. Table 4 illustrates the comparison between the Schulte times and the results of attention monitoring among the subjects. e results showed that the shorter a given Schulte time was, the more concentrated the subjects were and the higher the attention monitoring results. In contrast, there was less enhancement of the monitoring results.

Discussion
e main work in our paper was to propose an IRF-algorithm-based attention monitoring and training method with closed-loop neurofeedback. For attention monitoring, we divided attention into five levels ranging from low to high attention and applied the IRF algorithm to improve monitoring accuracy and performance. Furthermore, an offline experiment based on the Personal EEG Concentration Tasks dataset and an online experiment involving 10 young adults were carried out. e results yielded an average accuracy of 79.34% for the IRF algorithm. For attention training, we designed three training modes with neurofeedback, corresponding to sustained attention, selective attention, and focus attention. Furthermore, a self-control method with four indicators was used in the attention training experiment, and the results demonstrated a statistically significant performance improvement (p < 0.05) for the 10 tested young adults after attention training, thereby demonstrating the effectiveness of the proposed games.
From the perspective of the attention monitoring method, it is essential to achieve a promising level of accuracy and improved classification. At the same time, the attention mechanism and training method are vital for attention training. We show the differences between other studies and our work in Tables 5 and 6.
Most past studies explored attention training methods, such as the focused attention meditation (FAM) method proposed by Yoshida et al. [24]. In addition, Shereena et al. [25] used the EEG neurofeedback training method to design training tasks, aiming to enhance β waves for the purpose of suppressing θ waves.
ese studies related to attention training focused on EEG signals, with little emphasis on neurofeedback. Notably, several recent papers examined the method of combining neurofeedback and serious games, which is helpful for improving self-regulation skills in attention training with appropriate guidance; an example of this is the "ExerBrain" game [14], which assists individuals in improving their attention control due to the immersive and interactive feature of neurofeedback. Moreover, neurofeedback training has proven to be an efficient tool for sustained attention [26]. Nevertheless, attention, as a kind of higher-order cognition, comprises not only sustained attention but also selective attention and focus attention [25]. As such, this study provides a means by which to implement serious games and analyze three mechanisms of attention simultaneously to help young adults enhance their attention effectively. e advantages of this paper primarily comprise the following points: (i) we utilized the IRF algorithm for fivelevel attention monitoring and obtained promising accuracy; (ii) we designed serious games in a multiangle and targeted manner with consideration of sustained, selective, and focus attention; (iii) we quantified the attention monitoring results and used them as the control parameters to manipulate the games with improved accuracy; and (iv) four indicators were proposed in the experiment to validate the effectiveness of the presented method.
In addition, the main finding is that the attention of young adults could be enhanced by using closed-loop neurofeedback in comparison with methods that ignore neurofeedback. is is in line with the results of previous attention monitoring studies [27]. On this basis, this paper used the IRF algorithm to classify 5-level attention and attained an accuracy of 79.34%, which is higher than those of Journal of Healthcare Engineering 9  the other algorithms that were compared. Furthermore, consistent with past studies [11,25], we showed that neurofeedback training can assist young adults in improving their attention. In the present study, we implemented three serious games for young adults with neurofeedback and incorporated three mechanisms of attention that were not fully considered in past studies. Furthermore, the attention training method in this paper contributed to significant improvements in sustained attention, selective attention, and focus attention. erefore, we can conclude that all mechanisms of attention can be improved with specific serious games. e primary limitation of our study was the small number of subjects examined during the experiment. In    addition, there are a few datasets pertaining to the attention of young adults; these data are challenging to record due to the volatility of conductive media in BCIs. In addition, several external factors, such as the habits, motivations, and mental statuses of the subjects, were not considered.

Conclusions
We proposed an IRF-algorithm-based attention monitoring and training method with closed-loop neurofeedback, and we presented the mechanism of attention. In the future, we will collect attention data and attempt to fuse EEG and physiological signals (such as facial expressions and verbal speech) to improve the accuracy of attention monitoring. Furthermore, we will develop 3D serious games in the near future.

Data Availability
All the data included in this study are available upon request by contacting the corresponding author.

Conflicts of Interest
e authors declare that there are no conflicts of interest regarding the publication of this paper.