The improved grasshopper optimization algorithm and its applications

Grasshopper optimization algorithm (GOA) proposed in 2017 mimics the behavior of grasshopper swarms in nature for solving optimization problems. In the basic GOA, the influence of the gravity force on the updated position of every grasshopper is not considered, which possibly causes GOA to have the slower convergence speed. Based on this, the improved GOA (IGOA) is obtained by the two updated ways of the position of every grasshopper in this paper. One is that the gravity force is introduced into the updated position of every grasshopper in the basic GOA. And the other is that the velocity is introduced into the updated position of every grasshopper and the new position are obtained from the sum of the current position and the velocity. Then every grasshopper adopts its suitable way of the updated position on the basis of the probability. Finally, IGOA is firstly performed on the 23 classical benchmark functions and then is combined with BP neural network to establish the predicted model IGOA-BPNN by optimizing the parameters of BP neural network for predicting the closing prices of the Shanghai Stock Exchange Index and the air quality index (AQI) of Taiyuan, Shanxi Province. The experimental results show that IGOA is superior to the compared algorithms in term of the average values and the predicted model IGOA-BPNN has the minimal predicted errors. Therefore, the proposed IGOA is an effective and efficient algorithm for optimization.

Based on the existence of the constraint conditions, optimization models are divided into unconstrained optimization models and constrained optimization models, which widely exist in computer science 1 , artificial intelligence 2 , pattern recognition 3 , energy consumption 4 , truss structural systems 5 , engineering areas 6 , nonlinear time series 7 , and so on.
Swarm intelligence algorithms recently proposed have been applied to solve the optimization models obtained from different actual problems. The genetic algorithm (GA) by Holland in 1992 8 and the particle swarm optimization (PSO) by Eberhart and Kennedy in 1995 9 provided some insights for researchers to propose many other swarm intelligence algorithms, such as Moth-fame optimization algorithm (MFO) 6 , Multi-verse optimizer (MVO) 10 , Sine cosine algorithm (SCA) 11 , Whale optimization algorithm (WOA) 12 , Grey wolf optimizer (GWO) 13 , Bird mating optimizer (BMO) 14 , Harris Hawks Optimizer (HHO) 15 , Grasshopper Optimization Algorithm (GOA) 16 , Dragonfly Algorithm (DA) 17 , Slap Search Algorithm (SSA) 18 , Arithmetic Optimization Algorithm (AOA) 19 and Aquila Optimizer (AO) 20 . These swarm intelligence algorithms have the exploration phase and the exploitation phase. According to the different simulations, every swarm intelligence algorithm has the prominent updated method of the individual and the different applied background. Generally, benchmark functions are applied to test the performance of these swarm intelligence algorithms. Experimental results show that not all swarm intelligence algorithms can solve the whole optimization problems.
Machine learning has been used to solve the prediction and classification problems. For example, Support Vector Regression (SVR) and Long Short-Term Memory (LSTM) based deep learning model were combined to establish the deep learning method for predicting the AQI values accurately, which helped to plan the metropolitan city for sustainable development 21 . And LSTM Recurrent Neural Network was also utilized to preform the stock market prediction 22 . Especially, the randomness of the parameters of machine learning leads to unstable results of predictions and classifications. The fitter are the parameters, the better are the results. Swarm intelligence algorithms can be used to optimize the fitter parameters of machine learning. The problems of optimizing the parameters of neural network by using swarm intelligence algorithm are actually the optimization problem. For example, SCA and GA were used to optimize the parameters of BP neural network for predicting the direction of the stock market indices 23,24 ; the improved Exponential Decreasing Inertia Weight-Particle

