arXiv:2610.16921cs.NEOct 2026

Manuscript Offprint

arXiv:2610.16921

Time Window Optimization for Motor Imagery Classification via Temporal Structure Embedded Reinforcement Learning

Huan Luo, Na Lu, Xiaopeng Wang, Ziyang Shang

Huan Luo, Na Lu, Xiaopeng Wang, and Ziyang Shang

Abstract—Online motor imagery-based brain-computer interfaces (MI-BCIs) usually processes continuous EEG signal with fixed-length sliding windows, which is inflexible, human intervened, and misaligned with neural events. Time window optimization has shown promising improvement as a substitute solution. However, the existing optimization methods typically evaluate windows isolatedly and fail to model temporal dependencies across consecutive windows, which may produce fragmented and physiologically implausible sequences. To address this limitation, we propose a novel Temporal Structure Embedded Reinforcement Learning (TSE-RL) framework. This framework embeds prior temporal-structure knowledge of MI events into a stable RL formulation, reformulating window optimization as a constrained Markov Decision Process with ordinal relation enforcement of neural event. First, the evaluation and action selection upon each window has been changed from simply “retain/discard” to semantic alignment between window and neural events as Discard/Onset/sustain/Offset. Second, action masking is imposed by a finite-state machine (FSM) which enforces physiologically plausible decision orders with constraint of neural activity progress in term of planning/execution/recovery, enhancing both rationality, interpretability and classification performance. Third, a Transformer-based history encoder is designed to capture long-range inter-window dependencies in parallel, improving training stability and efficiency compared with existing recurrent architectures. Besides, TSE-RL adopts a plug-and-play design that can be integrated with diverse MI classifiers. Extensive experiments on multiple benchmark datasets demonstrate that TSE-RL consistently improves decoding performance in both cross-session and cross-subject settings. Visualization analyses further suggest that the learned policy of window optimization aligns with neurophysiological principles.

Index Terms—Brain computer interface, electroencephalography, motor imagery, reinforcement learning

I. INTRODUCTION

This work was supported by National Natural Science Foundation of China under Grant No. 62476213, Natural Science Basic Research Program of Shaanxi Province under Grant 2024JC-YBMS-486. (Corresponding author: Na Lu.)

Huan Luo is with the School of Future Technology, Xi'an Jiaotong University, Xi'an, 710049, China (e-mail: luohuan123@stu.xjtu.edu.cn).

Other authors are with the School of Automation Science and Engineering, Xi'an Jiaotong University, Xi'an, 710049, China (e-mail: lvna2009@mail.xjtu.edu.cn; wxp035112@stu.xjtu.edu.cn; 2203712691@stu.xjtu.edu.cn).

B RAIN computer interface (BCI) technology establishes a direct communication and control pathway between the brain and external devices by decoding neural activity [1]. It has broad potential in diverse fields such as neurorehabilitation, entertainment [2], and human-machine interaction [3]. Among non-invasive acquisition modalities, electroencephalography (EEG) is widely adopted due to its high temporal resolution and relatively low cost [4]. In motor imagery (MI) BCIs, users voluntarily imagine limb movements to elicit event-related desynchronization/synchronization (ERD/ERS) patterns [5], [6], thereby enabling device control without external stimuli.

Recent years have witnessed significant advances in MI-EEG signal decoding techniques, most of which analyze a predefined post-cue segment (typically 0–4 s) for feature extraction and classification [7]. Representative approaches range from Common Spatial Patterns (CSP) [8], which learns spatial filters by maximizing inter-class variance, to diverse deep learning methods. Convolutional Neural Networks (CNNs) like EEGNet [9] and M-ShallowConvNet [10] efficiently capture spatio-temporal patterns with depthwise separable convolutions or shallow designs. FBCNet [11] performs frequency-band fusion via multi-view convolutions, while ATCNet [12] integrates attention mechanisms with temporal convolutional networks. More recently, Transformer-based models have been explored in EEGConformer [13] and TSLANet [14]. And CSPNet [15] embeds CSP principles within a neural network framework. Riemannian geometry-based methods such as manifold attention network (mAtt) [16] characterize EEG patterns on the Riemannian manifold of symmetric positive-definite (SPD) matrices.

Although these methods perform well in offline evaluations, their performance in online scenarios are constrained by using a single, shared temporal segment to represent MI activity across trials. For instance, online systems often relies on a sliding window of fixed length (around 1 s) moving along the continuous EEG signal. Some windows may cover only a fraction of an MI event, some may contain excessive pre-event baseline activity, and some may be contaminated by burst artifacts, the majority of which are misaligned with actual neural events. Meanwhile, fixed-length windows restrict the timeliness of the system response. Online decoding thus can benefit from time window optimization, where windows are adaptively accumulated or discarded to form a segment that

