**5. Tuning neural network controller using particle swarm optimization**

An alternative technique is proposed, in this section, to optimize the neural network controller by implementing Particle Swarm Optimization algorithm. This algorithm works like animal behavior on finding foods and avoiding danger, where they will coordinate with each other to find the best position to settle. Likewise, PSO is directed by the movement of the best individual from the population, known as the social compound, and their own experience, known as the cognitive compound. The algorithm moves the set of solutions to find the best solution among them.

#### **5.1 Mathematical formulation**

*Ec* <sup>¼</sup> <sup>1</sup> 2 X *N*

where *r k*ð Þ is the desired output. So Δ*vji* comes

� � � � *<sup>T</sup>*

0 ð Þ *h*<sup>1</sup> *w*1*jS*<sup>0</sup>

Δ*v*1*<sup>j</sup>* ¼ �*η<sup>c</sup>*

<sup>¼</sup> *<sup>∂</sup>*ð Þ *y k*ð Þ� *r k*ð Þ *∂hc*<sup>1</sup>

Δ*v*1*<sup>j</sup>* ¼ �*η<sup>c</sup>*

Δ*vji* ¼ *ηcλcec*ð Þ*k s*

ð Þ¼ *Vx*<sup>1</sup> *diag s*<sup>0</sup> *h <sup>j</sup>*

*<sup>∂</sup>ec*ð Þ*<sup>k</sup> ∂hc*<sup>1</sup>

*<sup>∂</sup>y k*ð Þ

*∂Ec <sup>∂</sup>ec*ð Þ*<sup>k</sup>*

*<sup>∂</sup><sup>u</sup>* <sup>¼</sup> *<sup>∂</sup>yr k*ð Þ

*<sup>∂</sup>ec*ð Þ*<sup>k</sup> <sup>∂</sup>y k*ð Þ

the obtained incremental change Δ*v*1*<sup>j</sup>* is rewritten as

Δ*v*1*<sup>j</sup>* ¼ *ηcλcec*ð Þ*k s*

*<sup>∂</sup>yr k*ð Þ *∂h*<sup>1</sup>

> 0 ð Þ *h*<sup>1</sup> *w*1*jS*<sup>0</sup>

0

where Δ*v*1*<sup>j</sup>* is given by

and the Eq. (31) becomes

from where approximately

Δ*v*1*<sup>j</sup>* ¼ �*η<sup>c</sup>*

derivative of sigmoid function *s*

given by the following equation

*Deep Learning Applications*

with *S*<sup>0</sup>

So

which gives

**12**

*k*¼1

ð Þ *ec*ð Þ*<sup>k</sup>* <sup>2</sup> <sup>¼</sup> <sup>1</sup>

, *j* ¼ 1, … , *n*4. The output synaptic weights of the neural network controller are updated as

> *∂Ec ∂v*1*<sup>j</sup>*

> > *∂Ec ∂ec*

*y k*ð Þ under the condition that the neural model is equal to the system behavior

*<sup>∂</sup><sup>u</sup>* <sup>¼</sup> *<sup>∂</sup>yr k*ð Þ *∂h*<sup>1</sup>

> *∂h*<sup>1</sup> *∂s h <sup>j</sup>* � �

In this section, we used a fixed learning rate, *η*ð Þ*k* (respectively *ηc*ð Þ*k* ), and a

ð Þ¼ *h*<sup>1</sup> *s h*ð Þ<sup>1</sup> ð Þ 1 � *s h*ð Þ<sup>1</sup> .

*<sup>∂</sup>y k*ð Þ *∂u*

or in Eq. (33), *y k*ð Þ does not depend on *h*1, for this reason we use *yr k*ð Þ instead of

*<sup>∂</sup>u k*ð Þ *∂hc*<sup>1</sup>

*∂h*<sup>1</sup> *∂s h <sup>j</sup>* � �

*∂s h <sup>j</sup>* � � *∂h <sup>j</sup>*

ð Þ *Wx wjis*

¼ �*η<sup>c</sup>*

*∂Ec ∂ec*

