# Recursive sample weighted – N-way partial least squares for brain-computer interface decoder online learning with class imbalance

Rémi Souriau, Felix Martel, Tetiana Aksenova

► To cite this version:

Rémi Souriau, Felix Martel, Tetiana Aksenova. Recursive sample weighted – N-way partial least squares for brain-computer interface decoder online learning with class imbalance. Biomedical Signal Processing and Control, 2025, 113, pp.109025. 10.1016/j.bspc.2025.109025. cea-05504211

HAL Id: cea-05504211

https://cea.hal.science/cea-05504211v1

Submitted on 10 Feb 2026

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons CC BY 4.0 - Attribution - International License
Recursive Sample Weighted – N-way Partial Least
Square for Brain-Computer Interface Decoder Online
Learning with Class Imbalance

Rémi Souriau<sup>a,*</sup>, Félix Martel<sup>a</sup>, Tetiana Aksenova<sup>a</sup>

<sup>a</sup>Univ. Grenoble Alpes, CEA, Leti, Clinatec, F-38000 Grenoble, France

**Abstract**

Real-time online decoder training is effective for Brain-Computer Interfaces (BCIs), enabling the consideration of sensitive responses in the brain neural signals. However, class imbalance can occur during calibration, with some tasks (or classes) being harder to learn than others. If left unaddressed, this imbalance can significantly decreases the decoder's overall performance.

To tackle this issue, this paper introduces a novel algorithm called Recursive Sample Weighted – N-way Partial Least Squares (RSW-NPLS). In RSW-NPLS, weights are assigned to each training sample, with weighting a sample effectively equivalent to resampling it. The algorithm dynamically tracks the size of each class and computes weights to balance minority classes with the majority class at each update. A constraint is applied to avoid large weights during the calibration. The RSW-NPLS is well suited for BCI systems as it addresses several key constraints: it supports multiclass classification, is designed for online training, has low computational requirements, and can handle high-dimensional data.

The RSW-NPLS is compared to the Recursive Exponentially Weighted – N-way Partial Least Squares (REW-NPLS), another algorithm adapted for BCI systems but which does not address class imbalance. Both algorithms are evaluated in offline and pseudo-online configurations using three different databases to decode ECoG signals from paraplegia and tetraplegia patients implanted with WIMAGINE sensors. The RSW-NPLS outperforms the REW-NPLS in term of classification performance and stability. Tests demonstrate that the RSW-NPLS effectively compensates for class imbalance in real-time and maintains strong performance even with significant imbalances.

**Keywords**

Brain-computer interface, Class imbalance, Online learning, Electrocorticography, Tetraplegic, Paraplegic.

* Corresponding author at : Univ. Grenoble Alpes, CEA, Leti, Clinatec, F-38000 Grenoble, France.
E-mail address: remi.souriau@cea.fr (R. Souriau), felix.martel@cea.fr (F. Martel), tetiana.aksenova@cea.fr (T. Aksenova).
# 1- Introduction

Motor imagery Brain-Computer Interfaces (BCIs) offer a potential solution for individuals with severe motor disabilities. If the transmission of motor commands from the brain to the muscles is disrupted due to spinal cord injury, stroke, or other neurological damage, BCIs can bridge the gap. After recording the users' brain activity, the BCI system decodes their motor intentions to control an external effector, enabling movement. The brain activity can be measured with various type of sensors, such as noninvasive electroencephalography (EEG), minimally invasive intracranial electrocorticography (ECOG) [1], or more invasive intracortical microelectrodes array, etc. A BCI system may control various effectors such as an exoskeleton [2], [3], a wheelchair, an electrical spine stimulator [4] to activate the patient's own limbs, etc.

The BCI signal processing chain involves several steps. Recorded brain signals are first preprocessed to improve signal-to-noise ratio. Then, neural features are extracted, and a decoding model is used to predict the motor intent based on the input features. Finally, the command corresponding to the motor intent is sent to the effector. The decoder is, generally, patient specific, and is learned from the training data recorded during a single or multiple calibration session(s). During such sessions, the user performs mental tasks according to cues given by the system or by an experimenter. A large number of classifiers have been tested in BCI to classify mental tasks including sample-wise static linear and nonlinear classifiers [5] (e.g. linear discriminant analysis, Support-Vector-Machine (SVM), logistic regression, k-nearest neighbors, deep neural networks etc.), or dynamic classifiers such as generic Hidden Markov Models (HMM) [2], [6], [7], input-output HMM [8], conditional random fields [9], dynamic Bayesian models [10], time-dependent neural networks [11], or hierarchical HMM [12].

Nowadays, after proofs of concept in [3], [4], the main challenge in the BCI field is to make BCI systems usable in a daily life outside of the laboratory environment. To achieve this objective, the motor BCI decoder should meet a number of criteria. First, the models have to decode motor intention online with a high decision rate (at least 8-10 Hz) and a low latency. Moreover, closed loop online learning (streaming learning) is known to be more efficient compared to offline decoder learning [13]. Decoder training directly during the calibration sessions allows taking into account sensitive response in the brain neural signal. During online learning, data arrive in real time, are used to update the model, and are discarded. Thus, the full training data set is not available. In addition, a BCI system should be adapted to class incremental learning, i.e. the experimenter can add new states to the decoder without the need to retrain the full model. Next, the BCI system must operate in the so-called asynchronous mode. The decoder must be able to switch from an Idle State (IS) to Active States (AS). Guided by system, synchronous BCIs can only be used during a limited time frames [14]. One more challenge is to be able to control effectors with numerous degrees of freedom. The decoder should be designed to classify data across multiple labels. Finally, if restoring mobility, BCI system has to be compact and wearable. The decoding algorithms must not require high computational resources or remote computing, increasing latency. Ideally, a system adhering to the latest criterion can be implemented in a portable system.

This paper addresses one of the problems of real-life BCI: the problem of class imbalance during real-time decoder training. In BCI, some mental tasks is harder to perform than others, and require more time to train. For example, in [2], [3], the training of hand translations of an exoskeleton in a 3D space requires more time than the training wrist rotations. This results in class imbalance in the training data. Some classes called majority classes are overrepresented in the training data, while other minority classes are underrepresented. The class imbalance leads to a model bias in favor of majority classes, and, in the worst case, to ignoring the minority classes [15]. More generally, the problem of class imbalance is presented in many areas such as fault detection [16], email scam detection [17],
exploration of protein sequence in biology [18], credit risk assessment [19], etc. Online dynamic class balancing is less addressed in the literature compared to offline (static) class balancing (Figure 1). Dynamic class balancing is more complicated because class balancing must be done buffer by buffer when the final imbalance between classes is unknown. However, the interest in online algorithms and strategies to handle the class imbalance has been growing in recent years. A research on Scopus and Web of science shows the number of papers per year started to increase about twelve years ago and has accelerated in the last five years (see Figure 1 for number of articles by years in the SCOPUS database).

<figure><img src="image_2.png" /><figcaption>Figure 1: Number of articles by years from 1995 to 2024 according to a search on Scopus for online and offline algorithms. Keywords of the search were online learning AND class imbalance (and some related terms) for the blue curve and online related keyword were removed for the orange curve. The number of articles for online and online+offline methods are given on, respectively, the left scale and right scale. This graph illustrates the gain of interest in online learning algorithm the past recent years and the difference between the interests for online and offline methods.</figcaption></figure>

Generally, there are three main tendencies in both static and dynamic class balancing [15]. The first approach is data resampling. Resampling methods are independent from the learning algorithm and are based on over-sampling of the minority class, under-sampling the majority class, or both at the same time. One of the most popular method of such approach is the Synthetic Minority Over-sampling Technique (SMOTE) [20] and its variants, e.g. the Bordeline-SMOTE [21], the Adaptive Synthetic Sampling Approach for Imbalanced Learning (ADASYN) [22] etc. The SMOTE algorithm consists in creating new data for the minority class until both classes are balanced. Such a method requires knowing the entire dataset and is not adapted for online learning. Extensions of SMOTE to online learning are proposed in [23], [24], with the Continuous SMOTE (C-SMOTE) and the Very Fast Continuous SMOTE (VFC-SMOTE). These methods, however, are limited to binary classification and require storing past data in a variable-length window to over-sample the minority class. Another dynamic extensions of SMOTE is the SMOTE Edited Nearest Neighbor Regularized Weighted Online Sequential Extreme Machine Learning (SE-IRWOS-ELM) [25]. Data acquired chunk-by-chunk are over-sampled to balance two classes in each chunk. If a class is missing in a chunk, it is discarded. The SE-IRWOS-ELM algorithms cannot be applied for a multi-class problem unless each classes are present in each chunk. This is not applicable in BCI, especially if the experimenter wants to incrementally add new states after some training sessions. In addition, resampling methods require allocating additional memory to store data. The size of additional memory is variable. It may depend on how strong the imbalance between classes is. Such a constraint may not be adapted for compact systems with limited memory, and makes the time of the updating variable due to the changing size of the dataset.

The second approach to address the class imbalance issue, ensemble learning, consists in learning of a large number of classifiers. Weighted Online Sequential Extreme Learning Machine [26], Multi-class Over-sampling-based Online Bagging (MOOB) and Multi-class Under-sampling-based Online Bagging (MUOB) [27] are examples of online ensemble learning methods to tackle class imbalance. In MOOB
and MOUB, each observation is used to update each classifier *M* times, where *M* is a random variable following a Poisson's law. The parameter of the Poisson's law depends on the current imbalance in the data stream. The value of *M* tends to be large for an observation from the minority class, and small for an observation in the majority class. The classifier global output is obtained by votes from all the classifiers. Ensemble learning approaches require learning multiple classifiers. It results in increased computational time and memory consumption proportional to the number of models to learn.