Improved grasshopper optimization algorithm
The basic grasshopper optimization algorithm. GOA proposed in 2017 mimicked the behaviour of grasshopper swarms in nature for solving optimization problems 16 . The mathematical model of simulating the behaviour of grasshopper swarms is as follows 36 : where X i , S i , G i , and A i denote the position, the social interaction, the gravity force and the wind advection of the ith grasshopper, respectively. The randomness of the position of grasshoppers is considered and then the Eq. (1) is written to be X i = r 1 S i + r 2 G i + r 3 A i , where r 1 , r 2 , r 3 are the random numbers in the interval [0, 1], and S i is defined by where N denotes the number of the grasshoppers in the swarm, d ij = X j − X i is the distance between the ith grasshopper and the jth grasshopper, d ij = X j −X i d ij is the unit vector from the ith grasshopper to the jth grasshopper and the social force s(r) is defined by where f indicates the intensity of attraction and l is the attractive length scale. In the Ref. 16 , l = 1.5, f = 0.5. (1) Let d be the distance between two grasshoppers. d = 2.079 is called the comfort zone or comfortable distance where there is neither attraction nor repulsion between two grasshoppers. When d < 2.079 , there is repulsion between two grasshoppers. When d > 2.079 , there is attraction between two grasshoppers. In particular, when d changes from 2.079 to nearly 4, s increases. When d > 4,s decreases. When d > 10 , s trends to 0 and then s has no action. Therefore, d is mapped into the distance of grasshoppers in the interval of 1,4 . Thus the space between two grasshopper is divided into repulsion region, comfort zone, and attraction region.
G i in the Eq. (1) is defined by where g is the gravitational constant and ê i is a unity vector towards the center of the earth. But the grasshoppers are as soon as located in the comfort zone and the swarm can not be converged into the appointed point. Therefore, Eq. (6) can not be used to solve the optimization model directly.
In order to solve the optimization model, the Eq. (6) is modified to be where ub d , lb d are the upper bound and the lower bound of the dth component of the ith grasshopper, T d is the d th component of the optimal grasshopper T , the adaptive parameter c is a decreasing coefficient to shrink the comfort zone, repulsion zone, and attraction zone. In Eq. (7), the gravity force is not considered, that is, there is no G component. And assume that the wind direction ( A component) is always towards a target T d . In order to balance the exploration stage and the exploitation, the parameter c is defined by where c max , c min are the maximum and the minimum of the parameter c , respectively, t denotes the current iteration and T denotes the maximum iteration. In GOA, c max = 1, c min = 0.000001.
The improved GOA. Based on the influence of the gravity force not to be considered in the basic GOA, the right side of the Eq. (7) minus the sum of the product between the gravitational constant g and the unit vector from the ith grasshopper to the jth grasshopper, thus the new updated position of the grasshopper is obtained as follows The velocity of the ith grasshopper causes its position updated during the hunting process as follows where a is the acceleration coefficient and rand is the random number between 0 and 1. Therefore, the ith grasshopper adopts two updated ways Eqs. (9) and (11) of the position. According to the selected probability p , the position of the ith grasshopper is updated as follows where c is the same as that in the basic GOA.
Based on the above, the GOA is improved, written as IGOA. The concrete steps of IGOA are as follows.
Step 1. Initialization. Initialize the grasshopper swarm X i (i = 1, 2, . . . , N) , c max , c min , minimum and maximum of velocity, maximum number of iterations T.
Step 2. Calculate the fitness of every grasshopper and find the optimal grasshopper T . Let t = 1.
Step 3. Update the parameter c by use of Eq. (8).
(4) www.nature.com/scientificreports/ Step 4. For every grasshopper, the distance between the grasshoppers is firstly mapped into the interval 1,4 , and the selected probability p is adopted. If p < 0.5 , the position of the grasshopper is updated by use of Eq. (12) or Eq. (9). Otherwise, the position of the grasshopper is updated by use of Eq. (12) or Eqs. (10) and (11). If the position of the grasshopper is out of the bound, then the position of the grasshopper is updated by use of the upper bound and the lower bound.
Step 5. Calculate the fitness value of every grasshopper. Update T if there is a better grasshopper. Let t = t + 1.
Step 6. Judge whether the terminal condition is satisfied. If YES, return the optimal grasshopper T . Otherwise, turn Step 3.

The function optimization
In this section, we adopt 23 benchmark functions to test the performance the proposed IGOA by compared with GOA, PSO, MFO, SCA, SSA, MVO and DA.