<sup>¼</sup> *<sup>∂</sup>y k*ð Þ *∂hc*<sup>1</sup>

*∂ec ∂hc*<sup>1</sup>

2 X *N*

where *N* is the number of observations and *ec*ð Þ*k* is the tracking error which is

*k*¼1

ð Þ *Wx wjis*

0 ð Þ *hc*<sup>1</sup> *v*1*jS*<sup>0</sup>

*v*1*<sup>j</sup>*ð Þ¼ *k* þ 1 *v*1*<sup>j</sup>*ð Þþ *k* Δ *v*1*<sup>j</sup>*ð Þ*k* (30)

*∂hc*<sup>1</sup> *∂v*1*<sup>j</sup>*

<sup>¼</sup> *<sup>∂</sup>y k*ð Þ *<sup>∂</sup>u k*ð Þ

> *∂hc*<sup>1</sup> *∂v*1*<sup>j</sup>*

*∂s h <sup>j</sup>* � � *∂h <sup>j</sup>*

*∂h <sup>j</sup> <sup>∂</sup>u k*ð Þ

0

*∂h <sup>j</sup> ∂u*

*<sup>∂</sup>u k*ð Þ *∂hc*<sup>1</sup>

*∂hc*<sup>1</sup> *∂v*1*<sup>j</sup>*

ð Þ *hc*<sup>1</sup> *S Vx* ð Þ<sup>1</sup> (36)

*<sup>∂</sup>u k*ð Þ *∂hc*<sup>1</sup>

ð Þ *y k*ð Þ� *r k*ð Þ <sup>2</sup> (27)

ð Þ *Vx*<sup>1</sup> *xT*

<sup>1</sup> (29)

(31)

(32)

(33)

(34)

(35)

*ec*ð Þ¼ *k y k*ð Þ� *r k*ð Þ (28)

In this study, the Particle Swarm Optimization Feedforward Neural Network (PSO NN) is applied to a multi-layered perceptron where the position of each particle, in a swarm, represents the set of synaptic weights of the neural network for the current iteration. The dimensionality of each particle is the number of synaptic weights.

Let us consider a search space of dimension *D*. A particle *i* of the swarm is modeled by a position vector

$$\mathbf{x}\_{\text{ij}} = \begin{bmatrix} \mathbf{x}\_{i1}, & \mathbf{x}\_{i2}, & \dots, \mathbf{x}\_{iD} \end{bmatrix}^{T} \tag{37}$$

and a velocity vector denoted

$$\boldsymbol{v}\_{i\boldsymbol{j}} = \begin{bmatrix} v\_{i1}, & v\_{i2}, & \dots, v\_{iD} \end{bmatrix}^{T} \tag{38}$$

There is no concept of backpropagation in PSO NN where the direct neural network produces the learning error, objective function of each particle, based on the set of synaptic weights and biases, the positions of the particles. Each particle moves in the weighting space trying to minimize the learning error and keeps in memory the best position through which it passed, denoted

$$\text{Pbest}\_{\text{ij}} = \begin{bmatrix} pbest\_{i1}, \ pbest\_{i2}, \ \dots, pbest\_{iD} \end{bmatrix}^T \tag{39}$$

whereas the best position reached by the swarm is denoted

$$\mathbf{Gbest}\_{i\circ} = \begin{bmatrix} \mathbf{gbest}\_{i1}, \ \mathbf{gbest}\_{i2}, \ \dots, \mathbf{gbest}\_{iD} \end{bmatrix}^T \tag{40}$$

Changing the position means updating the synaptic weights of the neural network controller to generate the proper control law by reducing tracking error.

In each iteration *k*, the particles update their position by calculating the new velocity and move to the new position. At the iteration ð Þ *k* þ 1 , the velocity vector is calculated as follows:

$$w\_{\vec{\eta}}(k+1) = wv\_{\vec{\eta}}(k) + c\_1r\_1\left[pbest\_{\vec{\eta}}(k) - \boldsymbol{\varkappa}\_{\vec{\eta}}(k)\right] + c\_2r\_2\left[gbest\_{\vec{\eta}}(k) - \boldsymbol{\varkappa}\_{\vec{\eta}}(k)\right] \tag{41}$$

