# Cross-Correlation Wavelet-Domain-Based Particle Swarm Optimization for Lightning Mapping
## 2 Materials and Methods
### Lightning Mapping Optimization  
The conventional approach to validate a lightning map is through the use of a high-speed camera [1; 8; 25; 26]. To mitigate the dependency of the high-speed camera method for authenticating the real pattern of lightning mapping, the initial lightning maps were found by the proposed approach as shown in phase 3 (see Figure 1). The lightning maps were obtained by calculating the time-of-arrival delays using sequential sliding windows and Wavelet cross-correlation techniques. The PSO optimization utilized these initial estimates (referring to the actual lightning maps as produced by the CCWD method) to minimize the estimation errors by tuning some hyperparameters (i.e., sliding window size) that directly alter the estimation of the initial maps. Hence, in order to perform the PSO optimization, the window size (\(W_{s}\)) was adopted as a decision variable (refer to Section 3.1: Simulations).  
Figure 3 shows the flowchart of the proposed PSO-algorithm-based wavelet technique. The implementation of wavelet technique based on PSO steps are described as follows: (1) PSO initialization: set the PSO initial parameters and the wavelet-based technique; (2) generate initial population: select the first vector array of randomized window size (\(Ws\)); (3) fitness evaluation: evaluate the fitness value of each particle using objective function equation (Equation (3)); (4) compute the maximum iteration and update individual and global best data: local best value (Pbest) is calculated and compared with the existing global best value (Gbest); if the fitness value is minimized, then  
Figure 2: The lightning event extraction algorithm.  
new global best value; (5) update velocity and positioning of each population: the velocity and position of each population in the swarm are updated using Equations (1) and (2); (6) repeat steps from (3) to (5).  
In the PSO algorithm, every solution of a given problem is considered as a particle, which is able to move at arbitrary velocity across a dimensional search space to find two locations. In order to update the position of each particle, two factors are considered--the position factor and the velocity factor. The position factor shows the position of the particle in the search space, whereas the velocity indicates the direction and intensity of movement. We followed [27] to update the two factors of position and velocity in each iteration using Equations (1) and (2).  
\[X_{i}^{d}(t+1)=X_{i}^{d}(t)+V_{i}^{d}(t+1), \tag{1}\]  
Figure 3: Flowchart of lightning mapping procedures using PSO-based algorithm.  
\[V_{i}^{d}(t+1)=wV_{i}^{d}(t)+c_{1}r_{1}\Big{(}P_{i}^{d}(t)-X_{i}^{d}(t)\Big{)}+c_{2 }r_{2}\Big{(}g_{t}^{d}(t)-X_{i}^{d}(t)\Big{)}, \tag{2}\]  
where the velocity multiplied by a variable \(w\) as the first component called inertia weight factor, inertia weight normally decrease linearly from 0.9 to 0.4 to maintain the movement direction. The second component is called the cognitive component \(\Big{(}P_{i}^{d}(t)-X_{i}^{d}(t)\Big{)}\) because each particle is considered the distance between its personal best and current location. The third component, however, is called the social component \(\Big{(}g_{t}^{d}(t)-X_{i}^{d}(t)\Big{)}\) because the particle calculates the distance between its current position and the best position found by the entire swarm. It is worth mentioning that for the variable \(g_{t}^{d}(t)\) in the social component, there is no subscript because there is only one best solution in the swarm for all particles. \(c_{1}\) and \(c_{2}\) represent the two learning acceleration factors with a limited range of \((0,\ 4)\). The impact of the cognitive-social components and the movement of the particle can be changed by tuning these two acceleration factors. Meanwhile, \(r_{1}\) and \(r_{2}\) generates a uniform distribution of two random functions in the interval \((0,\ 1)\), used to increase the randomness searching for each particle in a single iteration, and \(V\) is the velocity factor of the agent \(i\) at iteration \(d\).