# EEG Channel Selection for Stroke Patient Rehabilitation Using BAT Optimizer
## 3 BAT Algorithm
### Procedure of BAT  
This section presents the general optimization procedure of the BAT algorithm. This optimization procedure contains six main steps, which are presented in Figure 2 and thoroughly discussed below:  
* Step 1: BAT algorithm parameter initialization. In this step, the BAT parameters are initialized with initial values. These parameters are the number of microbats  
Figure 1: Bat movement toward prey.  
Figure 2: Bat algorithm flowchart.  
(solutions) (\(N\)), maximum number of iterations (\(Max_{It}\)), max (\(f_{max}\)) and min (\(f_{min}\)) frequency range, velocity vector (\(v\)), loudness rate (\(A\)), pulse rate (\(r\)), initial pulse rate (\(r^{0}\)), two parameters (\(\lambda\) and \(\alpha\)) with constant values in the range [0, 1], and bandwidth range (\(\epsilon\)) in the range [\(-\)1, 1].
* Step 2: BAT population memory initialization. The BAT solutions are randomly generated in this step using Equation (1), considering the BAT algorithm and particular optimization problem parameters and constraints. \[x_{i}^{j}=lb_{i}+(ub_{i}-lb_{i})\times R,\] (1) where \(\forall i=1,2,\ldots,d\), \(\forall j=1,2,\ldots,N\), and \(R\) is a random number between 0 and 1. The produced solutions together generate the population, as shown in Equation (2), and are stored in the BAT memory (BM) in ascending order on the basis of their fitness values. The best solution with the fittest values is assigned to \(x^{Gbest}\) and stored in the first position of the BM. \[BM=\begin{bmatrix}x_{1}^{1}&x_{2}^{1}&\cdots&x_{d}^{1}\\ x_{1}^{2}&x_{2}^{2}&\cdots&x_{d}^{2}\\ \vdots&\vdots&\ldots&\vdots\\ x_{1}^{N}&x_{2}^{N}&\cdots&x_{d}^{N}\end{bmatrix},\] (2)
* Step 3: Bat population intensification. Now, all microbats \(x\) fly and change their position considering a velocity \(v\) defined by a frequency \(f\) that is generated randomly, as shown in Equations (3) and (4). Accordingly, the bat positions are updated using Equation (5). \[f_{i}=f_{min}+(f_{min}-f_{max})\times R,\] (3) \[v_{i}^{\prime j}=v_{i}^{j}+(x_{i}^{j}-x^{Gbest})\times f_{i},\] (4) \[x_{i}^{\prime j}=x_{i}^{j}+v_{i}^{\prime j},\] (5) It is notable that the microbats update their locations to be closer to the global best (\(x^{Gbest}\)). Thus, the new position of the microbats intensifies the position in a direction toward \(x^{Gbest}\).
* Step 4: Bat population diversification. In this step, the microbats' positions are updated based on random parameters to attempt to find better global solutions. A new solution is selected from the BM based on a selection method and assigned to \(x^{Gbest}\). Subsequently, the current solution is updated using \(x^{Gbest}\) as follows: \[x_{i}^{\prime j}=x^{Gbest}+\epsilon\times A_{j}^{\prime},\] (6) where \(A^{\prime}\) is the loudness average. As Steps 3 and 4 are contradictory steps, the BAT algorithm chooses one of them at a time for execution. This selection is based on the following equation: \[x^{\prime j}=\begin{cases}x^{Gbest}+\epsilon\times A_{j}^{\prime}&\text{ if }r_{j}\leq R\\ x^{j}+v^{\prime j}&\text{ otherwise}\end{cases},\] (7)
* Step 5: BM update. The position of the microbats in the BM will be updated in this step if the new location is fitter than the old one and \(R\leq A_{j}\). Moreover, \(x^{Gbest}\) will be updated if the new BM contains a solution with a better fitness value. Subsequently, \(r_{j}\) and \(A_{j}\) values will be updated in accordance with Equations (8) and (9).  
\[r_{j}=r_{j}^{0}(1-e^{(-\gamma\times ittr)}), \tag{8}\]  
\[A_{j}=\alpha\times A_{j}, \tag{9}\]  
where \(itr\) denotes the current iteration number.
* Step 6: Stop criterion. Steps 3, 4, and 5 will be repeated until the algorithm reaches the stop criterion.