# Research on Agricultural Product Price Prediction Based on Improved PSO-GA
## 3 Materials and Methods
### Optimization Algorithm Based on PSO-GA Improvement
#### 3.6.2 Improved PSO-GA  
The improved PSO-GA optimization algorithm proposed in this study utilizes elite learning, the dynamic adjustment of speed parameters, and uniform variation and arithmetic crossover methods, and makes full use of the global search ability of the particle swarm optimization algorithm and the characteristics of population diversity in genetic algorithms to achieve complementary advantages in order to achieve the purpose of determining the optimal combination model weights. The flowchart of this algorithm is given in Figure 2, below. The computational steps of the proposed improved PSO-GA weight assignment method can be expressed as follows:  
Step 1: Define the objective function \(\mathbf{F}(\mathbf{w})=\sum_{i=1}^{n}\mathbf{y}-|\hat{\mathbf{y}}_{\mathbf{n}}\,*\,\mathbf{x}_{\mathbf{ n}}|\)  
where \(\mathrm{x_{n}}\) is the value of the weighting coefficient, \(\hat{\mathbf{y}}_{\mathbf{n}}\) is the predicted value of the nth individual prediction model, and \(\sum_{i=1}^{n}\mathbf{x}_{i}\) = 1.  
Step 2: Set the solution space dimension \(\dim\,(D)\), population size \(N\), maximum number of iterations \(T\), acceleration coefficients \(c1\), \(c2\), GA maximum generation \(g1\), GA mutation rate \(r_{1}\)\(\in\)\([0,1]\), GA crossover rate \(r_{2}\)\(\in\)\([0,1]\), and other parameters are initialized.  
Step 3: Randomly generate the initial positions of N particles \(\mathbf{X}\) = {\(x_{1}\),\(x_{2}\),\(x_{3}\)...}, corresponding to the velocity \(\mathbf{V}\) = {\(v_{1}\),\(v_{2}\),\(v_{3}\)...}; \(x_{i}\) and \(v_{i}\) denote the position and velocity of the particle in \(d\)-dimensional space, respectively. \(x_{i}\) is also a solution to the problem.  
Step 4: In the \(i\)th iteration, the particle velocity and position are updated based on individual and population optimal solutions through dynamic weight adjustment, with the first \(T/2\) iterations facilitating individual exploration and the second \(T/2\) iterations facilitating convergence and evaluating particle adaptation. The formulas for updating velocity and position are as follows:  
\[\begin{split}\mathrm{v}_{\mathrm{ij}}^{(t+1)}=\mathrm{w}\times \mathrm{v}_{\mathrm{ij}}^{(t)}+\mathrm{c}_{1}\times\mathrm{rand}(0,1)\times \left[\mathrm{pbest}_{\mathrm{ij}}^{(t)}-\mathrm{x}_{\mathrm{ij}}^{(t)}\right] \\ +\mathrm{c}_{2}\times\mathrm{rand}(0,1)\times\left[\mathrm{gest}_{ \mathrm{ij}}^{(t)}-\mathrm{x}_{\mathrm{ij}}^{(t)}\right],\end{split} \tag{9}\]  
Figure 2: Flowchart of PSO-GA methodology.  
\[\begin{split}\text{x}_{\text{ij}}^{(t+1)}=\text{x}_{\text{ij}}^{(t)}+ \text{v}_{\text{ij}}^{(t+1)},\end{split} \tag{10}\]  
of which \(\text{v}_{ij}^{(t+1)}\) and \(\text{x}_{ij}^{(t+1)}\) denote the position and velocity of the \((t+1)\)th particle.  
Step 5: In each iteration, sort the particle swarm, keep the first half of the excellent particles \(p1\), perform arithmetic crossover and uniform mutation on the last half of the particles \(p2\), and then merge the old and new particles to form a new particle swarm.  
Step 6: Update the optimal position and optimal fitness value of the population by comparing the fitness value of the current position with the optimal fitness value.  
Step 7: Repeat Steps 4-6 to end the algorithm when the set maximum number of iterations or convergence accuracy is reached.