benchmark functions.
In this subsection, 23 benchmark functions are derived from the Ref. 15 . Tables 1,   2 and 3 show the function expression, the dimension, the range and the minimum value of seven unimodal
The setup of the parameters. In order to verify the validation of the proposed IGOA in the paper, we choose GOA, PSO, MFO, SCA, SSA, MVO and DA to be the comparable algorithms. In the experiments, the parameters of these eight algorithms are set up as shown in Table 4.  respectively, which are all less than those obtained by GOA and PSO. But for the unimodal function F 6 (x) , the average value of the optimal value obtained by IGAO is 2.0048E+00, which is less than that obtained by GOA and is more than that obtained by PSO. For the multimodal functions F 9 (x) − F 13 (x) , the average values of the optimal values obtained by IGAO are 4.2445E−01, 5.2213E−02, 2.9202E−04, 2.2805E−01 and 1.5727E+00, respectively, which are all less than those obtained by GOA and PSO. But for the multimodal function F 8 (x) , the average value of the optimal value obtained by IGAO is − 7.1112E+03, which is more than that obtained by GOA and is less than that obtained by PSO.
For the functions F 14 (x), F 20 (x) , the average values of the optimal values obtained by IGAO are 9.9816E−01 and − 3.2475E+00, respectively, whose degree closest to the optimal values 9.9800E−01 and − 3.32 is less than those obtained by GOA and is more than those obtained by PSO. For the functions F 16 (x) − F 17 (x) , the average values of the optimal values obtained by IGAO are − 1.0313E+00 and 3.9851E−01, whose degrees closest to the optimal values − 1.0316E+00 and 0.3978 are all less than GOA and PSO. For the functions F 18 (x) − F 19 (x) , the average values of the optimal values obtained by IGAO are 3.0152E+00 and − 3.8583E+00, whose degree closest to the optimal values 3 and − 3.86 is less than that obtained by PSO and is more than that obtained by GOA. For the functions , the average values of the optimal values obtained by IGAO are 1.9673E−03, − 8.9507E+00, − 9.4709E+00 and − 9.3486E+00, whose degrees closest to the optimal values 0.0030, − 10.1532, − 10.4028 and − 10.5363 are more than those obtained by GOA and PSO. Figure 2 shows the convergence curves of IGOA, GOA and PSO on the first 200 iterations on benchmark . It is observed from Fig. 2 that the convergence speed of IGOA is faster than those of GOA and PSO. Table 5 and Fig. 2 show that IGOA outperforms GOA and PSO.  , the average value of the optimal value obtained by IGAO is − 7.1112E+03, which is more than that obtained by SCA, SSA, MVO and DA and is less than that obtained by MFO.
For the function F 14 (x) , the average value of the optimal value obtained by IGAO is 9.9816E−01, whose degree closest to the optimal value 9.9800E−01 is less than that obtained by MVO and is more than that obtained by MFO, SCA, SSA and DA. For the function F 15 (x) , the average value of the optimal value obtained by IGAO is 1.9673E−03, whose degree closest to the optimal value 0.0030 is less than that obtained by MVO and DA and is more than that obtained by MFO, SCA and SSA. For the function F 16 (x) , the average value of the optimal value obtained by IGAO is − 1.0313E+00, whose degree closest to the optimal value − 1.0316E+00 is less than that obtained by MFO, SCA, SSA, MVO and DA. For the function F 17 (x) , the average value of the optimal value obtained by IGAO is 3.9851E−01, whose degree closest to the optimal value 0.398 is less than that obtained by MFO, SSA, MVO and DA and is more than that obtained by SCA. For the function F 18 (x) , the average value of the optimal value obtained by IGAO is 3.0152E+00, whose degree closest to the optimal value 3 is less than that obtained by MFO, SCA, SSA, MVO and DA. For the function F 20 (x) , the average value of the optimal value obtained by IGAO is − 3.2475E+00, whose degree closest to the optimal value − 3.32 is less than that obtained by MVO and is more than that obtained by MFO, SCA, SSA and DA. For the functions ,the average values of the optimal values obtained by IGAO are − 3.8583E+00, − 8.9507E+00, − 9.4709E+00 and − 9.3486E+00, which is the closer to the optimal values − 3.86, − 10.1532, − 10.4028 and − 10.5363 than those obtained by MFO, SCA, SSA, MVO and DA. Therefore, it is observed from Table 5

Applications
In this section, the proposed IGOA is used to optimize the weights and the bases of the BP neural network, and then predicted model IGOA-BPNN is obtained. Finally, the IGOA-BPNN is used to perform the prediction of the closing prices of the Shanghai Stock Exchange Index and the air quality index (AQI) of Taiyuan, Shanxi Province.
Predicted model. IGOA proposed in this paper is used to optimize the connected weights and the bases of BP neural network, and the predicted model IGOA-BPNN is established. The concrete steps of IGOA-BPNN are as follows: Table 5. The average values and the standard deviations of the optimal function values of these 23 benchmark functions. The bold indicates the optimal value for each benchmark function. www.nature.com/scientificreports/

