# A Gradient-Based Particle-Bat Algorithm for Stochastic Configuration Network
## 3 G-Bapso-Scn
### Solve the Optimization Problem Based on the G-BAPSO Algorithm
#### 3.2.2 G-BAPSO Algorithm  
The G-BAPSO algorithm introduces the local search mechanism and adaptive individual elimination strategy of the BAT algorithm under the framework of PSO. When the pulse frequency is low and the current individual fitness is less than the average fitness, Formula (16) is used to update the local individual position. Otherwise, individual velocity is updated by combining gradient information in the process of global search. With the guidance of gradient direction, the search speed is accelerated; the search mechanism of the bat-PSO algorithm could fully explore the solution space and help to jump out of the local minimum.  
The combination of the two could improve the search efficiency. The global update formula is shown in Formulas (26)-(28), where grad represents the gradient and \(c_{3}\) is a learning factor. The specific description of the G-BAPSO algorithm is shown in Algorithm 1, and the flow chart is presented in Figure 2.  
\[v_{t+1}=v_{t}+c_{1}rand_{1}(pb_{t}-p_{t})+c_{2}rand_{2}(gb_{t}-p_{t})+c_{3} grad \tag{26}\]  
\[p_{t+1}=p_{t}+v_{t+1} \tag{27}\]  
\[grad=[\frac{\partial\phi}{\partial w_{L,1}},\frac{\partial\phi}{\partial w_{L,2 }},...,\frac{\partial\phi}{\partial w_{L,d}},\frac{\partial\phi}{\partial b_{ L}}] \tag{28}\]where grad represents the gradient and \(c_{3}\) is the learning factor.  
Figure 2: The flow chart of G-BAPSO.  
```
1:Parameters initialization: \(c_{1}\), \(c_{2}\), \(c_{3}\), maxgen, popsize, popmin, popmax, initial pulse frequencies \(rp\), pulse frequency enhancement coefficient \(\sigma\) ;
2:Initialize the population position (w and b) and the velocity \(v\);
3:Calculate the fitness by (21), record the individual optimal position of the primary particle;
4:if the optimum fitness satisfies the inequality (20) then
5: record the global best position;
6:else
7: Adjust the value of \(r\) and continue to judge until inequality (20) is satisfied;
8:endif
9:for\(i=1\to maxgen\)do
10:for\(j=1\to sizeof\)do
11:if\(r_{j}<rand\) and \(fitness_{j}<mean(fitness)\)then
12: Update individual location according to (16);
13:else
14: Calculate the gradient according to (22)-(25), update individual speed according to (26), and then update individual position according to (27);
15:endif
16: Updating individual fitness values and pulse frequencies;
17:endfor
18:for\(k=1\to sizeof\)do
19:if\(fitness_{k}>fitnessbest(i)\)then
20: Update individual optimal position;
21:endif
22:if\(fitness_{k}>fitnesszek(i)\)then
23: Update optimal location of the group;
24:endif
25:endfor
26:endfor
27:returnzbest
```  
**Algorithm 1** The G-BAPSO algorithm  
Set \(L_{max}\) as the maximum number of hidden layer nodes. Under the G-BAPSO algorithm, the optimized configuration algorithm of SCN, called 'G-BAPSO-SC', is shown in Algorithm 2.  
```
1:Initialize network parameters \(e_{0}=[t_{1},t_{2},...,t_{N}]^{T},0<r<1\);
2:whiledo\(L\leq L_{max}\)
3: Calculate \(w_{L}\) and \(b_{L}\) by G-BAPSO;
4: Calculate \(W_{L,q}=(e_{L-1,q}^{T}h_{L}^{*})/(h_{L}^{*T}h_{L}^{*})\),
5:\(q=1,2,...,m\);
6:\(W_{L}=[W_{L,1},W_{L,2},...,W_{L,m}]^{T}\);
7: Calculate \(e_{L}=e_{L-1}-W_{L}h_{L}^{*}\);
8: Update \(e_{0}:=e_{L};L=L+1\);
9:endwhile
10:return\(W_{1},W_{2},...,W_{L}\),
11:\(w^{*}=[w_{1}^{*},w_{2}^{*},...,w_{L}^{*}]\),
12:\(b^{*}=[b_{1}^{*},b_{2}^{*},...,b_{L}^{*}]\).
```  
**Algorithm 2** The G-BAPSO-SC algorithm