where:

*w* being a variable parameter making it possible to control the changing of the particle at the next iteration,

*wvij* is a physical changing component,

$$\begin{aligned} &c\_1r\_1\left[\textit{pbest}\_{\vec{\eta}}(k)-\textit{x}\_{\vec{\eta}}(k)\right] \text{ is a conjugate changing component},\\ &c\_2r\_2\left[\textit{gbest}\_{\vec{\eta}}(k)-\textit{x}\_{\vec{\eta}}(k)\right] \text{ a social component of changing,}\end{aligned}$$

*c*<sup>1</sup> and social *c*<sup>2</sup> are respectively, two cognitive confidence coefficients and social which are present the degree of attraction towards the best position of a particle and that of these informants,

*r*<sup>1</sup> and *r*<sup>2</sup> are two random numbers drawn uniformly in the interval 0, 1 ½ � represent the proper exploration of particles in the search space.

The smallest learning error of each particle *Pbesti* and the smallest learning error found in the whole learning process *Gbesti* are applied to produce a fit of the positions towards the best solution or the targeted tracking error.

The position, at the iteration ð Þ *k* þ 1 , of particle *i* is then defined as follows:

$$\varkappa\_{i\bar{j}}(k+1) = \varkappa\_{i\bar{j}}(k) + v\_{i\bar{j}}(k) \tag{42}$$

• Random initialization of the positions and velocity of the *N* particles in the

*Tuning Artificial Neural Network Controller Using Particle Swarm Optimization Technique…*

• Calculation of the control law *ui*ð Þ*k* from the controller input vector *xc*ð Þ*k* ,

• **If** the current positions of particle *i* produce the best objective function in its

• **If** the objective function of particle i is the best overall objective function

• Evaluation of the positions of particles in the research space,

• Moving of particles according to Eqs. (41) and (42),

• Update *Pbesti* and *Gbesti* according to Eqs. (43) and (44),

In this section, we have proposed the PSO optimization steps of an indirect neural network adaptive controller. The corresponding algorithm will be applied for

In this section, a time-varying nonlinear discrete systems is used which is

*y k*ð Þ¼ <sup>þ</sup> <sup>1</sup> *y k*ð Þ*y k*ð Þ � <sup>1</sup> *y k*ð Þ � <sup>2</sup> *u k*ð Þ � <sup>1</sup> ð Þþ *y k*ð Þ� � <sup>2</sup> <sup>1</sup> *u k*ð Þ

*<sup>a</sup>*0ð Þþ *<sup>k</sup> <sup>a</sup>*1ð Þ*<sup>k</sup> <sup>y</sup>*<sup>2</sup>ð Þþ *<sup>k</sup>* � <sup>1</sup> *<sup>a</sup>*2ð Þ*<sup>k</sup> <sup>y</sup>*<sup>2</sup>ð Þ *<sup>k</sup>* � <sup>2</sup> (46)

described by the input–output model in the following Equation [21].

ð Þ *k* þ 1 ,

swarm,

• Repeat,

• **For** k: 1..N **Do**,

history **Then**,

,

,

• Evaluation of particle positions,

• **Until** reaching the stop criterion,

discrete SISO nonlinear systems.

**6. Results and discussion**

• *Pbesti eci*

**Then**,

• End If,

• End If,

• End For,

• End of PSO.

**15**

• *Gbesti eci*

• **For** all particles i **Do**,

*DOI: http://dx.doi.org/10.5772/intechopen.96424*

• Calculation of the outputs of the system *yi*

Once the change in positions has taken place, an update affects both *Pbesti* and *Gbesti* vectors. At the iteration ð Þ *k* þ 1 , these two vectors will be updated according to the following two formulations:

$$Pbest\_i(k+1) = \begin{cases} Pbest\_i(k) & \text{if } & f(\boldsymbol{\chi}\_i(k)) \ge f(Pbest\_i(k)) \\ \boldsymbol{\chi}\_i(k) & \text{else} \end{cases} \tag{43}$$

