The underlying mechanisms of tDCS-Based cognitive enhancement in unpredictable task switching: A machine learning-based approach for EEG signal analysis Authors: Ziyu Wang, Ziyuan Zhang, Rongjuan Zhu, Xinru Zhang, Xuqun You, Jimin Liang Published: 2026 ABSTRACT AbstractTranscranial direct current stimulation (tDCS) enhances cognitive abilities yet has highly inconsistent outcomes, highlighting the need to clarify its neurophysiological mechanisms. Herein, we integrated EEG with machine learning to assess 24 participants performing unpredictable magnitude/parity switching tasks under anodal tDCS (a-tDCS) and sham conditions using a double-blind design. Behavioral results showed that a-tDCS over the right dorsolateral prefrontal cortex (rDLPFC) markedly improved switch cost accuracy while reducing mixing cost accuracy. EEG analyses revealed that a-tDCS induced a significantly larger N1 in repeat trials, eliminated switch-repeat differences in N2 latency, frontal/central alpha (1200–1500 ms) and parietal beta power (600–800 ms), while enhancing central theta power (100–400 ms) in females. Moreover, participants were divided into high-gain and low-gain groups by median split of switch cost improvement score (a-tDCS minus sham accuracy). Decoding analyses further revealed a significantly higher trial-type classification accuracy in the low-gain group under a-tDCS condition during stimulus-response interval. Conversely, the high-gain group exhibited lower trial-type classification accuracy, albeit with a higher response-hand classification accuracy during pre-stimulus period. Additionally, model interpretability analyses showed a frequency band main effect on trial-type classification with significantly higher alpha and/or beta weights compared to theta and/or delta weights across regions. Furthermore, a-tDCS significantly reduced left frontal delta weights, enhanced left centrofrontal alpha weights, and increased right central alpha weights in high-gain group. These findings suggest that a-tDCS over the rDLPFC regulates attention, conflict detection, and inhibition to modulate unpredictable task switching, highlighting the dominant role of high-frequency bands in trial-type classification, and indicating that a-tDCS impacts the low- and high-gain groups via reactive conflict resolution and broad proactive preparation, respectively.Keywords: tDCS, EEG, Unpredictable task switching, Cognitive processing, Cognitive enhancement Introduction In both healthy individuals and patients, transcranial direct current stimulation (tDCS) can effectively enhance cognitive abilities, including executive control, attention, and multitasking (Boudewyn et al., 2020; Dedoncker et al., 2016; Ke et al., 2023; Narmashiri and Akbari, 2023). However, identical tDCS parameters (e.g., intensity, duration) often yield inconsistent outcomes across cognitive tasks, even within the same paradigm (Leite et al., 2011; Sdoia et al., 2020; Wang et al., 2021). Consequently, clarifying the neurophysiological mechanisms underlying tDCS effects is imperative. Previous studies have explored these mechanisms via electroencephalography (EEG) signal analysis (Chan et al., 2021). For example, Dubreuil-Vall et al. (2019) found that anodal tDCS (a-tDCS) over the left dorsolateral prefrontal cortex (lDLPFC) improved Eriksen Flanker task performance by modulating the N2 and P3 components, which reflect conflict monitoring and target evaluation, respectively. Despite such efforts, research in this area remains relatively limited, with insufficient depth in exploring underlying mechanisms. Recent work has proposed that combining EEG signals with machine learning (ML) techniques may deepen our understanding of these cognitive mechanisms, support the development of EEG-based brain-computer interface (BCI) systems, and enable more precise, intelligent, and personalized tDCS-driven cognitive enhancement (Albizu et al., 2023; Loriette et al., 2022; Shani et al., 2021; Vladisauskas et al., 2022; Wu et al., 2023). To advance both theoretical understanding and practical applications, we therefore employed ML techniques to explore the mechanisms of tDCS-mediated cognitive enhancement. Task switching, a crucial cognitive ability that examines how individuals process information when shifting between tasks (Cutini et al., 2021; Koch et al., 2018), has recently gained significant scholarly attention. Compared to performing the same task repeatedly, switching between tasks often results in a significant decline in performance—a phenomenon known as “switch cost,” which has been associated with task-set reconfiguration and inhibition (Meiran, 1996; Monsell, 2003; Rogers and Monsell, 1995). In critical occupations, a more pronounced switch cost is linked to greater safety risks. For instance, surgeons and emergency department doctors with larger switch costs face increased risks of surgical errors (Skaugset et al., 2016; Walter et al., 2014). Thus, tDCS has been employed as a potential approach to reduce switch costs, with single-session protocols currently being widely employed (Narmashiri and Akbari, 2023). Accumulating evidence suggests that single-session tDCS over the frontal cortex can reduce switch cost (i.e., accuracy and/or reaction time) (Leite et al., 2013; Prehn et al., 2021; Wang et al., 2020). Moreover, single-session tDCS may also modulate switch cost via other brain regions (e.g., posterior parietal cortex (PPC) or dorsomedial prefrontal cortex (DMPFC)) (Koshikawa et al., 2022; Wang et al., 2024). Conversely, other studies report no significant improvements or even performance decrements (Leite et al., 2011; Sdoia et al., 2020; Strobach and Antonenko, 2017; Strobach et al., 2016; Wang et al., 2021). Multi-session tDCS has also been explored in task switching but remains understudied. For example, Figeys et al. (2022) reported that a-tDCS over the left DLPFC (1.5 mA, 20 min/session, 10-15 sessions) significantly improved inhibitory processing and cognitive flexibility in elderly patients with depression and anxiety. Additionally, Tayeb and Lavidor (2016) integrated tDCS (1.5 mA, 20 min/session, 3 sessions) with task switching training and found a significantly improved reaction time in switch and repeat trials compared to the sham condition. Despite these efforts, the application of tDCS in task switching faces two key limitations. First, research has predominantly focused on whether tDCS enhances performance, with little attention to how it modulates underlying cognitive processes, particularly their neural substrates. For example, Leite et al., 2013 reported that although bilateral tDCS (left anode and right cathode, 1 mA, 20 min) enhanced letter/digit naming task performance, it reduced parity/vowel-consonant task performance. Similarly, Wang et al. (2021) found that even though unilateral a-tDCS (right anode, 1.5 mA, 20 min) enhanced parity/magnitude switching task performance, it reduced parity/vowel-consonant switching task performance. However, the electrophysiological basis of these task-specific effects (e.g., modulation of ERP components or oscillatory activity) remains unexamined. Second, multi-session tDCS protocols are understudied, especially combinations with cognitive training, partly due to unclear mechanisms that hinder the design of optimized stimulation regimens and training pairings. Based on these insights, an in-depth exploration of how tDCS influences task switching represents a critical direction in current research. Task switching involves multiple cognitive processes, such as task-set maintenance, reconfiguration, inhibition, and response making (Yeung et al., 2006), and EEG analysis is uniquely suited to capture their spatiotemporal dynamics. Most prior studies use predictable task-switching paradigms with pre-stimulus cues to isolate proactive and reactive control (Capizzi et al., 2020; Nicholson et al., 2005; Richardson et al., 2022; Sohn et al., 2000). However, real-life scenarios do not always allow for advance preparation, such as car drivers suddenly encountering situations that require rapid task switching. Consequently, to better reflect real-world situations, we focused on the cognitive processes in unpredictable task switching. Related event-related potential (ERP) analysis demonstrated that compared to repeat trials, switch trials elicit significantly larger parietal P3 amplitudes and potentially larger and delayed P2/N2 components, reflecting task-set reconfiguration, activation, and conflict monitoring processes (Friedman et al., 2008; Gajewski et al., 2018; Karayanidis et al., 2010; Nicholson et al., 2005; Petruo and Beste, 2021; Tsai and Wang, 2015; Zhuo et al., 2021). At the same time, time-frequency studies highlight the sensitivity of theta, alpha, and beta bands to task switching (Cunillera et al., 2012; López et al., 2019; Mansfield et al., 2012; McKewen et al., 2020, 2021). For instance, Capizzi et al., 2020 reported that switch trials showed significantly higher theta power and lower alpha and beta power in unpredictable task switching compared to repeat trials. These findings collectively lay a robust theoretical groundwork for exploring the neurophysiological mechanisms underlying tDCS-mediated cognitive enhancement. Multiple EEG-based studies have explored tDCS mechanisms in various cognitive tasks (Ghafoor et al., 2022; Gordon et al., 2018). For example, Masina et al. (2021) found that single-session tDCS (C4, 1.5 mA, 20 min) reduced task-state beta power (activating non-target areas), thereby modulating motor dexterity performance. Jones et al. (2017) integrated tDCS stimulation (DLPFC/PPC, 1.5 mA, 15 min/session, 4 sessions) with working memory training, which enhanced theta/low-alpha phase synchronization between the prefrontal-posterior regions, thus improving performance. Despite these valuable insights, tDCS mechanisms in task switching remain underexplored. Therefore, we sought to explore tDCS-induced neurophysiological changes in the DLPFC during unpredictable task switching using EEG analysis. It is worth mentioning that gender may also modulate the task-switching processing. For instance, some researchers have demonstrated a better task-switching performance in females (Stoet et al., 2013), while Kuptsova et al. (2015) conducted a fMRI experiment and discovered significant differences in brain activation between males and females during task switching. However, research on this topic remains scarce and requires further validation. Therefore, the current study also incorporates gender as a variable. Recent ML advancements have enabled the classification of different cognitive processes in task switching. Cao et al. (2023) employed Mahalanobis distance-based classification to decode task (color/shape) and trial (switch/repeat) types in a predictable color-shape switching paradigm. According to the results, healthy individuals' classification accuracy in both classification tasks was significantly above the chance level. However, task switching involves multiple cognitive processes, such as task preparation, cue identification, inhibitory control, task-set reconfiguration, and response execution. Treating each trial as a unit and classifying it simply as “switch” or “repeat” may not capture the dynamic neural mechanisms underlying these operations, thus limiting mechanistic understanding of how the brain coordinates dynamic cognitive demands. To address this challenge, Hubbard et al. (2019) analyzed EEG signals across different time points, electrodes, and four frequency bands (theta, alpha, beta, and gamma) using logistic regression during a predictable color-orientation switching task. This approach visualized the curves of classification accuracy changing over time, not only demonstrating the model's predictive capabilities but also illustrating the temporal dynamics of cognitive processes vividly, thus illuminating the sequential nature of cognitive control during task switching. Therefore, we leveraged ML algorithms to establish whether task-switching ability could be predicted and to examine how tDCS dynamically alters the cognitive processing involved in task switching. Herein, we integrated EEG analysis with ML techniques to investigate whether tDCS over the DLPFC affects unpredictable task-switching performance and to explore its underlying mechanisms. Specifically, this study attempts to answer three key questions: (1) How does tDCS influence switch cost via ERPs and EEG time-frequency features? (2) Can an ML-based approach predict task-switching ability using EEG time-frequency features? (3) Can classification results of ML models explain the dynamic neural mechanisms underlying cognitive processing differences in task switching under varying tDCS conditions? Materials and methods Participants This study recruited 24 healthy college students [11 males (age: M = 24.45, SD = 1.753) and 13 females (M = 23.60, SD = 1.51)] from Xidian University. All participants were right-handed, with normal or corrected-to-normal vision. No participants had metallic implants, a history of neurological disorders, or psychiatric illnesses. Before the experiment, all participants provided written informed consent. The Ethics Committee for Human Experimentation in the School of Electronic Engineering, Xidian University, reviewed and approved the study protocol. Stimuli and tasks All participants were required to complete two single tasks (i.e., magnitude task and parity task) and one switching task, in which the cue and stimulus appeared simultaneously. In the magnitude task, a digit selected from a predetermined set (1, 2, 3, 4, 6, 7, 8, and 9) appeared at the center of the screen, and participants were asked to determine whether it was greater or less than 5. In the parity task, they were asked to judge whether the digit was odd or even. In the switching task, the digits were randomly presented in either a circle or a square (Petruo and Beste, 2021), and the participants were asked to identify the magnitude and parity features when the digits were circled and squared, respectively. Half of the participants pressed the “F" key with their left index finger for smaller/even digits and the “J" key with their right index finger for larger/odd digits. The response keys for the other half were reversed. tDCS set-up Herein, tDCS was delivered using a DC-Stimulator Plus (NeuroConn GmbH, Germany). Two 5 × 7 cm2 rubber electrodes embedded in saline-soaked surface sponges were positioned on the head based on tDCS conditions per the international 10–20 system. For the real anodal stimulation condition (a-tDCS), the anode and cathode were placed over F4 and on the left cheek, respectively (Wang et al., 2024). A constant current of 1.5 mA was then applied continuously for 20 min, with a linear fade in and fade out of 30 s. An identical electrode placement was used in the sham condition, but without actual direct current. Instead, only a 30 s anodal pseudo-stimulation was applied to mask the true nature of the tDCS condition from participants. Note that this study adopted a double-blind design where neither participants nor researchers were aware of stimulation conditions. Procedure All participants completed three experimental sessions, with a minimum interval of 7 days between sessions to ensure sufficient washout and minimize potential carryover effects. First session Participants completed two single-task blocks (parity or magnitude tasks) and one switching task to familiarize themselves with procedures, reducing task novelty effects on subsequent results. For single tasks, each block included 16 practice trials and 128 experimental trials, respectively. At the start of each trial, a fixation point was displayed at the center of the screen for 1200 ms, followed by a digit stimulus that remained until participants submitted a response. For switching task, one practice block (16 trials) and four experimental blocks (128 trials/block) were used. Participants were first to achieve 100% accuracy in the practice block before proceeding to the experimental blocks, in which a 1200 ms fixation point signaled trial commencement. Subsequently, a cue (e.g., “□”) and a digit (e.g., “2”) were simultaneously presented at the center of the screen, and participants were instructed to respond to the stimulus accurately and rapidly. After participants submitted a response, a 1200 ms blank screen appeared, followed by the next cue-digit pair. Second and third sessions Participants performed all experiments in an electromagnetic shielding room. First, a 64-channel cap (10–20 system) was positioned, with 10 electrodes (AF4, AF8, F2, F4, F6, F8, FC2, FC4, FC6, FT8) left uncovered to avoid interference with tDCS electrodes (Fig. 1a). Following that, tDCS electrodes were positioned beneath the EEG cap (Fig. 1b), with half of the participants receiving sham and a-tDCS stimulation in the second and third sessions, respectively. Meanwhile, the other half received the reverse order. After stimulation for 20 min, tDCS electrodes were removed immediately, and the remaining 10 EEG electrodes were placed (taking ⁓10 min). The subsequent session began with a 10-min resting-state EEG recording, during which participants were fixated on a central screen point and instructed to avoid blinking and large eye movements, among other muscle activities (Fig. 1c). Subsequently, participants performed similar tasks as in the first session, but without the practice blocks (Fig. 1d). Prior work has demonstrated that tDCS effects can persist for up to 90 min (Feng et al., 2013). As all procedures (i.e., resting-state EEG and three experimental tasks) were completed within 90 min, tDCS effects likely remained active throughout the experiment. Timeline of the experimental procedure. EEG recording and pre-processing Electrophysiological data were collected using the ActiCHamp EEG system (Brain Products GmbH). A 64-electrode cap configured per the international standard 10/10 System was used, with a sampling rate set at 1000 Hz. The FCz and FPz electrodes served as the online reference and grounding electrodes, respectively. Electrode impedance was maintained below 5 kΩ throughout recording. Offline processing was performed in MATLAB (version 18a, Mathworks, Natick, MA, USA) and the EEGLAB toolbox. Task-state EEG data were re-referenced to an average reference, down-sampled to 250 Hz, and filtered with a 0.1-40 Hz band-pass filter. Epochs were extracted from −1200 to 2000 ms relative to stimulus onset, with baseline correction applied using the −1200 to 0 ms interval. Artifacts (e.g., eye movements, muscle activity) were removed using independent component analysis (ICA). Bad channels were identified via visual inspection, and any removed bad channels were interpolated. Trials with amplitudes exceeding ±80 μV were automatically rejected. For ERP analysis, epochs were further extracted from −200 to 1000 ms relative to stimulus onset, with baseline correction using the −200 to 0 ms interval. Key ERP components were analyzed based on prior literature and visual inspection of grand-averaged waveforms, including N1 (80-150 ms, Fz), P2 (150-250 ms, Fz), N2 (250-400 ms, Fz), and P3 (350-650 ms, Pz) (Friedman et al., 2008; Petruo and Beste, 2021). For time-frequency analysis, the power spectrum was obtained using wavelet transformation for 1 to 40 Hz with the use of a 5-cycle complex Morlet wavelet to obtain an adequate time-frequency resolution, and only the −600 to 1500 ms time window was then extracted, with baseline correction using the −600 to 0 ms interval. We focused on theta (4-7 Hz), alpha (8-12 Hz), and beta (13-30 Hz) bands, as previous work has demonstrated their critical roles in unpredictable task switching (Capizzi et al., 2020). The delta band (1-3 Hz) was additionally included as a potential frequency range of interest. Specifically, power values were extracted within distinct time windows for each band: 100-400 ms and 700-1500 ms for the theta band, 1200-1500 ms for alpha band, and 600-800 ms for beta bands. Decoding analysis We adopted the decoding framework described by Hubbard et al. (2019) to assess the classification ability of EEG time-frequency power features for three switching task attributes, including trial type (switch/repeat), task type (magnitude/parity), and response hand (left/right). Only correct trials were included in the decoding analysis. For time-frequency power feature extraction, we first aggregated electrodes into 17 brain regions to reduce dimensionality in decoding analysis (Table 1). Second, the time-frequency power spectrum was obtained using wavelet transformation for frequencies ranging from 1 to 40 Hz. Third, feature extraction was performed on the data from the four frequency bands—delta (1-3 Hz), theta (4-7 Hz), alpha (8-12 Hz), and beta (13-30 Hz)—across 17 brain regions. We only retained data from the −600 to 1500 ms window to optimize the classification process and reduce the calculation time. Note that for each participant, at least 80% of trials were included within this time window. Table 1Division of 17 scalp regions.Table 1ElectrodesScalp regionElectrodesScalp regionFp1, AF3, AF7, F1, F3, F5, F7Left FrontalFp2, AF4, AF8, F2, F4, F6, F8Right FrontalFC1, FC3, FC5Left CentrofrontalFC2, FC4, FC6Right CentrofrontalC1, C3, C5Left CentralC2, C4, C6Right CentralFT7, FT9, T7Left TemporalFT8, FT10, T8Right TemporalCP1, CP3, CP5Left CentroparietalCP2, CP4, CP6Right CentroparietalTP7, P7, TP9Left OccipitotemporalTP8, P8, TP10Right OccipitotemporalP1, P3, P5Left ParietalP2, P4, P6Right ParietalO1, PO3, PO7Left OccipitoparietalO2, PO4, PO8Right OccipitoparietalAFz, Fz, FCz, Cz, CPz, Pz, POz, OzMidlineNote: Electrodes are listed using comma-separated labels, following the International 10-20 system for EEG electrode placement. Division of 17 scalp regions. Note: Electrodes are listed using comma-separated labels, following the International 10-20 system for EEG electrode placement. Decoding was performed for three classification tasks, including task type, trial type, and response hand. A logistic regression classifier was used as implemented in the scikit-learn package in Python, with a tolerance of 1 × 10−4 and the inverse of the regularization strength (C) set to 1.0. Model performance was evaluated via stratified 10-fold cross-validation method, where 90% and 10% of the trials were used in the training and test sets, respectively. This approach was repeated until each trial had an opportunity to be part of the test set. For each classification task, average accuracy across the 10 folds was computed at each time point to visualize temporal dynamics of decoding performance. Data analysis Analyses were conducted on behavioral and task-state EEG data as follows: First, 23 participants were included in behavioral data analysis, as one participant with accuracy below 80% was excluded. Dependent variables included switch cost (switch trials minus repeat trials) and mixing cost (mixed trials minus single trials) for both accuracy and reaction time (RT) under sham and a-tDCS conditions. Several mixed-design analyses of variance (ANOVAs) were conducted, with tDCS condition (sham, a-tDCS) as a within-participant factor and gender (male, female) as a between-participant factor. Second, after excluding participants with poor-quality EEG signals, only 22 participants were included in EEG analysis. In ERP analysis, the peak and latency of ERP components were used as dependent variables, while trial type (repeat, switch), tDCS and gender were employed as independent variables. In time-frequency analysis, ANOVAs were performed using variables including tDCS, frequency bands (delta, alpha, beta, theta), scalp regions (frontal, central, parietal, and occipital), and gender, with the power of each frequency band in corresponding brain regions serving as the dependent variable. Third, in decoding analysis, participants were categorized into high-gain and low-gain groups using median split of the switch cost improvement score (i.e., a-tDCS switch cost accuracy minus sham switch cost accuracy). Dependent variables were peak classification accuracy and its latency across three periods, including pre-stimulus (−600-0 ms), stimulus-response interval (SRI, 0-900 ms), and post-response (900-1500 ms). Mixed-design ANOVAs were applied in each period, with tDCS, classification feature (trial type, task type, response hand), and gain group (low, high) as variables. Notably, the Greenhouse-Geisser (G-G) correction was used to adjust significant alpha levels if a major violation of the sphericity assumption was detected during these ANOVAs. Additionally, further Bonferroni post-hoc analyses were conducted in case of any significant interactions. Results Behavioral data For switch cost accuracy, the main effect of tDCS was significant [F (1, 20) = 45.173, p < 0.001, η2p = 0.693], with significantly larger values in the a-tDCS condition (M = 0.0122, SD = 0.01413) than in the sham condition (M = −0.0165, SD = 0.01668). Similarly, for mixing cost accuracy, the main effect of tDCS was significant [F (1, 20) = 19.550, p < 0.001, η2p = 0.494], albeit with a significantly lower accuracy in the a-tDCS condition (M = −0.0196, SD = 0.01665) than in the sham condition (M = 0.0022, SD = 0.01622). Finally, the main effect of gender was also significant [F (1, 20) = 4.693, p = 0.030, η2p = 0.190], with a significantly higher mixing cost accuracy in males (M = −0.003; SD = 0.003) than in females (M = −0.014, SD = 0.003). No other significant effects were observed (p-values >0.05). ERP analysis N1: For amplitude, the interaction between tDCS and trial type was significant [F (1, 20) = 12.904, p = 0.002, η2p = 0.392]. Post-hoc analysis further revealed that under the a-tDCS condition, repeat trials amplitude (M = −1.562, SD = 0.318) was significantly larger than switch trials amplitude (M = −2.546, SD = 0.318; p < 0.001), while no significant difference observed in the sham condition (repeat: −1.271 ± 0.220 μV; switch: −1.338 ± 0.216 μV; p = 0.804). No significant difference was found for latency (p-values >0.05) (Fig. 2). ERP waveforms under sham and a-tDCS conditions. P2: No significant difference was found for peak and latency (p-values >0.05). N2: For amplitude, the interaction between trial type and gender was significant [F (1, 20) = 10.175, p = 0.005, η2p = 0.337]. Post-hoc analysis revealed that, males showed a significantly negative N2 amplitude in switch trials (M = −3.333, SD = 0.692) compared to repeat trials (M = −2.998, SD = 0.649; p = 0.001), while females exhibited no difference (Repeat: −3.386 ± 0.592 μV; Switch: −3.355 ± 0.632 μV; p = 0.688). For latency, there was a significant interaction between tDCS and trial type [F (1, 20) = 4.797, p = 0.041, η2p = 0.193]. Under the sham condition, N2 latency was significantly delayed in switch trials (M = 325.267, SD = 9.993) than in repeat trials (M = 308.033, SD = 9.469; p = 0.022; p = 0.022), while no difference was observed under the a-tDCS condition (Repeat: 308.900 ± 11.319 ms; Switch: 308.367 ± 10.757 ms; p = 0.918) (Fig. 2). P3: For amplitude, the P3 value was significantly larger in switch trials (M = 2.100, SD = 0.409) than in repeat trials (M = 1.910, SD = 0.399) [F (1, 20) = 7.287, p = 0.014, η2p = 0.267]. No other significant effects were observed (p-values >0.05) (Fig. 2). Time-frequency analysis No significant differences were observed in the delta band (p-values > 0.05). Therefore, only significant results for the theta, alpha, and beta bands are reported below. Theta band Within the 100–400 ms time window, a significant interaction between tDCS and gender was observed over the central region [F (1, 20) = 5.093, p = 0.035, η2p = 0.203]. Females exhibited a significantly higher theta power in the a-tDCS condition (M = 0.581, SD = 0.255) compared to the sham condition (M = 0.266, SD = 0.265; p = 0.034), whereas males showed no such difference (Sham: M = 0.688, SD = 0.291; a-tDCS: M = 0.541, SD = 0.280; p = 0.342). Similar interaction effects were observed in parietal [F (1, 20) = 6.914, p = 0.016, η2p = 0.257] and occipital [F (1, 20) = 6.899, p = 0.016, η2p = 0.256] regions. Moreover, a significant main effect of trial type was observed in all brain regions, with the parietal region exhibiting the most pronounced difference [F (1, 20) = 24.327, p < 0.001, η2p = 0.549]. Switch trials (M = 0.427, SD = 0.221) had significantly larger values than repeat trials (M = 0.165, SD = 0.218) (Fig. 3). Scalp topography of the theta band (100-400 ms) under sham and a-tDCS conditions. Within the 700–1500 ms time window, a significant main effect of trial type was observed in all brain regions, with the central region exhibiting the most pronounced difference [F (1, 20) = 41.104, p < 0.001, η2p = 0.673]. Switch trials (M = 0.220, SD = 0.203) had significantly larger values than repeat trials (M = −0.090, SD = 0.190). No other significant effects were found (p-values > 0.05) (Fig. 4). Scalp topography of the theta band (700-1500 ms) under sham and a-tDCS conditions. Alpha band Within the 1200–1500 ms time window over the frontal region, the interaction between tDCS and trial type was significant [F (1, 20) = 4.964, p = 0.038, η2p = 0.199]. Post-hoc analysis further revealed that under the sham condition, the repeat trials (M = −1.052, SD = 0.337) had significantly larger values than switch trials (M = −1.583, SD = 0.395; p = 0.015). On the other hand, no such difference was observed between the repeat (M = −1.127, SD = 0.238) and switch (M = −1.069, SD = 0.281; p = 0.738) trials under the a-tDCS condition. A comparable interaction effect was found over the central region [F (1, 20) = 5.163, p = 0.034, η2p = 0.205], with repeat trials (M = −0.953, SD = 0.249) showing a significantly greater alpha power than switch trials (M = −1.382, SD = 0.309; p = 0.016) under the sham condition and no effect under the a-tDCS condition (p = 0.643). No other significant effects were found (p-values > 0.05) (Fig. 5). Scalp topography of the alpha band under sham and a-tDCS conditions. Beta band Within the 600-800 ms time window, a significant interaction between tDCS and trial type was found over the parietal region [F (1, 20) = 4.926, p = 0.038, η2p = 0.198]. Under the sham condition, the repeat trials (M = −2.126, SD = 0.240) showed significantly larger values than the switch trials (M = −2.398, SD = 0.245, p = 0.011). Conversely, no such difference was observed under the a-tDCS condition (Repeat: M = −2.338, SD = 0.205; Switch: M = −2.389, SD = 0.243; p = 0.569). No significant effects were detected in other brain regions (Fig. 6). Scalp topography of the beta band under sham and a-tDCS conditions. EEG-based classification model Herein, the classification accuracies for different categorization tasks (i.e., trial type, task type, and response hand) were determined at each sampling point from −600 to 1500 ms. Table 2 shows the peak values and latencies. Table 2Classification accuracy in unpredictable task switching.Table 2Shama-tDCSTrial typeTask typeResponse handTrial typeTask typeResponse handPeakLatencyPeakLatencyPeakLatencyPeakLatencyPeakLatencyPeakLatencyPre-stimulus (−600 to 0 ms)Low0.041(0.081)−290.5450.049(0.075)−362.5460.052(0.083)−269.4550.054(0.070)−328.7230.057(0.069)−238.1820.054(0.103)−224.000High0.065(0.096)−328.4000.051(0.079)−272.0000.042(0.072)−283.2000.045(0.079)−265.6000.055(0.088)−286.4000.059(0.093)−255.200SRI (0 to 900 ms)Low0.049(0.068)484.7270.059(0.104)444.3640.058(0.086)613.8180.066(0.092)605.4550.052(0.075)527.6360.058(0.078)626.182High0.059(0.082)406.0000.055(0.085)373.6000.063(0.074)468.8000.058(0.085)481.2000.060(0.089)454.0000.058(0.088)526.400Post-response (900 to 1500 ms)Low0.064(0.086)1193.4550.048(0.062)1226.9090.070(0.092)1148.3640.065(0.097)1242.5460.046(0.070)1064.3640.069(0.090)1190.545High0.058(0.084)1198.4000.056(0.076)1266.8000.065(0.096)1243.6000.067(0.106)1194.4000.052(0.075)1137.6000.065(0.092)1238.000Note: Peak values represent the magnitude by which classification accuracy exceeds random chance (50%), with values in parentheses indicating standard deviations (SD); “Low” refers to the Low-Gain Group and “High” refers to the High-Gain Group; latency is reported in milliseconds (ms); SRI refers to the stimulus-response interval. Classification accuracy in unpredictable task switching. Note: Peak values represent the magnitude by which classification accuracy exceeds random chance (50%), with values in parentheses indicating standard deviations (SD); “Low” refers to the Low-Gain Group and “High” refers to the High-Gain Group; latency is reported in milliseconds (ms); SRI refers to the stimulus-response interval. Classification accuracy A four-way ANOVA was conducted with tDCS (sham, a-tDCS), feature (trial type, task type, response hand), gain (low, high), and period (pre-stimulus, SRI, post-stimulus)​ as factors, and peak classification accuracy and its latency as dependent variables. For peak, a significant four-factor interaction was observed [F (4, 16) = 3.212, p = 0.041, η2p = 0.445]. Post-hoc tests further revealed that during the SRI, the low-gain group showed a significantly lower trial-type classification accuracy in the sham condition (M = 0.041, SD = 0.007) than in the a-tDCS condition (M = 0.054, SD = 0.005) [F (1, 19) = 6.597, p = 0.019, η2p = 0.258]. During the pre-stimulus period, the high-gain group showed a significantly higher trial-type classification accuracy in the sham condition (M = 0.065, SD = 0.007) than in the a-tDCS condition (M = 0.045, SD = 0.005) [F (1, 19) = 9.386, p = 0.006, η2p = 0.331]. During the pre-stimulus period, the high-gain group showed a significantly higher response-hand classification accuracy in the a-tDCS condition (M = 0.059, SD = 0.007) than in the sham condition (M = 0.042, SD = 0.006) [F (1, 19) = 4.605, p = 0.045, η2p = 0.195]. No other significant results were observed (p-values >0.05) (Fig. 6). For latency, the main effect of feature was significant [F (2, 18) = 5.385, p = 0.015, η2p = 0.374]. Compared to the task-type feature (M = 444.679, SD = 17.809; p = 0.012), the response-hand feature (M = 501.988, SD = 16.111) demonstrated a significantly later latency of classification accuracy peak, with no difference found between trial-type (M = 466.076, SD = 18.022) and task-type. No significant tDCS-related results were found (p-values > 0.05) (Fig. 7). Classification accuracy above chance level for low-gain and high-gain groups under sham and a-tDCS conditions. Model interpretability For the trial-type classification task of primary interest, three-way ANOVAs for each period and each brain region were conducted, with gain, tDCS, and frequency band as variables (see Fig. S1 and S2). Pre-stimulus period First, a significant tDCS * gain * band interaction was detected in the right central region [F (3, 17) = 4.568, p = 0.016, η2p = 0.446]. Post-hoc tests uncovered elevated alpha weights under a-tDCS (M = 0.142, SD = 0.023) compared with the sham (M = 0.058, SD = 0.017) in the high-gain group (p = 0.003). Second, the interaction between tDCS and band was significant in the left frontal [F (3, 17) = 3.379, p = 0.043, η2p = 0.374], left centrofrontal [F (3, 17) = 4.571, p = 0.016, η2p = 0.446], and left centroparietal regions [F (3, 17) = 3.673, p = 0.033, η2p = 0.393]. Post-hoc tests revealed higher delta weight under sham (M = 0.100, SD = 0.020) than a-tDCS (M = 0.051, SD = 0.007, p = 0.015) in the left frontal region, higher alpha weight under a-tDCS (M = 0.135, SD = 0.026, p = 0.013) than sham (M = 0.072, SD = 0.017) in the left centrofrontal region, but there were no significant differences in the left centroparietal region. Third, it was observed that the main effect of the band was significant in multiple brain regions (Table 3). Specifically, alpha band weight exceeded the delta band weight in the occipitoparietal, occipitotemporal, centroparietal, centrofrontal, and left central regions (ps < 0.05). Moreover, the beta band weight was increased in the parietal regions, particularly the left parietal region, where alpha (M = 0.112, SD = 0.013) and beta (M = 0.110, SD = 0.020) exceeded delta (M = 0.039, SD = 0.007; p < 0.001, p = 0.027, respectively). For the frontal regions, the alpha band weight was significantly greater compared with the theta band weight. Particularly, the alpha band weight (M = 0.115, SD = 0.019) markedly exceeded the theta (M = 0.058, SD = 0.008) (p = 0.015) in the left frontal region. Table 3Main effects of band in each brain region for trial type classification.Table 3RegionsPre-stimulusSRIPost-responseRegionsPre-stimulusSRIPost-responseLeft Frontal6.725**Right Frontal3.755*Left Centrofrontal3.350*Right Centrofrontal6.133**Left Central3.350*5.959**15.275***Right CentralLeft Centroparietal6.948**5.899**Right Centroparietal4.927*4.194*Left Parietal12.869***11.563***8.360**Right Parietal5.178**5.144**6.772**Left Occipitoparietal5.982**11.820***Right Occipitoparietal4.087*5.505**Left Occipitotemporal3.602*3.261*Right Occipitotemporal4.534*Left TemporalRight TemporalMidline4.968*Note: Values represent F-statistics for the main effect of frequency band on trial-type classification task. *p < 0.05. **p < 0.01. ***p < 0.001. Main effects of band in each brain region for trial type classification. Note: Values represent F-statistics for the main effect of frequency band on trial-type classification task. *p < 0.05. **p < 0.01. ***p < 0.001. The SRI period There was a notable interaction between band and gain in right central region [F (3, 17) = 3.668, p = 0.033, η2p = 0.393]. Results of post-hoc test demonstrated smaller theta band weight in the low-gain group (M = 0.065, SD = 0.009) relative to the high-gain group (M = 0.080, SD = 0.010; p = 0.010). No other significant tDCS-related effects were observed (ps > 0.05). Moreover, the main effect of the band was pronounced in the parietal, centroparietal, and left central regions (Table 3). Notably, the alpha band played a crucial role in the right parietal region, right centroparietal region and left central region. In the left parietal and left centroparietal regions, the beta band weight increased significantly. For instance, in the left parietal region [F (3, 17) = 11.563, p < 0.001, η2p = 0.671], alpha (M = 0.119, SD = 0.022) and beta (M = 0.120, SD = 0.013), exceeded delta (M = 0.050, SD = 0.008; p = 0.010, p < 0.001, respectively). The post-response period While there was a significant interaction of tDCS, band, with gain observed in the right occipitoparietal region [F (3, 17) = 5.918, p = 0.006, η2p = 0.511], post-hoc analyses were not significant. However, the main effect of the band was significant in multiple brain regions (Table 3). It was observed that the alpha band plays a major role in the left occipitoparietal, left occipitotemporal, and left centroparietal regions. In the parietal, right occipitoparietal, and left central regions, the beta band weight was also significantly increased. Using the right parietal region as an example [F (3, 17) = 6.772, p = 0.003, η2p = 0.544], both the alpha (M = 0.139, SD = 0.029) and beta (M = 0.111, SD = 0.016) exceeded delta (M = 0.061, SD = 0.008; p = 0.044, p = 0.008, respectively). Discussion This study is the first to explore the neural mechanisms underlying the tDCS-induced effect in unpredictable task switching by combining EEG analysis and ML. Notably, multiple significant tDCS-related effects were observed. In behavioral outcomes, a-tDCS over the rDLPFC significantly increased switch cost accuracy but decreased mixing cost accuracy compared to sham stimulation. For ERP analysis, a-tDCS elicited a marked larger N1 in repeat trials, while the significant difference in N2 latency between repeat and switch trials under sham condition disappeared under a-tDCS condition. Time-frequency results revealed a significantly larger theta power (100-400 ms) for females, whereas the significant difference in alpha power (1200-1500 ms, frontal and central regions) and beta power (600-800 ms, parietal region) between repeat and switch trials under sham condition disappeared under. In the EEG decoding analysis, significant tDCS-related differences were detected in pre-stimulus and SRI periods. Specifically, in the low-gain group, trial-type classification accuracy was significantly enhanced under a-tDCS compared to sham during the SRI. In the high-gain group, trial-type classification accuracy under a-tDCS condition was significantly lower while response-hand classification accuracy was significantly enhanced compared to sham condition during the pre-stimulus period. Model interpretability further showed that a-tDCS stimulation was associated with reduced delta band weights in the left frontal region, increased alpha band weights in the left centrofrontal region, and a selective enhancement of alpha band weights in the right central region exclusive to the high-gain group. These results demonstrate that a-tDCS over the rDLPFC alters task switching performance, reinforcing the critical role of the prefrontal cortex in task switching (Leite et al., 2011, Leite et al., 2013; Sdoia et al., 2020; Tayeb and Lavidor, 2016; Wang et al., 2021). They also validate the presence of ERP and time-frequency components in unpredictable task switching, consistent with prior studies (Capizzi et al., 2020; Gajewski et al., 2018; McKewen et al., 2021; Petruo and Beste, 2021; Wang et al., 2024). Beyond replication, our findings reveal that the rDLPFC a-tDCS influenced unpredictable task switching performance by targeting inhibition-related ERP components (i.e., N1 and N2), enhancing theta power, and attenuating alpha and beta power differences between switch and repeat trials. Moreover, from a ML perspective, we identified distinct effects of a-tDCS over the rDLPFC within specific periods, highlighting the significance of pre-stimulus task preparation in unpredictable task switching and revealing the complexity and dynamic nature of neural processes underlying it. ERP analysis First of all, we found a significantly more negative N2 and larger P3 in switch trials than repeat trials, which is consistent with outcomes from previous studies, and supporting a processing difference between switch and repeat trials (Meiran, 1996; Monsell, 2003; Rogers and Monsell, 1995). More importantly, our results revealed that a-tDCS over the rDLPFC significantly modulated the N1 and N2 components, inducing a larger repeat-related N1 and an earlier switch-related N2 under a-tDCS condition compared to sham. In unpredictable task switching, the N1 component is linked to early sensory encoding of abrupt stimuli and attentional resource allocation, while the N2 reflects rapid conflict monitoring and engagement of inhibitory control (Gajewski et al., 2018). Therefore, a larger repeat-related N1 suggests enhanced attentional resource allocation to repeat trials under a-tDCS condition as compensatory strategy (Gajewski et al., 2018), and the earlier switch-related N2 indicates improved conflict resolution efficiency during switching. Given that a-tDCS concurrently modulates both components, it may enhance N1 processing to provide reliable inputs for N2-mediated conflict detection, thereby accelerating conflict resolution and enabling faster inhibition of irrelevant task sets. However, unpredictable task switching inherently lacks advance cues, requiring sustained vigilance across all trials to maintain performance. Here, the larger repeat-related N1 under the a-tDCS condition may potentially reflect excessive attentional resource allocation. While this could facilitate rapid inhibition of irrelevant tasks, it may also lead to neural fatigue or cognitive resource depletion, ultimately impairing the ability to sustain high accuracy over time. This interpretation is supported by our behavioral data showing decreased mixed-trial accuracy under a-tDCS condition. Time-frequency analysis Generally, theta activity is critical for cognitive control and conflict monitoring, alpha band is involved in inhibitory control, and beta activity is involved in sensorimotor functions (Capizzi et al., 2020). In this study, we found a significantly higher theta power (100-400 ms, 700-1500 ms), lower alpha power (1200-1500 ms) and beta power (600-800 ms) for switch trials compared to repeat trials. These findings align with those of Capizzi et al., 2020, who identified processing differences between switch and repeat trials using time-frequency analysis. Specifically, repeat trials primarily involve reusing previous rules and response execution. Meanwhile, for unpredictable task switching, participants consistently need to activate the alternative task set and maintain both (the current and alternative task sets) in working memory for the next trial. In contrast, switch trials require more extensive cognitive processes. The increased theta power (100-400 ms) indicates inhibition of irrelevant task sets and activation of relevant ones. The decrease in beta power (600-800 ms) reflects inhibition of motor impulse associated with irrelevant stimulus-response mappings. The concurrent increase in theta and decrease in alpha (1200-1500 ms) suggests the disinhibition of irrelevant task sets and maintenance of task sets for upcoming trials. Notably, a-tDCS over the right DLPFC significantly altered theta power (100-400 ms), alpha power (1200-1500 ms, frontal and central regions), and beta power (600-800 ms, parietal region). The increased theta power under a-tDCS condition suggested enhanced attentional resource allocation and early conflict detection. For the absence of trial-type differences in beta power under the a-tDCS condition driven primarily by reduced suppression of beta power during repeat trials, one possible interpretation is that participants were actively inhibiting stimulus–response mappings irrelevant to the current task, even in the absence of an explicit demand for response inhibition. This could reflect a proactive neural regulatory strategy or a forced neural activity driven by a-tDCS. Moreover, the disappearance of trial difference in alpha power under a-tDCS condition, which is caused by the increased switch-trial alpha power, may indicate decreased effort in differentiating irrelevant task sets. However, it should be noted that caution is warranted when interpreting the absence of trial-type differences, as this pattern may arise from a variety of distinct factors or lack of power. In addition, we note that the larger theta power observed under the a-tDCS condition was only detected in females. Given that previous studies have reported better task-switching performance in females, a-tDCS over the right DLPFC may amplify this gender-related effect via modulation of theta power (Kheloui et al., 2023; Kuptsova et al., 2015). Considering the limited sample size, conclusions about tDCS-induced gender differences need to be interpreted with caution. Decoding analysis In this study, we determined the switch cost accuracy differences between a-tDCS and sham conditions and divided participants into low/high-gain groups via median split of switch cost improvement (Andrade et al., 2023). This grouping identified that tDCS had different effects on neural modulation. In the low-gain group, a-tDCS significantly improved accuracy in trial-type classification during the SRI period, suggesting that a-tDCS improved discrimination between repeat and switch trials post-stimulus. This effect is likely due to the rDLPFC's critical role in reactive conflict resolution (Aron et al., 2004;Wang et al., 2021). Conversely, the high-gain group revealed decreased trial-type classification accuracy under a-tDCS condition during pre-stimulus period. Although counterintuitive, this is consistent with the observations in ERP and time-frequency. Specifically, instead of predicting trial types, these participants may be adopted a non-selective preparatory strategy, distributing attention broadly to minimize uncertainty. Thus, the trade-off between anticipation and generality may have weakened trial-type specificity. In addition, a-tDCS improved response-hand classification accuracy during the pre-stimulus period in high-gain group, which may reflect strengthened stimulus-response mapping networks and more robust motor preparation. These divergent effects observed across groups may stem from pre-existing differences in cognitive strategies, with low-gain participants relying on reactive, stimulus-driven processing to resolve trial-type ambiguity and high-gain participants employing proactive control for broad trial preparation. Moreover, anodal tDCS over the right DLPFC may have accentuated these strategic differences between groups. Additional contributing factors—such as individual variability in neural plasticity, perceived task difficulty, and emotional or motivational states—may also play a role, although these influences warrant further investigation and empirical validation. Notably, the complexity of these interactions may also be influenced by the inherent limitations of a relatively small sample size. For latency, we observed a significantly delayed accuracy peak for response-hand classification compared to task-type classification, which indicated a sequential activation model of task switching (Hubbard et al., 2019). Moreover, Hubbard et al. (2019) reported significant latency differences in the peaks between trial-type classification and task-type classification, which was not detected in this study, potentially due to the lower task complexity (i.e., parity/magnitude task) and different task predictability. Interpretability The alpha band weights in the parietal and left central regions were consistently dominant across all periods, highlighting their critical roles in distinguishing switch and repeat trials during unpredictable task switching such as conflict monitoring and inhibitory control. Notably, both alpha and beta bands demonstrated significantly increased weights in the left parietal region, suggesting that beta activity may function synergistically with alpha rhythms to support sensorimotor integration during task switching. Future studies should be conducted to further clarify the role of alpha-beta relationship in task switching. Moreover, a broader network including frontal, occipitoparietal, occipitotemporal, and centrofrontal regions exhibited alpha band predominance during the pre-stimulus period. This proactive activation indicates that participants engaged in task-set preparation prior to stimulus onset, enabling the brain to more efficiently distinguish between switch and repeat trials once they appeared. Besides, unlike the SRI period, the post-response period was characterized by additional activation of the occipitoparietal and occipitotemporal regions, with alpha and beta bands showing significantly higher weights. This points to a post-response integrative process that includes response evaluation, error monitoring, and task-set re-alignment. Most a-tDCS-induced weight differences were primarily detected during the pre-stimulus period. Specifically, a-tDCS markedly decreased the delta band weights in the left frontal region while enhancing the alpha band weights in the left centrofrontal region. This finding suggests that tDCS enhances task preparation efficiency by reducing resting-state neural activity and strengthening cognitive control mechanisms. In addition, a-tDCS enhanced alpha band weights in the right central region exclusively in the high-gain group, with no significant differences in the low-gain group. This may reflect accelerated activation of motor response preplans, indicating that high-gain individuals may benefit more from a-tDCS over the DLPFC. During the SRI period, the high-gain group had significantly higher theta band weights in the right central region compared to the low-gain group. This likely reflects differences in conflict detection for motor rules between the two groups, suggesting that different strategies are involved in processing unpredictable task switching. Limitations This study presents several limitations. First, the current study was designed to investigate whether an ML-based approach can decode task-switching processes under tDCS conditions, which makes this work fundamentally exploratory rather than confirmatory. Given the exploratory nature and the limited sample size (N = 24) of this study, the current decoding results, along with their convergence with ERP and time-frequency analyses, should be interpreted as preliminary findings. Also, the generalizability of a-tDCS-induced gender differences warrants caution and requires further investigation. Thus, future studies should recruit larger samples, conduct well-powered experiments, and use strict FWER correction across multiple neurophysiological measures to establish the robustness of these initial observations. Second, we achieved a task-switching-related classification accuracy of 55.56% (maximum 58.9%), which is consistent with previous findings (Cao et al., 2023; Hubbard et al., 2019). However, this accuracy remains relatively low, and it may stem from shared neural representations between switch and repeat trials, as well as the influence of muscle-related or other non-neural EEG artifacts. Also, the small sample size has constrained the application and generalizability of ML methods. Future studies should recruit larger samples, while further optimizing task designs, improving noise suppression, and adopting more diverse analytical methods (e.g., principal component analysis, PCA). Third, the present study mainly used EEG to examine the neural mechanisms of tDCS-induced effects in task switching. However, EEG has low spatial resolution, making it difficult to identify which brain regions are modulated by tDCS in time-frequency and decoding analyses. Future studies could derive advantages from incorporating fMRI to explore the causal relationships between specific brain regions and task switching. Conclusions Here, we obtained the following conclusions. First, a-tDCS over the rDLPFC modulates unpredictable task switching performance by influencing early attentional allocation, conflict detection, and inhibitory control. Second, alpha and beta bands play important roles in trial-type classification for unpredictable task switching, especially in the parietal and left central regions. Third, a-tDCS differentially modulates the trial-type classification accuracy, where low-gain individuals exhibit a higher accuracy during SRI, which indicates enhanced reactive conflict resolution, and high-gain individuals present lower pre-stimulus accuracy as a function of general proactive preparation. CRediT authorship contribution statement Ziyu Wang: Conceptualization, Data curation, Funding acquisition, Investigation, Methodology, Writing – original draft, Writing – review & editing. Ziyuan Zhang: Data curation, Formal analysis, Methodology, Software, Visualization, Writing – original draft. Rongjuan Zhu: Conceptualization, Funding acquisition, Investigation, Methodology, Writing – original draft. Xinru Zhang: Data curation, Investigation, Methodology, Writing – original draft. Xuqun You: Conceptualization, Methodology, Validation, Writing – review & editing. Jimin Liang: Methodology, Supervision, Validation, Writing – review & editing. Declaration of competing interest The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper. Acknowledgments This study was supported by the National Natural Science Foundation of China (Grant No. 32200894) and the Youth Fund Project of Humanities and Social Sciences Research of the Ministry of Education of China (Grant No. 23YJC190042). Footnotes Supplementary data to this article can be found online at https://doi.org/10.1016/j.ynirp.2026.100386. Contributor Information Ziyu Wang, Email: wangziyu@xjtu.edu.cn. Jimin Liang, Email: jimleung@mail.xidian.edu.cn. Supplementary data The following are the Supplementary data to this article: Data availability Data will be made available on request. References Associated Data Data Availability Statement Data will be made available on request.