## 2 The Procedures of Forecasting Strategy
### Hybrid Firefly and Particle Swarm Optimization (HFPSO)
#### 2.5.3 Proposed Hybridization of HFPSO  
The efficiency of the ANFIS model is largely dependent on the proper choice of the premise or consequent parameters. It is highly important to select the ideal values for both types of parameters to ensure an accurate output representation of the ANFIS model. Previously, premise parameters were estimated according to the gradient descent algorithm. In this work, the premise parameters of the ANFIS model are optimized by a hybrid algorithm that combines the FF and PSO algorithms.  
The FF algorithm is advantageous in dealing with non-linear and multi-model optimization problems [37]. Nonetheless, the FF algorithm encounters a problem of getting trapped in the local minima [38]. On the other hand, the PSO algorithm is well known due to its simplicity and ease of the implementation mechanism in the optimization area [39]. However, the PSO has the demerit of premature convergence, which makes it difficult to obtain a better solution [40].  
Despite all the advantages offered by the FF and PSO algorithms, they also have some shortcomings that need to be alleviated. Thus, one of the ways to minimize this problem is to hybridize these two algorithms. In this work, the FF and PSO algorithms are combined to prevent the premature convergence of every algorithm, avoid trapping at local optima, and to balance the exploitation process and exploration process [38]. In Figure 6, the flowchart of the proposed HFPSO algorithm which is used by this work is shown.  
The detailed explanation of the procedures in the flowchart is explained as follows:  
**Step 1**: Initially, all of the input parameters used in the FF and PSO algorithm are defined.  
_[Xmin: Minimum search range limit = 0, Xmax: Maximum search range limit = 1, \(\textbf{Itr}_{\textbf{max}}\): Number of maximum iteration = 150, nPop: Number of Population = 15, C1: Cognitive parameter = 0.7, C2: Social parameter = 1.7, w: Inertia weight = 1, a: Randomization parameter = 0.6, \(\boldsymbol{\beta_{0}}\): Attractiveness of fireflies at zero distance = 2, \(\boldsymbol{\gamma}\): Coefficient of the light absorption = 89]_  
**Step 2**: The position of the population is initialized at random.  
**Step 3**: Fitness value, the P\({}_{\text{best}}\) solution and G\({}_{\text{best}}\) solution are calculated and assigned to the HFPSO algorithm.  
**Step 4**: The distance between P\({}_{\text{best}}\) and G\({}_{\text{best}}\) with a population \(x_{j}\) are identified as r\({}_{\text{px}}\) and r\({}_{\text{gx}}\), respectively. At this stage, the values of r\({}_{\text{px}}\) and r\({}_{\text{gx}}\) are calculated according to Equation (14) and Equation (15). Notation d in both equations represents the dimensionality of the search problem.  
\[r_{\text{px}}=\sqrt{\sum_{k=1}^{\text{d}}{(P_{\text{best}i,k}-x_{j,k})^{2}}} \tag{14}\]  
\[r_{\text{gx}}=\sqrt{\sum_{k=1}^{\text{d}}{(G_{\text{best}i,k}-x_{j,k})^{2}}} \tag{15}\]  
**Step 5**: At this stage, the fitness of population x\({}_{i}\) and population x\({}_{j}\) is compared.  
**Step 6**: If the fitness of the population \(x_{j}\) is greater than population \(x_{i}\), the local search will be started and handled by FF algorithm in updating new position according to Equation (13). Otherwise, the population will be handled by the PSO algorithm and it will update the new position according to Equation (16).  
\[x_{i,k}(t+1)=\omega x_{i,k}(t)+C_{1}e^{-r_{\text{pset}}x^{2}}(P_{\text{best},k}(t )-x_{i,k}(t))+C_{2}e^{-r_{\text{gs}}x^{2}}(G_{\text{best},k}(t)-x_{i,k}(t))+ \alpha(\gamma-0.5) \tag{16}\]  
**Step 7**: The values for fitness, \(P_{\text{best}}\) and \(G_{\text{best}}\) are updated.  
**Step 8**: Fireflies are sorted in descending order according to their fitness values.