IGOA
Step 1: Input data and divide these data into the training set and the testing data. Normalize the training set and the testing set.
Step 2: Initialize the size of the grasshopper swarm, c max , c min , minimum and maximum of velocity, the maximum number of iterations of IGOA, and the number of the nodes in the hidden layer of BP neural network and the maximum number of iterations of BP neural network. Choose Mean Square Error (MSE) to be the fitness function of IGOA, where y s , t s are the predicted value and the target value of the s th sample. Let t = 1.
Step 4: Map every grasshopper into the connected weights between the input layer and the hidden layer, the bases in the hidden layer, the connected weights between the hidden layer and the output layer, the bases in the output layer of BP neural network. Then train BP neural network and obtain the predicted values of the training set. According to predicted values and the target values, calculate the fitness value of this grasshopper. Find out the optimal grasshopper.
Step 5: Update the grasshopper swarm by use of IGOA. Then let t = t + 1.
Step 6: If the termination conditions are satisfied, then turn Step 6, otherwise turn Step 3.
Step 7: Output the optimal grasshopper. Then map the optimal grasshopper into the connected weights between the input layer and the hidden layer, the bases in the hidden layer, the connected weights between the hidden layer and the output layer, the bases in the output layer of BP neural network. Then train BP neural Prediction of Shanghai Stock Index. Data source. In this subsection, Shanghai Stock 000001 from December 19, 1990 to June 28, 2021 loaded from the website http:// quotes. money. 163. com/ trade/ lsjysj_ zhishu_ 000001. html contains 7459 days' data. Figure 4 shows that the trend of the 7459 days' closing prices. The features of every data sample consist of the closing price, the highest price, the lowest price, the opening price, the previous closing, the rise and fall amount, the rise and fall range, the trading volume and the transaction amount.
In this paper, we choose the closing price, the highest price, the lowest price, the opening price, the previous closing, the trading volume and the transaction amount to be the features of samples and use the features of the  Table 6. Figure 5 shows the comparison among the actual values and the predicted values of IGOA-BPNN, GOA-BPNN, PSO-BPNN and BPNN of these 75 testing samples.
From Table 6, the predicted errors MSE = 828.95, MAE = 21.70, RMSE = 3.32, MAPE = 0.62% obtained from predicted model IGOA-BPNN are less than those obtained from the predicted models GOA-BPNN, PSO-BPNN, MFO-BPNN, SCA-BPNN, SSA-BPNN, MVO-BPNN, DA-BPNN and BPNN, which shows that the proposed IGOA in this paper is more suitable for optimizing the parameters of BP neural network for predicting Shanghai Stock Index 000001. It is also observed from Table 6 that the predicted performance of the BP neural network optimized by swarm intelligence algorithms outperforms the pure BP neural network.
Prediction of air quality index in Taiyuan, Shanxi. Data source. The 1273 day's data from January 1, 2018 to June 26, 2021 in this subsection is derived from the website https:// www. aqist udy. cn/ histo rydata/ month data. php? city=% e5% a4% aa% e5% 8e% 9f. The features of every data consist of the current air quality index (AQI), quality grade, PM2.5, PM10, SO 2 , CO, NO 2 , O 3 . The relation between AQI and quality grade is shown in Table 7. The remaining 1264 data samples are kept by deleting the missing data. Figure 6 shows the number of days and proportion distribution of excellent, good, light pollution, moderate pollution, heavy pollution and serious pollution in these 1264 days. Figure 7 shows the trends of AQI in these 1264 days.
In this subsection, we choose the current AQI, PM2.5, PM10, SO 2 , CO, NO 2 and O 3 to predict AQI of the next day and select the 1241 data samples from January 1, 2018 to June 3, 2021 to be training set and the 22 data samples from June 4, 2021 to June 25,2021 to be the testing set.
Experimental results. The proposed IGOA-BPNN in this subsection is utilized to predict AQI in Taiyuan, Shanxi. Similar to "Experimental results", among the BPNN and the BPNN part of these comparable predicted    Table 8. Figure 8 shows the comparison among the actual values and the predicted values of IGOA-BPNN, GOA-BPNN, PSO-BPNN and BPNN of these 22 testing samples. From Table 8, the predicted errors MSE = 134.43, MAE = 32.51, RMSE = 7.81, MAPE = 31.91% obtained from predicted model IGOA-BPNN are less than those obtained from the predicted models GOA-BPNN, PSO-BPNN, MFO-BPNN, SCA-BPNN, SSA-BPNN, MVO-BPNN, DA-BPNN and BPNN, which shows that the proposed IGOA in this paper is more suitable for optimizing the parameters of BP neural network for predicting AQI in Taiyuan, Shanxi. It is also observed from Table 8 that the predicted performance of the BP neural network optimized by swarm intelligence algorithms outperforms the pure BP neural network.   However, the size of the initial population of IGOA, the parameters of BP neural network, and other machine learning methods may lead to different experimental results. Therefore, it is necessary to study the combination of swarm intelligence algorithm and different machine learning to establish prediction models to solve practical problems.