# An Overview of Variants and Advancements of PSO Algorithm
## 2 Concept of Particle Swarm Optimization (PSO) Technique
### Working Example of PSO  
The PSO algorithm can be more understandable with a working example with some iterations. The example is illustrated as below:  
Example: min f(x) = x\({}_{1}^{2}\ +\ x_{2}^{2}\ +\ x_{3}^{2}\ +\ x_{4}^{2}\) 0 \(\leq\) x\({}_{i}\ \leq\) 10 i = 1,2,3,4 Solution: Parameter setting of PSO algorithm  
Population Size (N\({}_{\mathrm{P}}\)) = 5, Inertia Weight (w) = 0.7, Acceleration Coefficient = c\({}_{1}\ =\ \mathrm{c_{2}}\ =\ 1.5\), Maximum iteration = 10 Iteration! : Generate random positions and velocities within domain 0 \(\leq\) x\({}_{i}\ \leq\) 10 and evaluate fitness of positions i.e.,  
\[X(position)= \begin{bmatrix}4&0&0&8\\ 3&1&9&7\\ 0&3&1&5\\ 2&1&4&9\\ 6&2&8&3\end{bmatrix} f(X)(fitness function)= \begin{bmatrix}80\\ 140\\ 35\\ 102\\ 113\end{bmatrix} v(velocity) \begin{bmatrix}9&6&1&8\\ 5&1&3&0\\ 7&4&1&4\\ 3&0&2&1\\ 1&6&8&7\end{bmatrix} \]Here fitness value of velocity is not required, fitness value of only positions is required:  
\[\mathrm{P}_{\mathrm{best}}^{(1)}\;=\; \begin{bmatrix}4&0&0&8\\ 3&1&9&7\\ 0&3&1&5\\ 2&1&4&9\\ 6&2&8&3\end{bmatrix} \qquad\qquad\qquad\qquad\mathrm{f}_{\mathrm{Pbest}}\;=\; \begin{bmatrix}80\\ 140\\ 35\\ 102\\ 113\end{bmatrix} \]  
In the first iteration as we do not have any historical information, so current position is considered as best direction i.e., \(\mathrm{P}_{\mathrm{best}}\;=\;X\). Now, \(\mathrm{g}_{\mathrm{best}}\;=\; \begin{bmatrix}0&3&1&5\end{bmatrix} \qquad \mathrm{f}_{\mathrm{g}_{\mathrm{best}}}\;=\;35\)  
So, in iteration 1, we get:  
\[V= \begin{bmatrix}9&6&1&8\\ 5&1&3&0\\ 7&4&1&4\\ 3&0&2&1\\ 1&6&8&7\end{bmatrix}\begin{matrix}\mathrm{v}_{1}^{(1)}\\ \mathrm{v}_{2}^{(1)}\\ \mathrm{v}_{3}^{(1)}\\ \mathrm{v}_{4}^{(1)}\\ \mathrm{v}_{5}^{(1)}\end{matrix} \;=\; \begin{bmatrix}4&0&0&8\\ 3&1&9&7\\ 0&3&1&5\\ 2&1&4&9\\ 6&2&8&3\end{bmatrix}\begin{matrix}\mathrm{X}_{1}^{(1)}\\ \mathrm{X}_{2}^{(1)}\\ \mathrm{v}_{3}^{(1)}\\ \mathrm{v}_{4}^{(1)}\end{matrix} \]  
\[\mathrm{P}_{\mathrm{best}}^{1}\;=\; \begin{bmatrix}4&0&0&8\\ 3&1&9&7\\ 0&3&1&5\\ 2&1&4&9\\ 6&2&8&3\end{bmatrix}\begin{matrix}\mathrm{P}_{\mathrm{best},\;1}^{(1)}\\ \mathrm{P}_{\mathrm{best},\;2}^{(1)}\\ \mathrm{P}_{\mathrm{best},\;3}^{(1)}\\ \mathrm{P}_{\mathrm{best},\;4}^{(1)}\\ \mathrm{P}_{\mathrm{best},\;4}^{(1)}\\ \mathrm{P}_{\mathrm{best},\;5}^{(1)}\end{matrix} \qquad\qquad\qquad\mathrm{f }_{\mathrm{Pbest}}\;=\; \begin{bmatrix}80\\ 140\\ 35\\ 102\\ 113\end{bmatrix} \]  
\[\mathrm{g}_{\mathrm{best}}\;=\; \begin{bmatrix}0&3&1&5\end{bmatrix} \qquad \qquad\qquad\mathrm{f}_{\mathrm{g}_{\mathrm{best}}}\;=\;35\]  
Iteration 2 (First solution):  
To calculate \(\mathrm{v}_{1}^{(2)}\), \(\mathrm{X}_{1}^{(2)}\). Let \(\mathrm{r}_{1}\;=\; \begin{bmatrix}0.4&0.3&0.9&0.5\end{bmatrix} \) and \(\mathrm{r}_{2}\;=\; \begin{bmatrix}0.8&0.2&0.7&0.4\end{bmatrix} \)  
\[\mathrm{v}_{1}^{(2)}\;=\;\mathrm{w}_{1}^{(1)}\;+\;\mathrm{c}_{1}\mathrm{r}_{1 }\;(\mathrm{p}_{\mathrm{best},\;1}^{(1)}\;-\;\mathrm{X}_{1}^{(1)})\;+\;\mathrm{ c}_{2}\mathrm{r}_{2}\;(\mathrm{g}_{\mathrm{best}}\;-\;\mathrm{X}_{1}^{(1)})\]  
\[\mathrm{X}_{1}^{(2)}\;=\;\mathrm{X}_{1}^{(1)}\;+\;\mathrm{v}_{1}^{(2)}\]  
\[\mathrm{X}_{1}^{(2)}\;=\;\mathrm{X}_{1}^{(1)}\;+\;\mathrm{v}_{1}^{(2)}\]  
\[\;=\; \begin{bmatrix}4&0&0&8\end{bmatrix} \;+\; \begin{bmatrix}1.5&5.1&1.75&3.8 \end{bmatrix} \]  
\[\;=\; \begin{bmatrix}5.5&5.1&1.75&11.8\end{bmatrix} \
otin[0,10]\]  
This is the new position of first particle in the second iteration but new position is not within the bounds. So, by using corner bounding strategy  
\[\mathrm{X}_{1}^{(2)}\;=\; \begin{bmatrix}5.5&5.1&1.75&10\end{bmatrix} \in[0,10]\]  
\[\mathrm{f}(\mathrm{X}_{1}^{(2)})\;=\;159.32\]  
No updation in \(\mathrm{p}_{\mathrm{best}}\) as \(\mathrm{f}_{\mathrm{P}_{\mathrm{best}}^{(2)}}^{(1)}\;=\;159.32\;>\;\mathrm{f}_{ \mathrm{best},\;1}^{(1)}\;=\;80\) and  
No updation in \(\mathrm{g}_{\mathrm{best}}\;\cdot\;\cdot\;\delta_{\mathrm{best}}= \begin{bmatrix} 0&3&1&5\end{bmatrix}