# A Fire Detection Algorithm Based on Tchebichef Moment Invariants and PSO-SVM
## 4 Particle Swarm Optimization-Support Vector Machine (PSO-SVM)
### Particle Swarm Optimization for SVM Parameters  
From Equations (29), (32), and (33), it is clear that the value selections of kernel parameter \(\tau\) and penalty factor \(C\) have an effect on the detection result. If these parameters are excessively large, the detection accuracy rate will be very high in the training sample set, but very low in the testing sample set. On the contrary, if they are disproportionately small, the detection accuracy rate will be too low to satisfy, making the model useless.  
PSO is a population-based global optimization algorithm from the simulation of birds feeding on behavior, proposed by [PERSON] and [PERSON] [39; 40; 41; 42; 43; 44]. Owing to its advantageous characteristic of high efficiency, robustness, and easy implementation with code, the PSO algorithm is applied to optimize the parameters of SVM in this paper, combined with K-fold cross-validation.  
In the PSO algorithm, the particle swarm is initialized by a population of particles, which are generated with random positions and velocities. The fitness value of particles are calculated with an objective function. Then, every particle updates its velocity and position dynamically with the personal-best value and global-best value. As a result, the global-best position is obtained by simply adjusting the position of every particle, according to its own personal-best value as well as neighboring particles.  
In the s-dimensional space, the \(i\)-th (\(i=1,\,2,\,\cdots,\,s\)) particle's position vector and velocity vector can be indicated as \(\mathbf{X_{i}}=(X_{i1},\,X_{i2},\,\cdots,\,X_{is})\) and \(\mathbf{v_{i}}=(v_{i1},\,v_{i2},\,\cdots,\,v_{is})\), respectively. Then, the PSO algorithm can be described by the following equations:  
\[v_{is}(t+1)=\omega v_{is}(t)+c_{1}r_{1}(t)\big{[}P_{is}(t)-X_{is}(t)\big{]}+c_{ 2}r_{2}(t)\big{[}P_{gs}(t)-X_{is}(t)\big{]} \tag{34}\]  
\[X_{is}(t+1)=X_{is}(t)+v_{is}(t+1) \tag{35}\]  
where \(v_{is}(t)\) is the previous velocity, which is limited in the range of \([-v_{\max},\,v_{\max}]\); \(P_{is}(t)\) is the individual-best position obtained for now; \(P_{gs}(t)\) is the global-best position obtained for now; \(\omega\) is the inertia weight value controlling the effect of the previous velocity on the current one; \(c_{1}\) and \(c_{2}\) are the acceleration coefficients; \(r_{1}(t)\) and \(r_{2}(t)\) are two independent pseudo-random numbers which are uniformly distributed in the range of \([0,1]\).  
The flow diagram of PSO-SVM model construction is illustrated in Figure 2, and the process of optimizing the SVM parameters with PSO is described as follows:  
1. Initialize particle and set PSO parameters. Generate the initial particles at random, which are composed of the SVM parameters \(\tau\) and \(C\). Then, set the PSO parameters, including the size of population \(s\), maximum number of iterations \(t_{\max}\), inertia weight \(\omega\), and acceleration coefficients \(c_{1},\,c_{2}\).
2. Fitness calculation. Evaluate the fitness value of every particle, which is the average classification accuracy of K-fold cross-validation. Take the current particle as its individual-best point and regard the particle with maximal fitness value as the global-best point.
3. Update. Every particle's velocity and position are updated by Equations (34) and (35), respectively. Evaluate the fitness of every current particle and compare the fitness value with that of the individual-best point and that of the global-best point. If the current value is better, update the particle with the current value as its individual-best point or global-best point.
4. Check stopping criteria. If the maximum number of iterations is attained, the evolutionary process will stop. Otherwise, proceed to Step 3.
5. Determine parameters. When the maximum number of iterations is attained and the stopping criteria is satisfied, the values of optimal parameters \(\tau\) and \(C\) are finally obtained. Then, the training and verification procedure is ended, and the PSO-SVM model is constructed.