Finally, algorithm-level methods directly adapt the learning algorithm to address the class imbalance. The classic approach is the cost-sensitive learning, which assigns a higher misclassification cost or higher weight to the minority class samples. Many online learning cost-sensitive algorithms focus on binary classification problems and not adapted to multiclass problems [26], [28], [29], [30]. These studies are majorly focused on applications where the minority class is the class of interest (fraud detection, medical diagnosis, manufacturing defect, etc.). The extension of a binary classification model into a multi-classification problem can be achieved through one-versus-all or one-versus-one strategies. However, such approaches require learning one model per class, which can become computationally intensive. Moreover, adding new classes during the calibration would mean to add some new models and/or retrain all previous models. Imbalance between multiple classes are considered in the Cost-Sensitive Online Adaptive Kernel Learning Algorithm for Multi-Classification (COAKM) [31]. The authors proposed a cost sensitive kernel-learning algorithm for support vector machine to handle class imbalance during an online learning. In this study, the authors claim that COAKM is not efficient to train the model on a database with a large imbalance and with high-dimensional data. These limitations are particularly inconvenient for BCI. The input feature in a motor BCI are, frequently, high-dimensional data (e.g. time-frequency-spatial representation of brain signal). In summary, unlinke resampling methods and ensemble learning, cost-sensitive algorithms address class imbalance without the need to train multiple classifiers or resample data. However, to the best of our knowledge, none of the proposed algorithm answering all the constraints of our application: streaming learning, class incremental learning, multi-class classification with dynamic evolution of class imbalance, adapted for compact system and high dimensional data.

The problem of dynamic real time class balancing in BCI is rarely addressed in the literature. In [25], the author presents the SE-IRWOS-ELM algorithm for learning a binary classifier in a BCI. Using dynamic resampling of each buffer this approach may not be feasible when dealing with a large number of classes. In [32], the author propose to fix class ratio by under-sampling data of the majority class and train a SVM for a binary classification problem in streaming learning. However, the algorithm is not adapted for multi-class classification problem and incremental learning.

In this paper, we propose the new Recursive Sample Weighted - N-way Partial Least Squares (RSW-NPLS) algorithm for BCI decoder learning, integrating dynamic class balancing. The proposed algorithm is a modification generic Recursive Exponentially Weighted N-ways PLS (REW-NPLS) [33]. REW-NPLS is an algorithm from the PLS family adapted for real-time streaming learning from high dimensional tensor data. Similar to other algorithms from the PLS family, REW-NPLS is not sensitive to irrelevant or redundant variables. The PLS family algorithms were used for the classification microarray data [34] or, in BCI, to decode desired movement of the index finger from magnetoencephalography data [33]. In [2], [3], [4], the REW-NPLS was integrated into a HMM to improve the decoder robustness. REWNPLS integrated to a HMM has been used for controlling of an exoskeleton by tetraplegic user [2], [3], and to restore the natural gait of a paraplegic user [4]. In this study, we modified the REW-NPLS algorithm adding a mechanism to handle class imbalance and its dynamic evolution during the online calibration of the system keeping the desired properties of the generic algorithm such as streaming learning, multi-class, etc. The proposed RSW-NPLS algorithm belongs to a family of algorithm-level approaches
directly adapting the learning algorithm for handling of the class imbalance without additional computational resources. Similarly to generic REW-NPLS, the proposed RSW-NPLS was integrated into a HMM to estimate emission probability of states. The RSW-NPLS and the REW-NPLS integrated into a HMM are compared in simulation of online streaming learning, in three databases recorded from two clinical trials with tetraplegic and paraplegic users. Results show the use of the RSW-NPLS improves the decoding performance, especially in the case of large imbalance. The classifier performance is also more stable.

## 2- Methods

### a. Generic PLS and family

#### Partial Least Square

Let $X = (X_1, ..., X_N)^T \in \mathbb{R}^{N \times p}$ be a matrix of $N$ observations of dimension $p$ and $Y = (Y_1, ..., Y_N)^T \in \mathbb{R}^{N \times q}$ be a matrix of outputs of dimension $q$, $X_t$ and $Y_t$ are the $t$th samples, respectively. The generic PLS [35] is an iterative algorithm to estimate the linear relationship between input and output variables: $Y_t = X_tB + b + E_t$, where $B \in \mathbb{R}^{p \times q}$ is the matrix of coefficients, $b \in \mathbb{R}^q$ is the bias vector, and $E_t$ is the residual vector (estimation error). The principle of the PLS algorithm and its extensions consists in projecting observations into a low dimension latent space to maximize the covariance of $X$ and $Y$. The representation of data into a low dimension space allows the algorithm to be effective for high dimension data in presence of highly correlated and/or irrelevant variables.

Data $X$ and $Y$ are, first, sample-wise normalized. For the sake of simplicity, in this study we will use the same notations for normalized data. Then, the covariance matrices $C^{XX}$ and $C^{XY}$ are computed:

$$ \begin{cases} C^{XX} = X^T X \\ C^{XY} = X^T Y. \end{cases} \qquad (1) $$

Coefficients of the regression model $B$ and $b$ are then deduced from the covariance matrices. There are several algorithms to estimate the linear regression coefficient e.g. the NIPALS algorithm or the kernel algorithm [33], [36]. The second one is retained in this study.

#### Recursive Exponentially Weighted PLS

The Recursive Exponentially Weighted Partial Least Squares (REW-PLS) [37] is a dynamic extension of the PLS for incremental streaming model learning. The model is updated whenever a new data chunk (or buffer) becomes available. Let $X_u \in \mathbb{R}^{n_u \times p}$ and $Y_u \in \mathbb{R}^{n_u \times q}$ be the input and the output data chunks, $n_u$ the size of the data chunk, and $u$ the index of the update iteration. Each time a new buffer is acquired, the current data are normalized. An iterative mean and standard deviation are computed according to past data and new ones to normalize each element of $X_u$ and $Y_u$. Covariance matrices $C_u^{XX}$ and $C_u^{XY}$ are then updated from the new normalized data chunk $\{X_u, Y_u\}$ and previous covariance matrices $C_{u-1}^{XX}$ and $C_{u-1}^{XY}$:

$$ \begin{cases} C_u^{XX} = X_u^T X_u + \lambda C_{u-1}^{XX} \\ C_u^{XY} = X_u^T Y_u + \lambda C_{u-1}^{XY} \end{cases} \qquad (2) $$

where $\lambda \in [0,1]$ is a forgetting factor. Then, coefficient of the regression model $B$ and $b$ are updated using new covariance matrices and the kernel algorithm. The current data chunk $\{X_u, Y_u\}$ can be discarded after computing the covariance matrices.
## N-way PLS

The N-way Partial Least Squares (NPLS) [38] extends the PLS to tensor observations. NPLS allows tensors of order higher than one as input and output variables. Note, that vectors are the tensors of the first order, matrices are the tensors of the second order, cubes are the tensors of the third order etc. In BCI, tensor variables of order higher than one are often considered. For example, in [2], the input variable is a tensor of the third order (cube). Let $X \in \mathbb{R}^{N \times I_1 \times \dots \times I_q}$ and $Y \in \mathbb{R}^{N \times J_1 \times \dots \times J_p}$ be the input and output tensors of N observations, respectively. Similar to the PLS, input and output data are normalized using in sample-wise manner. Then, covariance tensors are estimated:

$$ \begin{cases} C^{XX} = X \times_1 X \\ C^{XY} = X \times_1 Y \end{cases} \qquad (3) $$

where $C^{XX} \in \mathbb{R}^{(I_1 \times \dots \times I_q) \times (I_1 \times \dots \times I_q)}$, $C^{XY} \in \mathbb{R}^{(I_1 \times \dots \times I_q) \times (J_1 \times \dots \times J_p)}$ and "$\times_k$" is the k-mode tensor product. The computation of covariance tensors (3) is equivalent to the computation of covariance matrices (1) where tensor X and Y are transformed into matrices using the mode-1 unfolding [39]. Similar to the PLS and the REW-PLS, the regression coefficient may be computed using the kernel algorithm adapted for tensor object.

In the next sections, we keep matrix notations for tensors of any order for simplicity reason and without loss of generality.

## Recursive Exponentially Weighted NPLS

Finally, the REW-NPLS [33] combines the NPLS and the REW-PLS algorithms providing real-time adaptive decoder learning for tensor inputs and outputs.

## Sample-Weighted PLS

In the PLS family algorithms presented above, every samples contribute equally to the learning of the model in offline configuration. In [40], the author propose the Optimized Sample-Weighted PLS (OSW-PLS), an extension of the PLS, where samples are weighted according to the representativeness of each sample. Weight per samples are computed offline and are applied to learn the PLS model.

The data are first normalized using the same procedure as for the PLS algorithm. Then, covariance matrices are computed using the normalized data $\{X, Y\}$ and the weight vector $w \in \mathbb{R}^N$:

$$ \begin{cases} C^{XX} = X^T \text{diag}(w) X \\ C^{XY} = X^T \text{diag}(w) Y \end{cases} \qquad (4) $$

where diag(w) is the diagonal matrix containing the weights of the observations. Then, the coefficient regression are computed.

The authors demonstrated that data weighting in their algorithm is equivalent to resampling of data. For example, a weight equal to 2 for a sample is equivalent to duplicate it in the training database. Weights are not limited to natural integers that make the weighting approach a generalization of the resampling approach.

