Skip to main content
. 2019 Dec 18;20(1):6. doi: 10.3390/s20010006
Algorithm 1: PSO-ANN algorithm.
Input: All the eigenvalues of the optimal feature combination.
Output: The best position of the particle swarm Gbest, and the best prediction accuracy.
01: Set the parameters {n, iterationmax, vmax, vmin, xmax, xmin}
02: for i = 1 to n do /* n is the number of particles */
03:        Initialize vi = (vi1, vi2, vi3, vi4), xi = (xi1, xi2, xi3, xi4), Pbesti= xi
04: end for
05: Acquire training set Xtrain, Ytrain and test set Xtest, Ytest
06: Set the particle with best fitness(Pbesti) to be Gbest
07: for k = 1 to iterationmax do
08:        Update w with Equation (3)
09:        Update c1, c2 with Equation (4)
10:        for i = 1 to n do
11:                anni= ann_model(learning_rate = xi1, hidden_layer_ neurons = xi2,
12:                                momentum_parameter = xi3, rmsprop_parameter = xi4)
13:                anni.fit(Xtrain, Ytrain) /* Training ANN model */
14:                loss_valuei = anni.loss_value
15:                prediction_accuracyi = anni.score(Xtest, Ytest)
16:                if (loss_valuei > fitness(Pbesti).loss_value and
17:                        prediction_accuracyi < fitness(Pbesti).prediction_accuracy) then
18:                    Pbesti= xi
19:                end if
20:                 if (loss_valuei > fitness(Gbest).loss_value and
21:                        prediction_accuracyi < fitness(Gbest).prediction_accuracy) then
22:                    Gbest= xi
23:                end if
24:                for j = 1 to 4 do
25:                         vijk+1=wvijk+c1r1(Pbestijkxijk)+c2r2(Gbestjkxijk)
26:                         xijk+1=xijk+vijk+1
27:                end for
28:        end for
29: end for