and

$$Gbest\_i(k+1) = Arg \min\_i \left[ Pbest\_i(k+1) \right] \tag{44}$$

The algorithm is executed as long as one of the three, or all at the same time, of the following convergence criteria is verified:


$$|f\left(gbest\_{jk}(k)\right) - f\left(gbest\_{jk}(k-a)\right)| \le \varepsilon, \quad with \ a \in [1, N] \tag{45}$$

The parameter *ε* represents a tolerance chosen, most often, of the order of 10�<sup>5</sup> and *N* is a number of iterations chosen of the order of 10.

#### **5.2 The proposed algorithm of particle swarm optimization**

In this section, a summary of the proposed algorithm of the PSO neural network controller is presented.

*Tuning Artificial Neural Network Controller Using Particle Swarm Optimization Technique… DOI: http://dx.doi.org/10.5772/intechopen.96424*


*vij*ð Þ¼ *k* þ 1 *wvij*ð Þþ *k c*1*r*<sup>1</sup> *pbestij*ð Þ� *k xij*ð Þ*k*

*wvij* is a physical changing component,

where:

particle at the next iteration,

*Deep Learning Applications*

*c*1*r*<sup>1</sup> *pbestij*ð Þ� *k xij*ð Þ*k* h i

*c*2*r*<sup>2</sup> *gbestij*ð Þ� *k xij*ð Þ*k* h i

that of these informants,

to the following two formulations:

and

*Pbesti*ð Þ¼ *k* þ 1

the following convergence criteria is verified:

∣*f gbestjk*ð Þ*k* � �

controller is presented.

**14**

• the variation in particle speed is close to zero,

and *N* is a number of iterations chosen of the order of 10.

**5.2 The proposed algorithm of particle swarm optimization**

h i

*w* being a variable parameter making it possible to control the changing of the

is a cognitive changing component,

a social component of changing, *c*<sup>1</sup> and social *c*<sup>2</sup> are respectively, two cognitive confidence coefficients and social which are present the degree of attraction towards the best position of a particle and

The smallest learning error of each particle *Pbesti* and the smallest learning error

*xij*ð Þ¼ *k* þ 1 *xij*ð Þþ *k vij*ð Þ*k* (42)

*<sup>i</sup>* ½ � *Pbesti*ð Þ *<sup>k</sup>* <sup>þ</sup> <sup>1</sup> (44)

∣ ≤*ε*, *with α*∈ ½ � 1, *N* (45)

*Pbesti*ð Þ*k if f x*ð Þ *<sup>i</sup>*ð Þ*k* ≥*f Pbest* ð Þ *<sup>i</sup>*ð Þ*k*

*r*<sup>1</sup> and *r*<sup>2</sup> are two random numbers drawn uniformly in the interval 0, 1 ½ �

found in the whole learning process *Gbesti* are applied to produce a fit of the

*xi*ð Þ*k else*

*Gbesti*ð Þ¼ *k* þ 1 *Arg* min

• the maximum number of iterations defined has not been reached,

� *f gbestjk*ð Þ *k* � *α* � �

The position, at the iteration ð Þ *k* þ 1 , of particle *i* is then defined as follows:

Once the change in positions has taken place, an update affects both *Pbesti* and *Gbesti* vectors. At the iteration ð Þ *k* þ 1 , these two vectors will be updated according

The algorithm is executed as long as one of the three, or all at the same time, of

• the value of the objective is satisfactory, with respect to the following relation:

The parameter *ε* represents a tolerance chosen, most often, of the order of 10�<sup>5</sup>

In this section, a summary of the proposed algorithm of the PSO neural network

represent the proper exploration of particles in the search space.

positions towards the best solution or the targeted tracking error.

�

þ *c*2*r*<sup>2</sup> *gbestij*ð Þ� *k xij*ð Þ*k* h i

(41)

(43)


In this section, we have proposed the PSO optimization steps of an indirect neural network adaptive controller. The corresponding algorithm will be applied for discrete SISO nonlinear systems.