A second study [41] propose the Weighted PLS (WPLS) with fixed weights to learn a regression model. The choice of weights in [41] is based on prior of population distribution to get a training database the most representative regarding the population. Contrary to OSW-PLS [40] where the training set is normalized without considering weights, the author modify the normalization step to compute the mean and the variance based on the weighted dataset.
## b. Recursive Sample Weighted NPLS

In this study, we propose a new algorithm: the Recursive Sample Weighted NPLS (RSW-NPLS). Firstly, we adapted the WPLS [41] to tensor variables, resulting in the Sample Weighted NPLS (SW-NPLS) algorithm for offline study and comparison. A strategy to compute sample weights from imbalance between each class and the majority class is proposed. Then, in order to handle the class imbalance in real time, we propose online sample weighting procedure integrated to REW-NPLS.

### Sample Weighted NPLS

The Sample Weighted NPLS extends the WPLS to tensor objects. The normalization step of the SW-NPLS is similar to the WPLS, and is presented in appendix A-. Let $X$ and $Y$ the mode-1 unfolding of, respectively, the input and the output tensors, and $w \in \mathbb{R}^N$ be the vector of weights per observation with $N$ the size of the training set. Covariance matrices are computed from the full dataset and the vector of weights $w$ using equation (4). Regression are deduced using the kernel algorithm adapted for the tensor object. Different strategies to determine sample weights may be integrated to sample weighted algorithms depending on the objectives of the study.

### Recursive Sample Weighted NPLS

The Recursive Sample Weighted NPLS (RSW-NPLS) is the online version of the SW-NPLS and the extension of the REW-NPLS to weighted samples. Let $X_u$ and $Y_u$ the mode-1 unfolding of, respectively, the input and the output tensor at update $u$, $w_u \in \mathbb{R}^{n_u}$ be the vector of weights per observation for a given update, and $n_u$ the size of the data chunk. The input and output tensors $X_u$ and $Y_u$ are normalized (as in appendix B-), and covariance matrices are updated using the current data chunk and its associated weight vector:

$$ \begin{cases} C_u^{XX} = X_u^T \text{diag}(w_u) X_u + \lambda C_{u-1}^{XX} \\ C_u^{XY} = X_u^T \text{diag}(w_u) Y_u + \lambda C_{u-1}^{XY} \end{cases}, \quad (5) $$

where $\text{diag}(w_u)$ is the diagonal matrix containing the weights of the observations in the current data chunk.

Figure 2 provides schema of the REW-NPLS and the RSW-NPLS algorithms to illustrate their functioning during one update iteration. In the REW-NPLS, the update data chunk is first normalized, then covariance matrices are computed, and the decoder is updated [33]. In the RSW-NPLS, a step is added to compute the samples weights. Weights are used both for normalization and computation of the covariance matrices. As NPLS is an offline version of REW-NPLS algorithm, SW-NPLS is an offline version of RSW-NPLS algorithm. The difference between online and offline versions is that offline variants use the full training dataset all at once.

Table 1 provides a summary of the different algorithms presented in this section.
<figure><img src="image_3.png" /><figcaption>Figure 2: Structure of the generic REW-NPLS and the proposed RSW-NPLS algorithms. In the RSW-NPLS, an additional step computes vector of weights $w_u$ to apply to each observation of the update data set $\{X_u, Y_u\}$ during the normalization step and the covariance matrices update step. Covariance matrices are computed according to previous covariance matrices, normalized new data and weights. Finally, discriminative parameters $\{B, b\}$ are deduced.</figcaption></figure>

<table><caption>Table 1: Summary table of algorithms.</caption><thead><tr><td>Model names</td><td>Input/output objects</td><td>Online of offline learning?</td><td>Can handle class imbalance?</td></tr></thead><tbody><tr><td>PLS</td><td>Matrices</td><td>Offline</td><td>No</td></tr><tr><td>NPLS</td><td>Tensors</td><td>Offline</td><td>No</td></tr><tr><td>REW-PLS</td><td>Matrices</td><td>Online</td><td>No</td></tr><tr><td>REW-NPLS</td><td>Tensors</td><td>Online</td><td>No</td></tr><tr><td>OSW-PLS</td><td>Matrices</td><td>Offline</td><td>No</td></tr><tr><td>WPLS</td><td>Matrices</td><td>Offline</td><td>Yes</td></tr><tr><td>SW-NPLS</td><td>Tensors</td><td>Offline</td><td>Yes</td></tr><tr><td>RSW-NPLS</td><td>Tensors</td><td>Online</td><td>Yes</td></tr></tbody></table>

### c. Weighting strategies to balance classes

#### Class imbalance characterization

To handle class imbalance during learning, quantifying of level of class imbalanced is critical. Let $N^{(k)}$ be the number of occurrence of class $k$, $N^{(maj)}$ be the number of occurrence of the majority class, $N^{(min)}$ be the number of occurrence of the minority class, and $N$ be the total number of occurrence of all classes. Some criteria to characterize the class imbalance were proposed [15], [42], such as the vector of occurrence (class size): $(N^{(1)}, ..., N^{(K)})^T$.

In this article, to evaluate the algorithms efficiency, we quantify the database imbalance, using the Class Imbalance Ratio (CIR) [42]:

$$CIR = \frac{N^{(maj)}}{N^{(min)}}. \qquad (6)$$
This criterion is equal to 1 if the training set is perfectly balanced with the same number of samples in each class. The greater the imbalance between the majority class and the minority class, the higher the CIR. CIR quantifies the imbalance with a single number, and allows plotting results of performance as a function of the imbalance in the training dataset. However, it provides information between the majority and the minority classes only, which may impede the class balancing.

The vector of ratios of the size of the majority class and the sizes of other classes maybe another criterion to characterize the class imbalance. In this study, we choose these class ratios $CR^{(k)}$ to balance classes during the training

$$CR^{(k)} = \frac{N^{(maj)}}{N^{(k)}}. \qquad (7)$$

In the context of streaming learning, the database size $N$, class sizes $N^{(k)}$, class ratios $CR^{(k)}$ and the CIR are subject to change as the model is updated with a new buffer. Let $N_u$, $N_u^{(k)}$, $CR_u^{(k)}$, and $CIR_u$ be, respectively, the size of the database, the size of class $k$, the class ratio $k$ and the class imbalance ratio, of the database accumulated up to update $u$. Update equations of $N_u$, $N_u^{(k)}$, $CR_u^{(k)}$ and $CIR_u$ are given by:

$$N_u = \lambda N_{u-1} + n_u, \qquad (8)$$

$$N_u^{(k)} = \lambda N_{u-1}^{(k)} + n_u^{(k)}, \qquad (9)$$

$$CR_u^{(k)} = \frac{N_u^{(maj)}}{N_u^{(k)}}, \qquad (10)$$

$$CIR_u = \frac{N_u^{(maj)}}{N_u^{(min)}}, \qquad (11)$$

where $\lambda \in [0,1]$ is the forgetting factor, $n_u$ is the size of the current buffer and $n_u^{(k)}$ the size of class $k$ in the current buffer.

As the data weighting is equivalent to data resampling [40] in the RSW-NPLS and the SW-NPLS, the above notations can be redefined for weighted databases. Let $N^{(w)}$, $N^{(k,w)}$, $CIR^{(w)}$ and $CR^{(k,w)}$ be, respectively, the weighted size of the database, the weighted size of class $k$, the weighted class imbalance ratio and the weighted class ratio $k$, based on the size of classes would result from resampling corresponding to weighting procedure. Equations to compute $N^{(w)}$, $N^{(w)}$, $CIR^{(w)}$ and $CR^{(w)}$ are given by:

$$N^{(w)} = \sum_{i=1}^{N} w_i, \qquad (12)$$

$$N^{(k,w)} = \sum_{i \in i^{(k)}} w_i, \qquad (13)$$

$$CR^{(k,w)} = \frac{N^{(maj,w)}}{N^{(k,w)}}, \qquad (14)$$

$$CIR^{(w)} = \frac{N^{(maj,w)}}{N^{(min,w)}}, \qquad (15)$$

where $w = (w_1, ..., w_N)^T \in \mathbb{R}^N$ is the weight vector per observation and $i^{(k)} \in \mathbb{R}^{N^{(k)}}$ is the set of indices of observations corresponding to the class $k$.
Finally, in the case the weighted database in dynamic learning, let $N_u^{(w)}$, $N_u^{(k,w)}$, $CIR_u^{(w)}$ and $CR_u^{(k,w)}$ be, respectively, the weighted size of the database, the weighted size of class $k$, the weighted class imbalance ratio and be the weighted class ratio $k$, of the database accumulated up to update $u$.

Updated equations of $N_u^{(w)}$, $N_u^{(k,w)}$, $CIR_u^{(w)}$ and $CR_u^{(k,w)}$ are given by:

$$N_u^{(w)} = \lambda N_{u-1} + \sum_{i=1}^{n_u} w_{u,i}, \qquad (16)$$

$$N_u^{(k,w)} = \lambda N_{u-1}^{(k,w)} + \sum_{i \in i_u^{(k)}} w_{u,i}, \qquad (17)$$

$$CR_u^{(k,w)} = \frac{N_u^{(maj,w)}}{N_u^{(k,w)}}, \qquad (18)$$

$$CIR_u^{(w)} = \frac{N_u^{(maj,w)}}{N_u^{(min,w)}}, \qquad (19)$$

where $w_u = (w_{u,1}, ..., w_{u,n_u})^T \in \mathbb{R}^{n_u}$ is the weight vector per observation in the current buffer and $i_u^{(k)} \in \mathbb{R}^{n_u^{(k)}}$ is the set of indices of observation include in class $k$ in the current buffer.

