# Analysis and Improvement of Fireworks Algorithm
## 2 Fireworks Algorithm  
In FWA, the explosion amplitude of each fireworks and the number of sparks produced by the explosion are calculated based on its relative fireworks fitness values in the fireworks population. Assume that the number of fireworks is N and the number of dimensions is \(d\), then the explosion amplitude \(A_{i}\) (Equation (1)) and the number of explosion sparks \(S_{i}\) (Equation (2)) for each firework \(X_{i}\) are calculated as follows. \[A_{i}=A\times\frac{f(X_{i})-y_{\min}+\varepsilon}{\sum\limits_{i=1}^{N}{(f(X_{i })-y_{\min})+\varepsilon}} \tag{1}\]  
\[S_{i}=m\times\frac{y_{\max}-f(X_{i})+\varepsilon}{\sum\limits_{i=1}^{N}{(y_{ \max}-f(X_{i}))+\varepsilon}} \tag{2}\]  
where \(y_{\max}=\max(f(X_{i}))\), \(y_{\min}=\min(f(X_{i}))\), \(A\) and \(m\) are two constants to control the explosion amplitude and the number of explosion sparks, and \(\varepsilon\) is the machine epsilon to avoid \(A_{i}\) or \(S_{i}\) is equal to 0. In order to limit the good fireworks do not produce too many explosive sparks, while the poor fireworks do not produce too few sparks, its scope \(S_{i}\) is defined as. \[S_{i}=\left\{ \begin{array}{ll}round(a\times m),&S_{i}<a\times m\\ round(b\times m),&S_{i}>b\times m\\ round(S_{i}),&otherwise\end{array} \right. \tag{3}\]  
where \(a\) and \(b\) are fixed constant parameters that confine the range of the population size. Based on \(A_{i}\) and \(S_{i}\), the explosion operator is performed (confer Algorithm 1). For each of the \(Si\) explosion sparks of each firework \(X_{i}\), Algorithm 1 is performed once. In Algorithm 1, the operator % refers to the modulo operation, and \(X_{min}^{k}\) and \(X_{max}^{k}\) refer to the lower and upper bounds of the search space in dimension \(k\). In order to increase the diversity of the population, the fireworks algorithm introduced mutation operator used to generate mutation sparks, namely Gaussian mutation sparks. Gaussian mutation of the spark produced as follows: First of all in the fireworks population randomly select a fireworks \(X_{i}\), and then the fireworks randomly select a certain number of dimensions for Gaussian mutation operation. Algorithm 2 shows this process, it is performed \(N_{g}\) times, each time with a randomly selected firework \(X_{i}\) (\(N_{g}\) is a constant to control the number of Gaussian sparks). ```
Initialize the location of the explosion sparks: \(X_{j}=X_{i}\)  Calculate offset displacement: g = Gaussian(1,1)  Set \(z=\text{rand}(1,d)\)  For \(k=1\):\(d\) do  If \(k\)\(\in\)\(z\) then \(X_{j}^{k}=X_{j}^{k}\times g\)  If \(X_{j}^{k}\) out of bounds \(X_{j}^{k}=X_{min}^{k}+1\)\(X_{j}^{k}\)\(\%\)\((X_{max}^{k}-X_{min}^{k})\)  End if  End if End for
```  
**Algorithm 2**Generating Gaussian Sparks  
In order to transmit the excellent information in the fireworks population to the next generation population, the algorithm chooses a certain number of individuals (including fireworks, explosion sparks and Gaussian sparks) as the next generation fireworks. In FWA, the current best location is always kept for the next iterations. In order to keep the diversity, the remaining \(N-1\) locations are selected based on the method of roulette. For location \(X_{i}\), the selection probability \(\text{p}_{\text{i}}\) is calculated as follows:  
\[p(X_{i})=\frac{R(X_{i})}{\sum\limits_{j\in K}R(X_{j})} \tag{4}\]  
\[R(X_{i})=\sum\limits_{j\in K}d(X_{i},X_{j})=\sum\limits_{j\in K}\big{|}|X_{i}- X_{j}|\big{|} \tag{5}\]  
where \(K\) is the set of all current locations including original fireworks and both types of sparks (without the best location). As a result, fireworks or sparks in low crowded regions will have a higher probability to be selected for the next iteration than fireworks or sparks in crowded regions. Algorithm 3 summarizes the framework of FWA. Based on Algorithms 1 and 2, explosion sparks and Gaussian sparks are produced, respectively. For explosion sparks, the number of sparks and the amplitude of the explosion depend on the fitness value of the fireworks.