## 3 Proposed LSTM-GA and Optimized LSTM-GA Approach
A GA is an optimization method inspired by the principles of natural selection and genetics. It starts with a population of randomly generated solutions and then iterates through several selection, crossover, and mutation steps. Fitness values are iteratively assigned to solutions, with those that are effective at solving a problem having a slightly increased chance of passing on their characteristics to the next generation. Ideally, over many generations, this process leads to an increasingly refined solution to the problem at  
Figure 3: Methodology process. hand, with the population converging toward an optimal or near-optimal solution [40]. The main steps for the GA include the following:  
* **Creating Initial Population:** To prevent premature convergence, the population's diversity should be preserved. This is why we use random initialization to prevent having similar solutions. Each individual's genes encode the specific LSTM model's hyperparameters: the number of layers, units per layer, batch size, number of epochs, and dropout rate. The random initialization of genes within predefined ranges uses \(g_{i}=\text{random}(a_{i},b_{i})\), where the bounds for the i-th hyperparameter are defined by \(a_{i}\) and \(b_{i}\). This enables a diverse starting population, which better explores the combinations of hyperparameters for the GPS spoofing detection problem. * **Fitness Function:** This is a mathematical operation that evaluates the effectiveness of an individual (a set of hyperparameters). In our case, the fitness function calculates the maximum validation accuracy of the LSTM model trained with a specific hyperparameter set: \[f(x)=\max(\text{val\_accuracy}(x))\] (1) where \(x\) represents the individual's hyperparameters. Higher validation accuracy indicates better detection performance, and the fittest individuals are advanced to the crossover stage. * **Crossover:** Every two individuals selected (parent chromosomes) are crossed over in order to generate offspring with a combination of the hyperparameters of the parents. Two-point crossover is used for our GA, where genes between two randomly selected points, \(c_{1}\) and \(c_{2}\), are swapped across the parents. Offspring born this way inherit hyperparameters from both parents, which might fasten the convergence to optimal configurations. \[\text{Offspring1}=[g_{11},\dots,g_{1c_{1}-1},g_{2c_{1}},\dots,g_{2c_{2}},g_{1c _{2}+1},\dots,g_{1n}]\] (2) \[\text{Offspring2}=[g_{21},\dots,g_{2c_{1}-1},g_{1c},\dots,g_{1c_{2}},g_{2c_{ 2}+1},\dots,g_{2n}]\] (3)
* **Mutation:** Mutation randomly modifies genes to maintain diversity in the population and avoid early convergence. During this step, each gene, \(g_{i}\), representing one hyperparameter is assigned a mutation probability, \(P_{\text{mutation}}=0.2\). Mutated genes are re-randomized within their pre-defined ranges. \[g_{i}^{\prime}= \begin{cases}\text{Random}(a_{i},b_{i}),&\text{if }r\leq P_{\text{mutation}}\\ g_{i},&\text{otherwise}\end{cases} \] (4) Here, \(r\) is a random number in \([0,1]\). This helps to explore less likely configurations, which may yield superior performance for GPS spoofing detection. * **Survivor Selection:** Survivor selection is a process that identifies which individuals will progress to the subsequent generation. In this project, generational replacement incorporating elitism is employed to guarantee the retention of the highest-performing solutions. The next generation's population is given as \[\text{Population}_{t+1}=\text{Elites}_{t}\cup\text{Offspring}_{t}\] (5) where _Elites_ are the best-performing individuals from the current generation, \(t\), retaining the best hyperparameter configurations. * **Termination Condition:** It is of importance to note the termination condition when a Genetic Algorithm cycle comes to an end. For this work, the algorithm stops once the number of generations, \(t\), has reached the maximum \(T_{\max}\).