## Class balancing strategies

From our literature review, only the COAKM [31] had been proposed to learn a multi-classification model using weights to balance classes in online manner. Weights are updated online by computing the modified class ratio $\tilde{CR}_u^{(k)}$ for each class $k$, and are used to compute the cost function to update a support vector machine. As mentioned in the introduction, the algorithm does not handle well dynamic changes during only training and database with large dimension.

In the current study, we propose a samples weighting strategy integrated to a PLS type algorithm for classification, especially addressing the problem of multi-class balancing in the online training with high-dimensional data. Weighting strategies had already been applied to PLS algorithms [40], [41]. However, these studies consider other problems (the representativeness of the training database and improvement model performance) and are only adapted to offline studies.

**Offline weight computation for multi-class balancing.** Offline computation is performed in parallel for comparison purposes. As we address the problem of class imbalance only, we propose here to use the same weight for all the samples from the same classe: $w = (w_1, ..., w_N)^T \in \mathbb{R}^N$, $w_i = wc^{(k)}$, for any $i$ corresponding to a sample belonging to class $k \in [1, K]$. In this case, the weight vector per class $wc = (wc^{(1)}, ..., wc^{(K)})^T \in \mathbb{R}^K$ is to be estimated. The weight $wc^{(k)}$ for samples of the class $k$ is proposed to be computed according to the majority class volume:

$$wc^{(k)} = CR^{(k)}, \quad k \in [1, K], \qquad (20)$$

The equation (20) computes weights higher than one for every classes except for the majority class. The weight for the majority class in equal to one. This strategy corresponds to over-sampling data from minority classes to perfectly balance the dataset. This choice of over-sampling over under-sampling was done with the next online use in mind. In online model training, under-sampling would mean favoring old data and the impact of the user's feedback would be neglected.

Equation (20) allows to perfectly balance classes in the training set. However, such a procedure cannot be applied in an online configuration because it requires to know the final imbalance of data, while only present and past samples are known. In addition, once viewed, old data are not kept in the memory.
**Online weight computation for multi-class balancing.** Similarly, in real-time, we propose to use the same weights $wc_u^{(k)}$ for the samples from the same class $k$ for a given update (see Figure 2). However, it varies from one update to another. Let $wc_u = (wc_u^{(1)}, ..., wc_u^{(K)})^T$ be a weight vector per class at update $u$. The update of $wc_u^{(k)}$ and $N_u^{(k,w)}$ is performed according to the following equations:

$$N_u^{(maj,w)} = \max_k (\lambda N_{u-1}^{(k,w)} + n_u^{(k)}), \qquad (21)$$

$$wc_u^{(k)} = \frac{N_u^{(maj,w)} - \lambda N_{u-1}^{(k,w)}}{n_u^{(k)}}, \qquad (22)$$

$$N_u^{(k,w)} = \lambda N_{u-1}^{(k,w)} + wc_u^{(k)} n_u^{(k)}, \quad k \in [1, K]. \qquad (23)$$

First, the size of the majority class $N_u^{(maj,w)}$ in computed in (21), considering $wc_u^{(maj)} = 1$. Equation (22) provides the weight per class $wc_u^{(k)}$ to apply to each sample of the current update to balance each class with the majority class. Finally, the weighted size of classes are updated in (23) for the current data chunk. For class each class $k$, the forgetting factor $\lambda$ is multiplied by the previous size of the class $N_{u-1}^{(k,w)}$. The forgetting factor reduces the size of each class, as the old samples are forgotten as the model is trained. Then, the number of sample of the class $k$ in the current buffer $n_u^{(k)}$ times the weight $wc_u^{(k)}$ is added to get $N_u^{(k,w)}$. To avoid computational issue, $wc_u^{(k)}$ is fixed to 0 if $n_u^{(k)} = 0$.

To avoid large weights that may increase the level of noise or bias the model, we propose to apply a constraint $w_{max}$ to bound the weight of each class $wc_u^{(k)}$. In addition to limiting noise, the constraint prevents overweighing a few samples when there is a large imbalance, ensuring that newly learned states receive moderate weights and preserve the impact of future samples on the model. The RSW-NPLS is tested with different constant $w_{max}$ to study the impact of this parameter.

### d. Integration of RSW-NPLS into the HMM for classification

Similarly to studies in [2], [3], [4], we integrated the proposed RSW-NPLS algorithm to HMM for robust classification. A HMM is a dynamic classifier based on two stochastic processes: the hidden process and the observation process. The dynamic evolution of these two processes is modeled using three probability laws. The emission law models the probability of the current observation given the current state. The transition law provide the probability of the current state giving the previous ones. Finally, the prior law models the frequency of occurrence of a state. HMMs are widely used in many fields of study, like bioinformatics [43], speech recognition [44], etc. HMMs are well-suited for online and incremental learning, making them an effective choice for BCI decoding. In BCI systems, the hidden process corresponds to the mental state of the user performing the corresponding motor imagery (resting, moving a hand, etc.), and the observation process corresponds to his recorded brain signal. Learning a HMM consists in learning the transition law and the emission law. These laws are learned independently. In [2], [3], [4] the REW-NPLS is used to learn the emission probability. In this study, we compare the proposed HMM-RSWNPLS to generic HMM-REWNPLS with using simulations of online learning. Similarly, the offline algorithms NPLS and the SW-NPLS integrated to a HMM, HMM-SWNPLS and HMM-NPLS respectively, are compared. Any extension of the “PLS” integrated to a HMM is noted HMM-“PLS” in the rest of this paper.
## 3- Databases

The proposed algorithms were evaluated using data sets recorded during the “BCI and Tetraplegia” clinical trial (ClinicalTrials.gov, NCT02550522) [2], [3] and the “STIMO-BSI” clinical trial (ClinicalTrials.gov NCT04632290) [4].

The user's neural signals were recorded with a sampling frequency of 586 Hz using WIMAGINE implants [45]. WIMAGINE is an implant designed to record multi-channels ECoG signals. The implants are placed under the cranial cavity, for the electrodes to be in contact with the dura mater. This configuration enables to record signals with better spatial resolution and signal-to-noise ratio than EEG sensors. Following the surgery, implants remain beneath the skin and are not visible from the outside. They communicate with the decoding software via an antenna, with data being transmitted to a custom headset.

During the calibration sessions, an experimenter gives instructions to the user. The BCI user performs a mental task associated to each cue given by the experimenter.

Neural features are extracted from the ECoG signal every 100 ms using the continuous complex wavelet transform (CCWT) with the Morlet mother wavelet with configurable epoch durations (200ms or 1s in this study) and set of frequencies (from 2Hz to 200Hz in study). After computing the CCWT, the absolute values are retained, and a decimation step is applied to reduce the temporal dimensionality [2]. The time-frequency-spatial tensor $X_t \in \mathbb{R}^{T \times F \times C}$ is then used as the input of the decoder where T is the temporal dimension, F is the number of frequencies, and C is the number of channels.

In parallel with the decoding process, the tensors $X_t$ are stored forming a tensor $X_u \in \mathbb{R}^{n_u \times T \times F \times C}$, for the updating procedure. Cues given by the experimenter are considered as the ground truth and are used as labels. Let $Y_t \in \mathbb{R}^K$ be one hot encoding vector indicate the label of $X_t$ where K is the number of classes. The position of the “1” in the vector $Y_t$ gives which state is active at time t. The accumulated labels form the matrix $Y_u \in \mathbb{R}^{T \times K}$. After 15 seconds of neural features and labels accumulation ($n_u$ is fixed to 150 in this application) tensor $X_u \in \mathbb{R}^{150 \times T \times F \times C}$, and matrix $Y_u \in \mathbb{R}^{150 \times K}$ are used to update the decoder.

Finally, the decoder output is sent as a command to drive the effector. The user receives a visual and/or proprioceptive feedback, allowing them to adjust their thoughts in real time.

Figure 3 provides an illustration of a training session with the full signal processing chain.
<figure><img src="image_4.png" /><figcaption>Figure 3: Scheme of experimental sessions. The experimenter provides a sequence of cues and the user has to perform mental tasks associated to the current cues. Neural signals are recorded thanks to WIMAGINE implants. Neural features are computed using the CCWT and a decimation step, and are used into two blocs. The prediction bloc compute the decoder output that will command the effector. And, the updating bloc update the prediction model using the 15 last second of features and cues. Finally, the user receive a feedback from the BCI system to adapt his thought during the experimental session.</figcaption></figure>

Three databases **BCI - Exo5**, **BCI - Exo8**, **BSI - Gait** are used to compare algorithms.

The databases **BCI - Exo5**, and **BCI - Exo8** come from the "BCI and Tetraplegia" clinical trial (ClinicalTrials.gov, NCT02550522) [2], [3] and were recorded with the same patient. The patient has a C4-C5 spinal cord injury. They kept a control of their neck and shoulders, but they have a limited control of their elbows and wrists extensors. The patient was implanted with two WIMAGINE implants in June 2017. The implants are placed in the skull, facing the sensory motor cortex. In this database, input features tensor $X_t$ are CCWT coefficients from 64 channels computed on a one-second sliding window, with a sliding step of 100ms. Fifteen equally spaced frequencies from 10 to 150 Hz are represented, resulting in feature tensor of dimensions $T = 10, F = 15$ and $C = 64$.

### Database: BCI - Exo5