PREPRINT

better matches informative neural patterns, providing better balance between timeliness and accuracy.

Researchers have proposed various time window optimization strategies. Correlation-based Time Window Selection (CTWS) [17] adjusts the onset of window by correlating sliding windows with reference signals. Approaches based on Ant Colony Optimization (ACO) [18] and Sparrow Search Algorithm (SSA) [19] employ meta-learning and heuristic searches to identify optimal configurations in time-frequency parameter space. However, these techniques typically evaluate and select candidate windows independently, treating each as an isolated “good/bad” decision based on the quality of the window, with configurations searched offline and applied uniformly across trials [20], [21]. This limitation can result in fragmented or physiologically implausible window sequences that fail to capture the coherent evolution of MI events. In contrast, our method optimizes the time window sequence, conditioning each decision on cross-window history and on the constraint of MI phases. MI events exhibit contralateral desynchronization of the μ\mu (8–13 Hz) and β\beta (13–30 Hz) rhythms during MI execution, and a subsequent rebound of synchronization of the β\beta-rhythm after the event ends [22]. Such an evolution suggests distinct MI phases from onset to sustained imagery and finally to offset.

Reinforcement Learning (RL) provides an ideal framework to overcome this limitation, as it inherently models sequential decision-making processes with uncertainty. By formulating the problem of time window optimization in MI-EEG as a Markov Decision Process (MDP), an agent makes adaptive decisions at each time step based on the current state and historical context (e.g., whether to retain a window and what temporal role it plays in the MI event) to maximize cumulative rewards through interactions with the environment. It also avoids brute-force search over window combinations through exploration-exploitation. In addition, Safe Reinforcement Learning [23] also inspires us to incorporate neural event ordinal information, where temporal-structure patterns must be embedded to constrain the action space. Notably, preliminary studies have demonstrated the potential of RL in improving BCI adaptivity. Aung et al. [24] use RL to decide whether to classify or skip the current time point, and Zhang et al. [25] use RL to adaptively focus on features at varying scales. In both, RL improves the adaptivity of the BCI decoding: the action optimizes one component inside the decoding pipeline, while the analyzed window remains fixed and predefined. Our work instead optimizes the window itself, taking each incoming window as the decision unit, assigning it an explicit semantic role, and constraining the action space by the structure of MI events.

Therefore, we propose a Temporal Structure Embedded Reinforcement Learning (TSE-RL) framework for adaptive time window optimization in MI-EEG decoding. The core innovation of this framework is to embed prior temporal-structure knowledge of MI events into a stable RL framework, transforming window optimization from isolated “good/bad” judgments to semantic alignment of complete neural events. Specifically, TSE-RL incorporates three mechanisms to make this idea practical and reliable. The first mechanism transforms the action selection upon each time window from simply “retain/discard” to semantic alignment between window and neural events as Discard/Onset/sustain/Offset. This semantic alignment mechanism imposes physiological patterns on window optimization of EEG signal. The second mechanism adopts Finite State Machine (FSM) for constrained action masking which enables safe reinforcement learning in restricted action space. Without proper constraints, the RL agent may generate physiologically implausible window sequences that violate the known temporal structure of MI events (e.g., selecting an Offset before an Onset). The third mechanism concerns Transformer-based history encoding. The decisions of window optimization require integrating historical context, while traditional RL methods often employing Recurrent Neural Networks (RNNs) to capture temporal dependencies. When processing long sequences, RNNs are prone to gradient vanishing or explosion, resulting in training instability [26]. The main contributions of this paper include:

  • We propose a temporal window optimization method that embeds MI event temporal structure knowledge into a reinforcement learning framework. The action space based on EEG time window evaluation is semantically aligned with neural event for interpretability and performance improvement. FSM-based action masking is designed to ensure physiological plausible decision sequence with constraint of neural activity progress in term of planning/execution/recovery.

  • We design a Transformer-based history encoder to replace training-unstable recurrent networks. This encoder takes historical window sequences as input and leverages self-attention mechanisms to learn temporal dependencies across windows in parallel, improving both training stability and computational efficiency.

  • TSE-RL is plug-and-play and can be integrated with various mainstream MI classifiers. Simulated online experiments on multiple public datasets demonstrate that it significantly improves decoding performance in both cross-session and cross-subject settings.

References (35)