The patient was trained to control 8 degree of freedom of a virtual exoskeleton. Degrees of freedom are: the 3D translation of the hand and the wrist rotation for both arms. The decoder was composed of a five states-classifier ($K = 5$): right hand translation ($AS_{RH}$), left hand translation ($AS_{LH}$), right wrist rotation ($AS_{RW}$), left wrist rotation ($AS_{LW}$) and idle (IS) states. The ECoG signal has been saved into a database. Ten recording sessions, recorded between September and October 2018, of total duration 370 minutes were retained for this study.

### Database: BCI - Exo8

Between January and March 2020, the patient was trained to control a virtual exoskeleton. The patient performed the tasks to control the 3D translation of both hands, wrists rotations, the grasp of each hand, and a binary command to activate or to stop working cycles, resulting in eight different states ($K = 8$): $AS_{RH}$, $AS_{LH}$, $AS_{RW}$, $AS_{LW}$, left grasp ($AS_{LG}$), right grasp ($AS_{RG}$), walk ($AS_{RUN}$) and IS. The ECoG signal has been saved into a database composed of 10 recording sessions of total duration 300 minutes.

### Database: BSI - Gait

This database has been recorded in the context of the "STIMO-BSI" clinical trial [4] (clinicaltrials.gov, NCT04632290). The patient recruited for this clinical protocol is paraplegic; he suffers from an incomplete cervical spinal cord injury (C5/C6). The patient was implanted with two WIMAGINE
implants placed in front of the sensorimotor cortex and with a spinal cord stimulator to activate
muscles of his legs. Between September 2021 and January 2022, the patient was trained to control
both legs. Models were trained to decode three states (K = 3): the left hip (AS<sub>LHp</sub>), the right hip (AS<sub>RHp</sub>)
flexion and the idle (IS). The pulse generator stimulates the spinal cord to perform hip flexions of both
legs, following the decoded user intent.

The database is composed of 10 sessions of total duration 60 minutes. To highlight the impact of class imbalance on model performance, the ten sessions with the largest imbalance were selected. In this database, the input features tensor $X_t$ correspond to the CCWT coefficients from 64 channels over 200ms. CCWT coefficients has been decimated to obtain 2 point on the temporal modality with a sampling frequency of 10 Hz. Frequencies represented in the tensor feature are centered around 2, 5:5:100, 125, 150 and 200 Hz ($T = 2, F = 24$ and $C = 64$).

The databases are characterized by different level of classes' imbalance shown in Figure 4.

<figure><img src="image_5.png" /><figcaption>Figure 4: Ratio per class for each database and sessions. Each subfigure presents the class imbalance of the BCI – Exo5 (A), BCI – Exo8 (B) and BSI – Gait (C) databases. Pie charts give the size of each class (all the 10 recording sessions). Boxplots show the distributions of class ratios each sessions, highlighting that the imbalance also depends on the recording sessions.</figcaption></figure>

4- Evaluation

a. Performance criteria in presence of class imbalance

Most of assessment criteria do not take account of the imbalance between classes, which can lead to
misinterpretation of results. The bias induced by the imbalance makes the model tend to ignore the
minor class. For example, in the case of a binary classification of data with a ratio of 1/100 between
the minority class and the majority classes, a model that ignores the minority class would have a 99%
of accuracy (i.e. the ratio of good predictions by the model). Some criteria, however, like the recall
(sensitivity) or the specificity are not sensitive to class imbalance. These scores are probability
measures providing information per class about the model performance. The geometric mean (G-
mean) of the sensitivity and the specificity is a score mostly used in the literature to evaluate
performances of a model in a context of class imbalance [15], [42], [46]. For the multi-classification
problem, the G-mean can be evaluated by class [47] with the same formula as for the binary
classification, or with a variant for multi-class [46], [48], [49] which corresponding to the geometric mean of recalls:

$$ 
\left\{ 
\begin{aligned}
Rec^{(k)} &= \frac{TP^{(k)}}{TP^{(k)} + FN^{(k)}} \\
G_m &= \left( \prod_{k=1}^{K} Rec^{(k)} \right)^{1/K}
\end{aligned}
\right. 
\qquad (24) 
$$

with K the number of classes, TP(k) the number of true positive of the class k, FN(k) the number of false negative of the class k, Rec(k) the recall of the class k, and G_m the G-mean of recalls. The G-mean is equal to one only if the model perfectly classify all the samples. If one class is ignored by the model (the classifier never predict the class), then the G-mean is equal to zero. The drawback of this score is that G-mean is equal to zero if at least one class is not predicted, however, there is no information about performance for other classes. At the same time, the G-mean allows to detect the worst databases. In this study, the G-mean for multi-class is retained to evaluate the performance of models with regard to class imbalance.

To control the effectiveness of the proposed algorithms, the chance level was evaluated for each database by random permutation of the expected outputs preserving the class distribution. This process was repeated 100 times across all 252 testing datasets, with the G_m calculated for each iteration. The average of these G_m values was then taken as the chance level.

## b. Offline and Pseudo-online tests

Firstly, the offline variants of the algorithms, the generic HMM-NPLS and class balancing HMM-SWNPLS, were compared. Offline training refers to a training procedure where the full training database is available, it is then possible to balance the classes perfectly, with the same weight for samples from the same class.

A pseudo-online procedure was used to compare the online variants of the algorithms. During pseudo-online learning, models are trained simulating the online configuration. Data are presented by 15 seconds long chunks, which are then discarded for the next update iteration. Pseudo-online learning differs from online learning by not incorporating the user feedback in the brain signal. However, it allows to test algorithms before an integration into the clinical BCI decoding platform to get first results. Pseudo-online testing is a good compromise, as clinical trials are very expensive and time consuming. Also, pseudo-online testing allows to compare algorithms using exactly the same data. This is not possible during online testing.

To compare the different training algorithms (offline and pseudo-online), we consider the ten recording sessions of databases presented in section 3-. Five out of ten recording sessions were selected to train the model and the rest was used to test the model. This experiment was repeated for all the five out of ten combinations (252).
<figure><img src="image_6.png" /><figcaption>Figure 5: Dynamic evolution of weighted class sizes, and weighted CIR. An example from the BCI – Exo5 database. The figure (A) provides results for the HMM-REWNPLS, the figure (B) provides results for the HMM-RSWNPLS ($w_{max}$ = 2), and the figure (C) provides results for the HMM-RSWNPLS ($w_{max}$ = 10). In each sub figure, the top plot represents the dynamic evolution of $N_u^{(k,w)}$, while the bottom plot is the evolution of the $CIR_u^{(w)}$.</figcaption></figure>

<figure><img src="image_7.png" /><figcaption>Figure 6: Dynamic evolution of weighted class sizes, and weighted CIR. An example from the BCI – Exo8 database. See Figure 5 for explanations.</figcaption></figure>
<figure><img src="image_8.png" /><figcaption>Figure 7: Dynamic evolution of weighted class sizes, and weighted CIR. An example from the BSI-Gait database. See Figure 5 for explanations.</figcaption></figure>

<figure><img src="image_9.png" /><figcaption>Figure 8: Boxplots of CIR at the end of the calibration. $CIR_{end}^{(w)}$ refers to the weighted class imbalance ratio at the end of the calibration. For each database, results are given for the HMM-REWNPLS, the HMM-RSWNPLS ($w_{max}$ = 2) and the RSWNPLS ($w_{max}$ = 10).</figcaption></figure>

# 5- Results

## a. Dynamic evolution of class imbalance ratio

Figures Figure 5 to Figure 7 give examples of the evolution in time of $N_u^{(k,w)}$ and $CIR_u^{(w)}$ for each database. Each subfigures (A), (B) and (C) represents a different algorithm: the HMM-REWNPLS, the HMM-RSWNPLS ($w_{max}$ = 2) and the HMM-RSWNPLS ($w_{max}$ = 10). Figure 8 provides the distribution of $CIR_u^{(w)}$ at the end of the training for the three databases.

In examples presented in figures 5-6, the IS is the majority state for databases **BCI – Exo5** and **BCI – Exo8**. In **BCI – Exo5**, the IS is almost twice as represented as the minority class (AS<sub>LW</sub>). The HMM-RSWNPLS algorithm improves balance between classes depending on constraint $w_{max}$. For $w_{max}$ = 2, only the hand translation states (AS<sub>LH</sub> and AS<sub>RH</sub>) were balanced with the IS. Wrist rotation states
(AS<sub>LW</sub> and AS<sub>RW</sub>) remained minority. $w_{max}$ = 10 allows the algorithm to balance all the classes with a CIR close to one at the end of the calibration. In **BCI-Exo8**, the IS represents 40% of the dataset at the end of the training of the HMM-REWNPLS. The HMM-RSWNPLS improves the class balance without perfectly balancing them. With $w_{max}$ = 2, the idle remains the majority state with a ratio equal to 26% while minority classes (AS<sub>LG</sub> and AS<sub>RG</sub>) get a ratio equal to 5%. With $w_{max}$ = 10, class ratios are bounded between 9% to 15%.

In the examples from **BSI-Gait** (Figure 7), the IS is the minority state. At the end of the learning with the HMM-REWNPLS, the ratio of the IS tends to 10% while ratios of left and right hip tend to 45%. With the HMM-RSWNPLS ($w_{max}$ = 2), the ratio of the IS is doubled at the end of the calibration. Finally, the IS becomes balanced with the two other states with the HMM-RSWNPLS ($w_{max}$ = 10) algorithm.

These three examples show the HMM-RSWNPLS succeed to rebalance classes. The constraint $w_{max}$ has a significant impact on the final balance.

Distributions of $CIR_{end}^{(w)}$ (at the end of the calibration) presented in Figure 8 for all tests with the HMM-REWNPLS and HMM-RSWNPLS ($w_{max}$ = 2 and $w_{max}$ = 10) show the HMM-RSWNPLS reduces the class imbalance. Median values of $CIR_{end}^{(w)}$ for the HMM-REWNPLS are equal to 2.29, 8.65 and 2.69 for, respectively, the databases **BCI-Exo5**, **BCI-Exo8** and **BSI-Gait**. The HMM-RSWNPLS also allows to reduce the variance of $CIR_{end}^{(w)}$. The median absolute deviation of $CIR_{end}^{(w)}$ decreases from the HMM-REWNPLS to the HMM-RSWNPLS ($w_{max}$ = 10) by 83% to 97%.

## b. Comparison of performances

Figures 9 to Figure 11 give classification performances for each databases. Prediction results from offline calibration with the HMM-NPLS and the HMM-SWNPLS in function of the CIR of the training set are given in subfigures (A). Boxplots of prediction results from offline and pseudo-online calibrations are provided in sub-figures (B). The HMM-RSWNPLS is tested with a constraint $w_{max}$ from 2 to 10 and with no limitation (noted $w_{max}$ = $\infty$).

Offline performances of the HMM-NPLS in function of the CIR shows the higher the CIR, the lower the $G_m$. In the database **BCI-Exo5**, the model performance shows a sharp decrease as the CIR increases. $G_m$ is always lower than the chance level for a CIR higher than 3.5, and maybe null for some tests. A brief analysis of null performances reveals that the recall of the minority class is 0, indicating that the minority class was completely ignored by the model. In the database **BCI-Exo8**, classes are extremely imbalanced with a CIR between 6 and 23. Results with the HMM-NPLS algorithm are low with a $G_m$ < 0.5. The score decreases as the CIR increases, and in about the half of the tests, it reaches a null value. The performances in database **BSI-Gait** also decline as the CIR increases, but the decrease is less pronounced. $G_m$ is lower than the chance level in only 4 cases.

In all databases, the HMM-SWNPLS succeeds to obtain a performance higher than the chance level contrary to the NPLS for which results with high CIR are often lower than the chance level. Using the HMM-SWNPLS allows to compensate the effect of class imbalance, and succeeds to maintain a consistent level of performance even in case of large imbalance in databases **BCI-Exo5** and **BCI-Exo8** ($G_m \in [0.65 \ 0.9]$ in **BCI-Exo5** and $G_m \in [0.55 \ 0.75]$ in **BCI-Exo8**). For **BSI-Gait**, the HMM-SWNPLS did not succeed to maintain performances in the same range. However, the decrease of performance for the HMM-SWNPLS is lower than the decrease of performance with the HMM-NPLS. According to Figures 9-11 (B), the HMM-SWNPLS outperforms the HMM-NPLS in term of median $G_m$ for all databases.
Pseudo-online results show that the HMM-RSWNPLS improves results in comparison of the HMM-REWNPLS for all databases and for all constraints $w_{max}$. In all databases, increasing the constraint tends to improve the global performance of the model and there is at least one constraint for which the HMM-RSWNPLS provides results higher than the chance level for all tests. By increasing the constraint, the distribution of $G_m$ obtained with the HMM-RSWNPLS tends to the distribution of $G_m$ with the HMM-SWNPLS. For databases **BCI-Exo5** and **BCI-Exo8**, applying no constraint ($w_{max} = \infty$) degrades the performance of the decoder.

From the HMM-REWNPLS to the HMM-RSWNPLS ($w_{max} = 10$), the mean $G_m$ criterion increases by 68%, 825% and 18% for, respectively, the **BCI-Exo5**, the **BCI-Exo8** and the **BSI-Gait** databases. The standard deviation of $G_m$ decreases by 74% and 50% for, respectively, the **BCI-Exo5** and the **BSI-Gait** databases. For the **BCI-Exo8** database, about half of $G_m$ are null, which tends to decrease the standard deviation.
<figure><img src="image_10.png" /></figure>

<figure><img src="image_11.png" /></figure>

Figure 9: Comparison of results for the BCI – Exo5 database. In (A), results from offline training are compared using the HMM-NPLS in blue and the HMM-SWNPLS in red. The Y-axis corresponds to the geometric mean of recall and the X-axis gives the CIR of the training set (before balancing). Results of the HMM-NPLS and the HMM-SWNPLS for the same database are vertically aligned. In (B), boxplots of geometric means are given per algorithm. The two first algorithms are offline to compare them with the pseudo-online versions. The dashed line highlights the separation between offline and pseudo-online methods. The third column is the HMM-REWNPLS algorithm. Then, results from HMM-RSWNPLS are given for different values of the maximum over-sampling weight. The last column presents results of the HMM-RSWNPLS without any constraint on the weight computation.

<figure><img src="image_12.png" /></figure>

<figure><img src="image_13.png" /></figure>

Figure 10: Comparison of results for the BCI – Exo8 database. See Figure 9 for description.

<figure><img src="image_14.png" /></figure>

<figure><img src="image_15.png" /></figure>

Figure 11: Comparison of results for the BSI – Gait database. See Figure 9 for description.
# 6- Discussion

The databases recorded during BCI experimental sessions are imbalanced due to several reasons. Some tasks are more difficult to perform and take longer to learn and carry out. During the calibration of the BCI system, the experimenter chose to ask the idle state more frequently than active states to minimize user fatigue. Consequently, the idle state tends to the majority state in many database.

Class imbalance has an important impact on the classification performance. In our study we observed strong effect of class imbalance in the training database on the decoder performance in all test databases, even if decoding performance (G-mean) degradation depending on CIR varies for different databases. Generally, it is approaching chance level for CIR above 3-4. During online or pseudo-online learning, the class imbalance is subject to change over time: a new task can be added to the model, or, for example, a state may be majority at some point and become minority later in the training. Also, the model is updated buffer by buffer and past data are discarded after being used to update the model. The full database and its class imbalance is then not available while training the model. A mechanism to compensate the class imbalance and able to adapt to change in class imbalance in real time is required.

In this paper, the RSW-NPLS algorithm is proposed to counterbalance the effect of class imbalance during the online closed loop training of a BCI system. In this algorithm, the class imbalance is quantified at each update and weights to balance classes are computed for each sample. The main advantage of the RSW-NPLS is that it does not require to resample data or to learn multiple models in parallel. This makes this algorithm adapted for streaming and incremental learning with a limited memory storage and computational resources. Integrated to the HMM, the RSW-NPLS can be used for robust multi-class classification problem.

Weighting samples to balance classes during the calibration of the BCI system improves its classification performance. In the case where classes were already well balanced, the proposed algorithms do not degrade the model performance in comparison with the current algorithm. Both offline HMM-SWNPLS and online HMM-RSWNPLS algorithms succeed to counter-balance the effect of class imbalance and provide more stable results, decreasing the performance standard deviation. To improve the robustness of the model, a constraint is applied to the calculation of the weights to avoid overweighting the samples during training. The results presented in this study show that the presence of an upper bound on weights improves performance of models in comparison with no constraint applied.

The HMM-RSWNPLS was tested with two patients in three different database. Data were recorded from the same patient in database with five and eight classes (BCI – Exo5 & Exo8). For these databases, the improvements brought by the HMM-RSWNPLS are particularly marked. The BSI – Gait database was recorded from another patient in a database with three classes. For this database the improvement is less pronounced. This difference may probably be explained by better class separability with clear lateralization of classes in the data base BSI – Gait compared to BCI – Exo5 & Exo8 databases. Performance decreases slightly as the imbalance between classes increases.

Neural data sets BCI – Exo5 & Exo8 and BSI – Gait were recorded from different patients. This may contribute to variation in algorithm's performance. The results of BCI vary essentially from one user to another [50], [51]. Finally, the user's feedback is different giving the database. This can lead to changes in user behavior, reaction times etc.
This paper presents a proof of concept with promising results, albeit with certain limitations. Tests were conducted in offline and pseudo-online configurations with only two patients and few database. Clinical validation of this algorithm, online tests with more patients and more databases are required.

In this study, only one approach to compute weights to compensate class imbalance has been tested, other strategies of weight computation can be explored.

## Acknowledgments

Authors thank members of the brain computer interface project of the LETI/DTIS/SRBN/LCCDM, in particular Guillaume Charvet and Fabien Sauter-Starace for the project management, Thomas Costecalde and Serpil Karakas for collecting and providing the clinical datasets of the BCI and Tetraplegia project.

Authors thank Grégoire Courtine, Jocelyne Bloch, Henri Lorach and the Defitech Center for Interventional Neurotherapies (.NeuroRestore) for collecting and providing the STIMO-BSI clinical dataset.

This work has been supported by the European Commission (EIC 2021-TransitionChallenges01-01 ReverseParalysis 101057450), Fonds Clinatec (BCI4GRASP) and Institut Carnot Leti.
## References

[1] K. J. Miller, D. Hermes, and N. P. Staff, "The current state of electrocorticography-based brain-computer interfaces," *Neurosurgical Focus*, vol. 49, no. 1, p. E2, Jul. 2020, doi: 10.3171/2020.4.FOCUS20185.

[2] A. Moly et al., "An adaptive closed-loop ECoG decoder for long-term and stable bimanual control of an exoskeleton by a tetraplegic," *J. Neural Eng.*, vol. 19, no. 2, Art. no. 2, Mar. 2022, doi: 10.1088/1741-2552/ac59a0.

[3] A. L. Benabid et al., "An exoskeleton controlled by an epidural wireless brain-machine interface in a tetraplegic patient: a proof-of-concept demonstration," *The Lancet Neurology*, vol. 18, no. 12, Art. no. 12, Dec. 2019, doi: 10.1016/S1474-4422(19)30321-7.

[4] H. Lorach et al., "Walking naturally after spinal cord injury using a brain-spine interface," *Nature*, vol. 618, no. 7963, Art. no. 7963, Jun. 2023, doi: 10.1038/s41586-023-06094-5.

[5] M.-C. Schaeffer and T. Aksenova, "Data-Driven Transducer Design and Identification for Internally-Paced Motor Brain Computer Interfaces: A Review," *Front Neurosci*, vol. 12, p. 540, 2018, doi: 10.3389/fnins.2018.00540.

[6] G. Hotson et al., "Individual finger control of a modular prosthetic limb using high-density electrocorticography in a human subject," *Journal of Neural Engineering*, vol. 13, no. 2, 2016, doi: 10.1088/1741-2560/13/2/026017.

[7] M. S. Fifer et al., "Simultaneous neural control of simple reaching and grasping with the modular prosthetic limb using intracranial EEG," *IEEE Trans Neural Syst Rehabil Eng*, vol. 22, no. 3, pp. 695-705, May 2014, doi: 10.1109/TNSRE.2013.2286955.

[8] S. Chiappa and S. Bengio, "HMM and IOHMM modeling of EEG rhythms for asynchronous BCI systems," Jan. 2003.

[9] B. A. S. Hasan and J. Q. Gan, "Temporal modeling of EEG during self-paced hand movement and its application in onset detection," *J Neural Eng*, vol. 8, no. 5, p. 056015, Oct. 2011, doi: 10.1088/1741-2560/8/5/056015.

[10] Z. Wang, A. Gunduz, P. Brunner, A. L. Ritaccio, Q. Ji, and G. Schalk, "Decoding onset and direction of movements using Electrocorticographic (ECoG) signals in humans," *Front Neuroeng*, vol. 5, p. 15, 2012, doi: 10.3389/fneng.2012.00015.

[11] E. Haselsteiner and G. Pfurtscheller, "Using time-dependent neural networks for EEG classification," *IEEE Transactions on Rehabilitation Engineering*, vol. 8, no. 4, pp. 457-463, Dec. 2000, doi: 10.1109/86.895948.

[12] R. Souriau et al., "Hierarchical Hidden Markov Model for Online Decoding in Brain-Computer Interface," in *2024 32nd European Signal Processing Conference (EUSIPCO)*, Lyon, France: IEEE, Aug. 2024, pp. 1466-1470. doi: 10.23919/EUSIPCO63174.2024.10715255.

[13] M. D. Murphy, D. J. Guggenmos, D. T. Bundy, and R. J. Nudo, "Current Challenges Facing the Translation of Brain Computer Interfaces from Preclinical Trials to Use in Human Patients," *Front Cell Neurosci*, vol. 9, p. 497, 2015, doi: 10.3389/fncel.2015.00497.

[14] J. J. Williams, A. G. Rouse, S. Thongpang, J. C. Williams, and D. W. Moran, "Differentiating closed-loop cortical intention from rest: building an asynchronous electrocorticographic BCI," *J Neural Eng*, vol. 10, no. 4, p. 046001, Aug. 2013, doi: 10.1088/1741-2560/10/4/046001.

[15] S. Wang, L. L. Minku, and X. Yao, "A Systematic Study of Online Class Imbalance Learning With Concept Drift," *IEEE Transactions on Neural Networks and Learning Systems*, vol. 29, no. 10, pp. 4802-4821, Oct. 2018, doi: 10.1109/TNNLS.2017.2771290.

[16] X. Chen, D. Lei, and G. Xu, "Prediction of icing fault of wind turbine blades based on deep learning," in *Proc. IEEE Int. Conf. Autom., Electron. Electr. Eng.*, AUTEEE, Institute of Electrical and Electronics Engineers Inc., 2019, pp. 295-299. doi: 10.1109/AUTEEE48671.2019.9033143.

[17] P. Zhao, S. Hoi, and ACM, "Cost-Sensitive Online Active Learning with Application to Malicious URL Detection," in *Nanyang Technological University*, 2013, pp. 919-927.
[18] M. Minot, S. Reddy, and I. Bahar, "Nucleotide augmentation for machine learning-guided protein engineering," BIOINFORMATICS ADVANCES, vol. 3, no. 1, Jan. 2023, doi: 10.1093/bioadv/vbac094.

[19] M. R. Sousa, J. Gama, and E. Brandão, "A new dynamic modeling framework for credit risk assessment," Expert Systems with Applications, vol. 45, pp. 341–351, Mar. 2016, doi: 10.1016/j.eswa.2015.09.055.

[20] N. V. Chawla, K. W. Bowyer, L. O. Hall, and W. P. Kegelmeyer, "SMOTE: Synthetic Minority Over-sampling Technique," jair, vol. 16, pp. 321–357, Jun. 2002, doi: 10.1613/jair.953.

[21] H. Han, W.-Y. Wang, and B.-H. Mao, "Borderline-SMOTE: A New Over-Sampling Method in Imbalanced Data Sets Learning," in Advances in Intelligent Computing, D.-S. Huang, X.-P. Zhang, and G.-B. Huang, Eds., Berlin, Heidelberg: Springer, 2005, pp. 878–887. doi: 10.1007/11538059_91.

[22] H. He, Y. Bai, E. A. Garcia, and S. Li, "ADASYN: Adaptive synthetic sampling approach for imbalanced learning," in 2008 IEEE International Joint Conference on Neural Networks (IEEE World Congress on Computational Intelligence), Jun. 2008, pp. 1322–1328. doi: 10.1109/IJCNN.2008.4633969.

[23] A. Bernardo, H. Gomes, J. Montiel, B. Pfahringer, A. Bifet, and E. Della Valle, "C-SMOTE: Continuous Synthetic Minority Over-sampling for Evolving Data Streams," in Polytechnic University of Milan, X. Wu, C. Jermaine, L. Xiong, X. Hu, O. Kotevska, S. Lu, W. Xu, S. Aluru, C. Zhai, E. Al-Masri, Z. Chen, and J. Saltz, Eds., 2020, pp. 483–492. doi: 10.1109/BigData50022.2020.9377768.

[24] A. Bernardo and E. Della Valle, "VFC-SMOTE: very fast continuous synthetic minority over-sampling for evolving data streams," DATA MINING AND KNOWLEDGE DISCOVERY, vol. 35, no. 6, pp. 2679–2713, Nov. 2021, doi: 10.1007/s10618-021-00786-0.

[25] L. Zhang, C. Li, R. Zhang, and Q. Sun, "Online semi-supervised learning for motor imagery EEG classification," COMPUTERS IN BIOLOGY AND MEDICINE, vol. 165, Oct. 2023, doi: 10.1016/j.compbiomed.2023.107405.

[26] B. Mirza, Z. Lin, and K.-A. Toh, "Weighted Online Sequential Extreme Learning Machine for Class Imbalance Learning," Neural Process Lett, vol. 38, no. 3, pp. 465–486, Dec. 2013, doi: 10.1007/s11063-013-9286-9.

[27] S. Wang, L. L. Minku, and X. Yao, "Dealing with multiple classes in online class imbalance learning," in IJCAI Int. Joint Conf. Artif. Intell., Kambhampati S., Ed., International Joint Conferences on Artificial Intelligence, 2016, pp. 2118–2124. [Online]. Available: https://www.scopus.com/inward/record.uri?eid=2-s2.0-85006136656&partnerID=40&md5=5f11e83b5f4024c90fe02c71a5462c75

[28] D. Sahoo, P. Zhao, and S. C. H. Hoi, "Cost-sensitive online multiple kernel classification," in J. Mach. Learn. Res., Durrant R.J. and Kim K.-E., Eds., Microtome Publishing, 2016, pp. 65–80. [Online]. Available: https://www.scopus.com/inward/record.uri?eid=2-s2.0-85070957716&partnerID=40&md5=055c7890b3c67a3d9b2850b2c3b16e29

[29] Z. Chen, V. Sheng, A. Edwards, and K. Zhang, "Cost-sensitive sparse group online learning for imbalanced data streams," Mach Learn, 2023, doi: 10.1007/s10994-023-06403-z.

[30] J. Wang, P. Zhao, and S. C. H. Hoi, "Cost-Sensitive Online Classification," IEEE Transactions on Knowledge and Data Engineering, vol. 26, no. 10, pp. 2425–2438, Oct. 2014, doi: 10.1109/TKDE.2013.157.

[31] Y. Chen, Z. Hong, and X. Yang, "Cost-Sensitive Online Adaptive Kernel Learning for Large-Scale Imbalanced Classification," IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING, vol. 35, no. 10, pp. 10554–10568, Oct. 2023, doi: 10.1109/TKDE.2023.3266648.

[32] M. Krell, N. Wilshusen, A. Seeland, and S. Kim, "Classifier transfer with data selection strategies for online support vector machine classification with class imbalance," JOURNAL OF NEURAL ENGINEERING, vol. 14, no. 2, Apr. 2017, doi: 10.1088/1741-2552/aa5166.
[33] A. Eliseyev et al., "Recursive Exponentially Weighted N-way Partial Least Squares Regression with Recursive-Validation of Hyper-Parameters in Brain-Computer Interface Applications," *Sci Rep*, vol. 7, no. 1, Art. no. 1, Nov. 2017, doi: 10.1038/s41598-017-16579-9.

[34] A.-L. Boulesteix, "PLS dimension reduction for classification with microarray data," *Stat Appl Genet Mol Biol*, vol. 3, p. Article33, 2004, doi: 10.2202/1544-6115.1075.

[35] P. Geladi and B. R. Kowalski, "Partial least-squares regression: a tutorial," *Analytica Chimica Acta*, vol. 185, pp. 1-17, Jan. 1986, doi: 10.1016/0003-2670(86)80028-9.

[36] Bhupinder. S. Dayal and J. F. MacGregor, "Improved PLS algorithms," *Journal of Chemometrics*, vol. 11, no. 1, pp. 73-85, 1997, doi: 10.1002/(SICI)1099-128X(199701)11:1<73::AID-CEM435>3.0.CO;2-#.

[37] B. S. Dayal and J. F. MacGregor, "Recursive exponentially weighted PLS and its applications to adaptive control and prediction," *Journal of Process Control*, vol. 7, no. 3, pp. 169-179, 1997, doi: 10.1016/S0959-1524(97)80001-7.

[38] R. Bro, "Multiway calibration. Multilinear PLS," *Journal of Chemometrics*, vol. 10, no. 1, pp. 47-61, 1996, doi: 10.1002/(SICI)1099-128X(199601)10:1<47::AID-CEM400>3.0.CO;2-C.

[39] T. G. Kolda and B. W. Bader, "Tensor Decompositions and Applications," *SIAM Rev.*, vol. 51, no. 3, pp. 455-500, Aug. 2009, doi: 10.1137/07070111X.

[40] L. Xu et al., "Optimized sample-weighted partial least squares," *Talanta*, vol. 71, no. 2, pp. 561-566, Feb. 2007, doi: 10.1016/j.talanta.2006.04.039.

[41] J.-M. Becker and I. R. Ismail, "Accounting for sampling weights in PLS path modeling: Simulations and empirical examples," *European Management Journal*, vol. 34, no. 6, pp. 606-617, Dec. 2016, doi: 10.1016/j.emj.2016.06.009.

[42] A. Luque, A. Carrasco, A. Martín, and A. de las Heras, "The impact of class imbalance in classification performance metrics based on the binary confusion matrix," *Pattern Recognition*, vol. 91, pp. 216-231, Jul. 2019, doi: 10.1016/j.patcog.2019.02.023.

[43] R. Durbin, S. R. Eddy, A. Krogh, and G. Mitchison, *Biological Sequence Analysis: Probabilistic Models of Proteins and Nucleic Acids*. Cambridge University Press, 1998.

[44] L. R. Rabiner, "A tutorial on hidden Markov models and selected applications in speech recognition," *Proceedings of the IEEE*, vol. 77, no. 2, pp. 257-286, Feb. 1989, doi: 10.1109/5.18626.

[45] C. S. Mestais, G. Charvet, F. Sauter-Starace, M. Foerster, D. Ratel, and A. L. Benabid, "WIMAGINE: Wireless 64-Channel ECOG Recording Implant for Long Term Clinical Applications," *IEEE Transactions on Neural Systems and Rehabilitation Engineering*, vol. 23, no. 1, pp. 10-21, Jan. 2015, doi: 10.1109/TNSRE.2014.2333541.

[46] S. Wang, L. L. Minku, and X. Yao, "Resampling-Based Ensemble Methods for Online Class Imbalance Learning," *IEEE Transactions on Knowledge and Data Engineering*, vol. 27, no. 5, pp. 1356-1368, May 2015, doi: 10.1109/TKDE.2014.2345380.

[47] Y. Lu, Y.-M. Cheung, and Y. Yan Tang, "Adaptive chunk-based dynamic weighted majority for imbalanced data streams with concept drift," *IEEE Trans. Neural Networks Learn. Sys.*, vol. 31, no. 8, pp. 2764-2778, 2020, doi: 10.1109/TNNLS.2019.2951814.

[48] W. Liu, C. Zhu, Z. Ding, H. Zhang, and Q. Liu, "Multiclass imbalanced and concept drift network traffic classification framework based on online active learning," *Eng Appl Artif Intell*, vol. 117, 2023, doi: 10.1016/j.engappai.2022.105607.

[49] A. Li, M. Han, D. Mu, Z. Gao, and S. Liu, "Online active learning method for multi-class imbalanced data stream," *Knowl. Inf. Systems. Syst.*, 2023, doi: 10.1007/s10115-023-02027-w.

[50] M. C. Thompson, "Critiquing the Concept of BCI Illiteracy," *Sci Eng Ethics*, vol. 25, no. 4, pp. 1217-1233, Aug. 2019, doi: 10.1007/s11948-018-0061-1.

[51] B. Z. Allison and C. Neuper, "Could Anyone Use a BCI?," in *Brain-Computer Interfaces: Applying our Minds to Human-Computer Interaction*, D. S. Tan and A. Nijholt, Eds., London: Springer, 2010, pp. 35-54. doi: 10.1007/978-1-84996-272-8_3.
# Appendices

## A- Normalization of data in the SW-NPLS

Let $X = (x_{t,i_1,...,i_q}) \in \mathbb{R}^{N \times I_1 \times \dots \times I_q}$ and $Y = (y_{t,i_1,...,i_p}) \in \mathbb{R}^{N \times J_1 \times \dots \times J_p}$ be the input tensor and the output tensor where $L$ is the size of the training set. Algorithm 1 presents the element-wise normalization of $X_t$ in the SW-NPLS, given the sample weight vector $w \in \mathbb{R}^N$. For $Y_t$ the procedure is identical.

### Algorithm 1: Element-wise normalization in SW-NPLS

- Notation:

- $i = (i_1, ..., i_q)$: element index in sample tensor.

- $SS^i \in \mathbb{R}^N$: sum squared of samples for element $i$ taking into account class balancing.

- $w = (w_1, ..., w_N) \in \mathbb{R}^N$: weights vector.

- $\mu^i$: updated mean for element $i$ taking into account class balancing.

- $\sigma^i$: updated standard deviation for element $i$ taking into account class balancing.

- Inputs:

- $w$.

- Steps:

- Update database size:

$$N^{(w)} = \sum_{l=1}^{N} w_l$$

- Update means:

$$\mu^i = \frac{1}{N_u^{(w)}} \sum_{l=1}^{N} w_l x_{t,i}$$

- Update sum squared:

$$SS^i = \sum_{l=1}^{N} w_l x_{t,i}^2$$

- Update standard deviation:

$$\sigma^i = \sqrt{\frac{SS_u^i - N^{(w)}(\mu^i)^2}{N^{(w)} - 1}}$$

- Sample normalization:

$$\tilde{x}_{t,i} = \frac{x_{t,i} - \mu^i}{\sigma^i}, \quad l \in [1, \tau]$$

Note that this algorithm generalizes the normalization procedure of the NPLS and the PLS algorithms where all weights are equal to 1, and, for the PLS, where $X$ and $Y$ are matrices.
## B- Normalization of data in the RSW-NPLS

During the online calibration, tensor $X_u$ and $Y_u$, at update $u$, are normalized using dynamic mean and dynamic standard deviation updated according to the new data chunk. The normalization of $X_u$ is the same as the normalization of $Y_u$.

Update tensors contain samples of update $u$: $X_u = (x_{t,i_1,...,i_q}) \in \mathbb{R}^{n_u \times I_1 \times \dots \times I_q}$ composed by samples $X_t \in \mathbb{R}^{I_1 \times \dots \times I_q}$, and $Y_u = (y_{t,i_1,...,i_p}) \in \mathbb{R}^{n_u \times J_1 \times \dots \times J_p}$ composed by samples $Y_t \in \mathbb{R}^{J_1 \times \dots \times J_p}$. Algorithm 2 presents the element-wise normalization of $X_t$ in the RSW-NPLS given the sample weight vector $w_u \in \mathbb{R}^{n_u}$. For $Y_t$ the procedure is identical.

### Algorithm 2: Element-wise normalization in RSW-NPLS

- Notation:

- $i = (i_1, ..., i_q)$: element index in sample tensor.

- $SS_u^i \in \mathbb{R}^{n_u}$: cumulative sum squared of samples from update $u$ for element $i$ taking into account class balancing.

- $w_u = (w_{u,1}, ..., w_{u,\tau_u}) \in \mathbb{R}^{n_u}$: weights vector.

- $\mu_u^i$: updated mean for element $i$ taking into account class balancing.

- $\sigma_u^i$: updated standard deviation for element $i$ taking into account class balancing.

- $\lambda$: forgetting factor.

- Step $u$:

Inputs:

- $N_{u-1}^{(w)}$. Initialization: $N_0^{(w)} = 0$.

- $\mu_{u-1}^i$. Initialization: $\mu_0^i = 0$.

- $SS_{u-1}^i$. Initialization: $SS_0^i = 0$.

- $w_u$.

- Steps:

- Update database size:

$$N_u^{(w)} = \lambda N_{u-1}^{(w)} + \sum_{l=1}^{n_u} w_{u,l}$$

- Update means:

$$\mu_u^i = \frac{1}{N_u^{(w)}} \left( \lambda N_{u-1}^{(w)} \mu_{u-1}^i + \sum_{l=1}^{n_u} w_{u,l} x_{t_{l,i}} \right)$$

- Update sum squared:

$$SS_u^i = \lambda SS_{u-1}^i + \sum_{l=1}^{n_u} w_{u,l} x_{t_{l,i}}^2$$

- Update standard deviation:

$$\sigma_u^i = \sqrt{\frac{SS_u^i - N_u^{(w)} (\mu_u^i)^2}{N_u^{(w)} - 1}}$$

- Sample normalization:

$$\tilde{x}_{t_{l,i}} = \frac{x_{t_{l,i}} - \mu_u^i}{\sigma_u^i}, \quad l \in [1, n_u]$$