Osprey optimization algorithm integrated with graph neural networks for intrusion detection in wireless sensor networks Authors: Divya Bhavani Mohan, Prakash Arumugam, Anand R. Published: 2025 ABSTRACT With the complexity of the cyber-attacks increasing tremendously, framing an efficient intrusion detection system (IDS) has proved to be highly vital and crucial in ensuring security across the wireless sensor networks (WSNs). The major function of IDS is to prevent the WSNs from suspected attacks. Conventional IDS face numerous challenges which include limited capability, inadequate identification of attacks and detection of high false alarm rates, leading to complex data processing and pattern identification. To overcome these issues, a novel method which integrates Osprey Optimization Algorithm (OOA) and Graph Neural Networks (GNN) referred as OOA-GNN is proposed for enhancing the WSN security by efficiently detecting various categories of attacks. The proposed model integrates a deep learning framework built on graphical structures to obtain complex relationships and the hyperparameters of GNN is fine-tuned by OOA for improving the detection performance. In order to evaluate the proposed model, Wireless Sensor Networks-Dataset (WSN-DS) is chosen which is imbalanced in nature. To solve the imbalance characteristics, Synthetic Minority Oversampling Technique (SMOTE) is used on the training set. The OOA-GNN framework, through graphical representation of WSN data, successfully gathers the network patterns. The accuracy of 99.68% obtained through OOA-GNN outperforms traditional classifiers such as AdaBoost, Gradient Boosting Model (GBM), Xtreme Gradient Boosting (XGBoost), K-Nearest Neighbour-Arithmetic Optimization Algorithm (KNN-AOA), and K-Nearest Neighbour-Particle Swarm Optimization (KNN-PSO). Evaluating standard performance metrics demonstrate that the projected OOA-GNN model beats conventional approaches in terms of low false positive rate while adaption to network fluctuations. The proposed model enhances network reliability, improves the model’s exactness of attack detection and decreases false alarm occurrences by integrating parameter-tuning capabilities of the OOA with graph-based neural framework in real-time WSN operations. Introduction Wireless Sensor Networks (WSNs) have risen to be highly crucial in terms of data collection and real-time observation across diverse areas of applications like defense, healthcare, industrial automation, environmental surveillance and development of smart cities. Such networks comprise of large number of sensor nodes placed on a physical space, in which each node is capable of detecting, processing and sending the information wirelessly. While aligning the information, the nodes keep an eye on both environmental and physical conditions, including temperature levels, humidity, pressure or intrusion detection, letting the systems make smart and timely decisions. Although WSNs have benefits, they are susceptible to serious security threats. Their vulnerability to cyber threats is due to the decentralized structure, limited energy and memory resources and open communication channels. WSN attacks may risk data integrity, confidentiality and availability but interrupt important applications. Intrusion Detection Systems (IDSs) are those security mechanisms which are crucial because they keep track of what happens in the network, detect any abnormal behavior and act accordingly when an intruder has accessed the network illegally. Conventional IDS methods like those based on signature and anomaly, are usually faced with low detection capabilities, high false alarms and low adjustability to emerging attack trends. Although recent Machine Learning (ML) and Deep Learning (DL) methods have enhanced the practice of intrusion detection, they have drawbacks. Most of the approaches do not reflect complicated dependencies among nodes and cannot effectively support the imbalanced datasets, thus they are not more appropriate to be implemented in real-time WSNs. To counteract these shortcomings, Osprey Optimization Algorithm - Graph Neural Networks (OOA-GNN) framework is proposed. The GNN element is useful in modeling the interaction between network nodes, as well as identifying the patterns in the WSN traffic, and the OOA element is helpful in optimizing the model parameters and identifying the most appropriate features for enhanced classification. Secondly, the training data is subjected to SMOTE to deal with the imbalance of classes, as the minority types of attacks are properly identified. The suggested OOA-GNN framework proves to be superior to current IDS methods with high detection accuracy, specificity, sensitivity, f1_score and low false-positive rate. OOA-GNN offers a viable, strong and efficient solution that can function in the dynamic, resource-limited WSN environment by using a combination of graph-based deep learning and nature inspired optimization. Need for optimization based graph neural network models Traditional Machine Learning (ML) models confront difficulties while analyzing high-dimensional imbalanced datasets and lack capability to recognize intricate network traffic data patterns across the space and time. The IDS performance of various learning approaches including AdaBoost and Bagging face limitations, because they maintain fixed feature sets and static model architectures which reduce their adaptability to dynamic WSN environments. The OOA functions as a nature inspired optimization technique to improve intrusion detection model performance via its implementation for addressing the present challenges. Through its osprey-inspired hunting mechanisms, OOA optimizes the selection of features along with setting model parameters and determining weights of the classifier. The proposed OOA-GNN model effectively learns complex attack patterns and network structures through graph-based representation, resulting in improved classification performance. Contributions of the research article This research paper improves intrusion detection performance in WSNs by paving way for a novel framework, OOA–GNN. Two key motives are addressed by OOA namely, selection of most relevant features and optimization of GNN hyperparameters to improve classification accuracy while maintaining efficient computational performance. To resolve the problem of class imbalance, WSN-DS employs the SMOTE sampling technique, thereby ensuring uniform distribution of attack category and improving the identification of minority-class attacks. The GNN framework by means of representing WSNs as graphs, encodes the complex inter-node dependencies and spatial relationships within WSNs. GNN grasps the interaction and the hidden patterns among the nodes effectively, which leads to the learning of factors which influence potential intrusion behaviours. The proposed model detects the distributed and coordinated attacks with the help of aforementioned capability, that are often overlooked by conventional approaches. GNN integrated with OOA achieves an impressive classification accuracy of 99.68% which outperforms other reported classifiers. This specific graph-based structure enhances the adaptability and also ensures efficient performance of the WSN under dynamic topologies and evolving cyber-attacks.The paper is organised as follows—section “Literature review” discusses the review of literature done to identify the research problem. This is further followed by a detailed explanation of the proposed system in section “Proposed approach”. Section “Pseudocode of the proposed model: OOA-GNN with SMOTE balancing” discusses the algorithms and implementation of the proposed system whereas, section “Results and discussion” discusses the results obtained from the implementation. The paper is finally concluded in section “Conclusion”. Literature review A detailed literature review related to various methodologies developed and implemented for intrusion detection is presented in this section. An optimization technique based on the behaviour of prairie dogs coupled with differential evolution (DE) is suggested for addressing complex network problems. The incorporation of DE mutation and crossover along with exploration and exploitation strategy into PDO leads to effective detection of attacks in a network1. A Neural Network Model based on Quasi-Newton (QN3) is developed and implemented for the purpose of attack detection considering 100 nodes in a network. The accuracy obtained by this method is 79.90%, which is significantly higher compared to other methods2. Binary Chimp Optimization (BCO) based ID method is formulated with different phases that includes normalization of data, selection of features and tuning of parameters by Sine Cosine Algorithm (SCA). The processing time of 7.26 seconds for a real time implementation of WSN proves the efficacy of the formulated model3. Firefly Algorithm (FA) integrated with Support Vector Machines (SVM) is suggested in this study which includes the data normalization, feature selection by FA and the classification by SVM. Grey Wolf Optimizer is used for fine-tuning the parameters. FA based ML method produces an accuracy of 99.34% outperforming KNN-PSO and XGBoost models4. An efficient ID method that includes data cleaning and transformation is suggested in this study. Various hybrid deep learning architectures like CNN+RNN are assessed. These DL models achieve accuracy above 99% and surpass traditional methods5. Sequential Forward Search (SFS) technique combined with Random Forest (RF) classifier is framed for selecting the key features of STIN and UNSW_NB15 datasets. The developed model generates an accuracy of 90.5% and 78.52% on STIN and UNSW_NB15 respectively6. An amalgamation of RF and Recursive Feature Elimination (RFE) as a novel technique is suggested to enhance the IDS accuracy. This approach undergoes three stages including data preprocessing, normalization and feature selection for enhanced efficiency. The developed model produces an accuracy of 90.5% on STIN and 78.52% on UNSW_NB15 dataset.The study proves that the hybrid ensemble model attained an efficacy of 99% for CIC-IDS2018 dataset and 98.53% for UNSW_NB157. This study presents the NN-LEACH protocol as a method to optimize the energy efficiency of WSN through cluster-based routing solutions. This method enhances the duration of network operation by implementing efficient energy management during cluster formation, cluster head selection and data transmission phases8. KGMS-IDS is designed to resolve the class imbalance and rare-class attack identification. SMOTE, auto-encoders and ensemble learning are integrated with soft voting for multiclass anomaly detection. The model produces exceptional results by achieving 86.39% accuracy on NSL-KDD and 99.94% accuracy in case of N-BaIoT thus proving its competence in classification of attacks9. A hybrid ML based IDS is suggested for identification of attacks in WSNs. The system collects the information from sensor nodes through hybrid ML techniques. The proposed model is assessed on benchmark datasets comprising NSL-KDD, UNSW_NB15 and CICIDS2017. The model delivers outstanding performance levels with 99.82% accuracy and 99.91% precision across different simulation environments10. An AutoML framework is used for enhancing the ID in WSNs. The required predictors such as region area, sensing range, transmission area and sensor range are simulated using Monte Carlo Simulations. Through Bayesian optimization, the model selects the highest-performing ML algorithm and further tunes the hyperparameter to improve the prediction accuracy11. The authors proposed a ML methodology to identify routing-based attacks in IoT networks. A custom attack dataset is generated with essential features such as node power levels and spatial location using the Contiki Cooja simulator. The research showed greater performance by RF classifier, which yielded 99.33% accuracy12. This study represents MC-GRU, an innovative IDS joining CNN along with GRU for improving attack detection in WSNs. Here, CNN layers extract deep network traffic patterns whereas GRU captures temporal and spatial patterns in the data13. This study suggests an IDS for WSNs which combines C5.0 classifiers with bi-directional Long Short Term Memory (LSTM) networks. The method starts with optimal feature selection using information gain and later a multi-correlation analysis algorithm is applied to transform features into a TAM matrix. Further, the TAM matrix is processed by LSTM to achieve better accuracy14. A systematic literature review is performed to analyze various DL-based IDS. Relevant studies from 2010 to 2020 were selected using specific keywords and evaluated to identify the research gaps. This review is performed mostly on older datasets15. SLGBM is developed that integrates Sequence Backward Selection (SBS) algorithm with LightGBM classifier. Data dimensionality reduction is performed by SBS prior to the process of classification for improving the efficiency. The model delivered f1_score of 99.8% for normal attack and accuracy of 99.4% and 99.1% for Blackhole and Grayhole attacks respectively16. A DL based Defense Mechanism (DLDM) is suggested for detection and isolation of attacks in WSNs. DL techniques enable detection at a low computational cost within the lightweight framework to boost cluster-based security measures against two major DoS attack forms: exhaustion and flooding. The simulation results show detection rates ranging from 86% to 99% with false alarming at an average of 15%17. The proposed methodology integrates SMOTE + RF for addressing class imbalance in the selected dataset. The application of SMOTE on the minority classes helps in balancing the dataset before using it for training the RF classifier. This combination enhanced the classification accuracy reaching 92.57% when applied to the KDD Cup’99 dataset18. A Deep Belief Network (DBN) integrated with Genetic Algorithm (GA) is proposed for efficient ID. The GA efficiently tunes DBN structure by selecting optimal hidden layers and neuron counts. The model simplifies the network design while enhancing the accuracy across various attack types19. A hybrid model that develops the clusters using Restricted Boltzmann Machine (RBM) is developed and implemented. The RBM performs both the feature selection and classification for detecting normal or malicious attacks in WSNs. The results produced a strong performance indicating 99.12% rate of detection and 99.91% efficacy through three hidden layer configuration20. Although many ML and DL methods show considerable progress in ID of WSNs, there are a number of challenges which have to be addressed. Most of the current approaches are dependent on old datasets like the KDD Cup 99 and NSL-KDD, which reduce the ability to use them effectively against the contemporary and evolving forms of attacks. Also, some of the models have high computational overhead, low detection rate of rare attacks, and lack real-time adaptiveness. Most of the models also lack in balancing accuracy of attack identification and reduction of false alarm rate. To address the above gaps, the proposed methodology incorporates an optimization based hybrid detection model, which emphasizes on reducing false positives and enhancing the detection of minority class attacks. Table 1 epitomizes the various techniques, datasets used, their accuracy and limitations. Table 1Summary of the reported works in the literature.CategoryPaper / methodDataset(s)Accuracy / resultLimitationsDLDM17Deep LearningWS(Simulated)86%–99%detection rate,<15% false alarmsLimited to DoS(exhaustion,flooding); scalabilitynot testedSLGBM16SBS + LightGBMWSN-specificF_measure obtained:Normal-99.8%,Blackhole-99.4%,Grayhole-99.1%,Flooding–96.5%,Scheduling–96.1%Attack variety limited;may not generalizeto other networktypesMC-GRU13CNN + GRUWSN (Simulated)99.57% accuracyFocus on specificattacks;computational costunaddressedKGMS-IDS9Geometric SMOTE+ Autoencoder +EnsembleNSL-KDD, N-BaIoTAccuracy-86.39%for NSL-KDD,99.94% for N-BaIoTDependent onsyntheticoversampling;potential overfittingSFS-RF and RF-SFS-GRU6Random Forest+ RFECIC-IDS2018,UNSW-NB15, NSLUNSW_NB15 SFS-RF-78.52%Accuracy andRF-SFS-GRU - 79%AccuracyHigh dimensionality;lacks energy-aware designIDS-HML10Hybrid MLFrameworkNSL-KDD, UNSW-NB15, CICIDS2017Accuracy: 99.82%;Precision: 99.91%;F1_measure: 100%May require complextuning; olderdatasets usedNN-LEACH8Cluster-basedRouting ProtocolWSN (Simulated)5% energyreduction, improvedlifespanProtocol-level only;not an ML-based IDSSMOTE+RF18Oversampling+Random ForestKDD Cup 99Accuracy-92.57%Relies on outdateddataset; basic MLapproachC5.0 + Bi-LSTM14Feature Selection +Deep LearningKDD100, NSL-KDD,UNSW-NB15Accuracy: KDD100-99.91%,NSL-KDD-99.61%,UNSW-NB15-99.29%High complexity;limited scalabilityfor WSNsDBN + GA19Deep Belief Network+ Genetic AlgorithmNSL-KDDNot explicitly stated(claimed improvedaccuracy)Tuning complexity;limited datasetvariationRBC-IDS20Clustered RBMWSN dataset(Simulated)99.12% detectionrate,99.91%accuracyNot validated onlarge-scale or real-time WSNsAutoML + GPR11BayesianOptimization + GPRSimulated (k-barriermodel)R = 1, RMSE = 0.007Focused onprediction, not fullIDS implementationML-based Routing IDS12RF classifier onsimulated attack dataCooja/Contiki (IoT)99.33% accuracyNarrow scope;limited attack typesGNN-IDS21Graph AttentionNetworkNSL-KDD99.% accuracyNot discussedBS-GAT22Behaviour Similarity-Graph AttentionNetworkBoT-v2, ToN-v2BoT-v2-99%accuracy, ToN-v2–97.88% accuracyMulti-class scenariois unsatisfactory dueto lack ofcompleteness Table 1Summary of the reported works in the literature.CategoryPaper / methodDataset(s)Accuracy / resultLimitationsDLDM17Deep LearningWS(Simulated)86%–99%detection rate,<15% false alarmsLimited to DoS(exhaustion,flooding); scalabilitynot testedSLGBM16SBS + LightGBMWSN-specificF_measure obtained:Normal-99.8%,Blackhole-99.4%,Grayhole-99.1%,Flooding–96.5%,Scheduling–96.1%Attack variety limited;may not generalizeto other networktypesMC-GRU13CNN + GRUWSN (Simulated)99.57% accuracyFocus on specificattacks;computational costunaddressedKGMS-IDS9Geometric SMOTE+ Autoencoder +EnsembleNSL-KDD, N-BaIoTAccuracy-86.39%for NSL-KDD,99.94% for N-BaIoTDependent onsyntheticoversampling;potential overfittingSFS-RF and RF-SFS-GRU6Random Forest+ RFECIC-IDS2018,UNSW-NB15, NSLUNSW_NB15 SFS-RF-78.52%Accuracy andRF-SFS-GRU - 79%AccuracyHigh dimensionality;lacks energy-aware designIDS-HML10Hybrid MLFrameworkNSL-KDD, UNSW-NB15, CICIDS2017Accuracy: 99.82%;Precision: 99.91%;F1_measure: 100%May require complextuning; olderdatasets usedNN-LEACH8Cluster-basedRouting ProtocolWSN (Simulated)5% energyreduction, improvedlifespanProtocol-level only;not an ML-based IDSSMOTE+RF18Oversampling+Random ForestKDD Cup 99Accuracy-92.57%Relies on outdateddataset; basic MLapproachC5.0 + Bi-LSTM14Feature Selection +Deep LearningKDD100, NSL-KDD,UNSW-NB15Accuracy: KDD100-99.91%,NSL-KDD-99.61%,UNSW-NB15-99.29%High complexity;limited scalabilityfor WSNsDBN + GA19Deep Belief Network+ Genetic AlgorithmNSL-KDDNot explicitly stated(claimed improvedaccuracy)Tuning complexity;limited datasetvariationRBC-IDS20Clustered RBMWSN dataset(Simulated)99.12% detectionrate,99.91%accuracyNot validated onlarge-scale or real-time WSNsAutoML + GPR11BayesianOptimization + GPRSimulated (k-barriermodel)R = 1, RMSE = 0.007Focused onprediction, not fullIDS implementationML-based Routing IDS12RF classifier onsimulated attack dataCooja/Contiki (IoT)99.33% accuracyNarrow scope;limited attack typesGNN-IDS21Graph AttentionNetworkNSL-KDD99.% accuracyNot discussedBS-GAT22Behaviour Similarity-Graph AttentionNetworkBoT-v2, ToN-v2BoT-v2-99%accuracy, ToN-v2–97.88% accuracyMulti-class scenariois unsatisfactory dueto lack ofcompleteness Summary of the reported works in the literature. 86%–99% detection rate, <15% false alarms Limited to DoS (exhaustion, flooding); scalability not tested F_measure obtained: Normal-99.8%, Blackhole-99.4%, Grayhole-99.1%, Flooding–96.5%, Scheduling–96.1% Attack variety limited; may not generalize to other network types Focus on specific attacks; computational cost unaddressed Geometric SMOTE + Autoencoder + Ensemble Accuracy-86.39% for NSL-KDD, 99.94% for N-BaIoT Dependent on synthetic oversampling; potential overfitting SFS-RF and RF-SFS-GRU6 Random Forest + RFE CIC-IDS2018, UNSW-NB15, NSL UNSW_NB15 SFS- RF-78.52% Accuracy and RF-SFS-GRU - 79% Accuracy High dimensionality; lacks energy- aware design Hybrid ML Framework NSL-KDD, UNSW- NB15, CICIDS2017 Accuracy: 99.82%; Precision: 99.91%; F1_measure: 100% May require complex tuning; older datasets used Cluster-based Routing Protocol 5% energy reduction, improved lifespan Protocol-level only; not an ML-based IDS Oversampling +Random Forest Relies on outdated dataset; basic ML approach Feature Selection + Deep Learning KDD100, NSL-KDD, UNSW-NB15 Accuracy: KDD100-99.91%, NSL-KDD-99.61%, UNSW-NB15-99.29% High complexity; limited scalability for WSNs Deep Belief Network + Genetic Algorithm Not explicitly stated (claimed improved accuracy) Tuning complexity; limited dataset variation WSN dataset (Simulated) 99.12% detection rate,99.91% accuracy Not validated on large-scale or real- time WSNs Bayesian Optimization + GPR Simulated (k-barrier model) Focused on prediction, not full IDS implementation RF classifier on simulated attack data Narrow scope; limited attack types Graph Attention Network Behaviour Similarity- Graph Attention Network BoT-v2-99% accuracy, ToN-v2– 97.88% accuracy Multi-class scenario is unsatisfactory due to lack of completeness From Table 1, it is observed that various IDS solutions have been applied to resolve security concerns in WSNs including the scarcity of computational resources, topological dynamism and uneven distribution of attacks in the previous literature. Conventional ML based IDS offers lightweight detection but is not strong in capturing intricate relations amongst nodes and modifying attack patterns. IDS approaches that use anomalies are dynamic and can be used to adjust to changing attacks, however, they tend to have many false positives. Class imbalance techniques like SMOTE have been used when the sample sizes are uneven, but it has not been widely used with DL methods. The suggested OOA-GNN framework addresses such gaps through the use of GNN to model node interactions, OOA to optimize hyperparameters and features and the use of SMOTE to address the minority attack classes. The projected method is more accurate, robust, and efficient than the current techniques, which can be implemented in the real-time WSN setup. Proposed approach The proposed OOA-GNN based IDS is designed to boost the security of WSNs by integrating the OOA for feature selection and GNNs for classification. Although designed for continuous optimization, OOA is modified into binary variant, where the individuals represent a binary string (either 0 or 1). The fitness function evaluates each feature subset and includes a penalty term to discourage the selection of features that are redundant. This strategy leads OOA to explore the high dimensional feature space and choose the relevant features for effective detection of intrusion in WSNs. OOA efficiently selects the most informative features by mimicking the hunting and navigation behaviour of ospreys, using an adaptive search mechanism that enhances classification accuracy. Figure 1 depicts the proposed methodology’s architectural flow diagram. Fig. 1Flow diagram of the proposed methodology. Flow diagram of the proposed methodology. The suggested methodology is evaluated using the WSN-DS, which is a widely used benchmark for ID in WSNs. After the feature selection, the resulting dataset exhibits the class imbalance. Considering the imbalanced characteristic of the WSN-DS dataset, SMOTE resampling technique is used on the training dataset, where synthetic samples for minority classes are generated. The class distribution is balanced by interpolating between the existing minority classes for improving the classifier sensitivity. Most importantly, SMOTE is not applied to test data in order to avoid data leakage risk, evaluation bias and misinterpretation of generalization ability. The pre-processed data is then transformed into a graph representation in which each network event is treated as a node and edges represent relationships based on similarity metrics such as Euclidean distance or KNN. The structured graph is then processed using GNN, which captures spatial and temporal dependencies within the network. The trained OOA-GNN model is capable of classifying various categories of attacks with 99.68% accuracy, outperforming traditional ML models. The integration of graph-based learning with optimized feature selection provides an adaptive and robust approach to ID, making the system highly efficient in identifying complex cyber threats in WSN environments. Dataset representation The dataset has been obtained through Prince Sultan University, Saudi Arabia. The complete information related to the dataset features can be referred from23. WSN-DS is selected because it is the only dataset that captures actual communication properties of WSNs which are not simulated with conventional internet data (e.g. NSL-KDD, CICIDS2017). Thus, WSN-DS offers a more realistic simulation of sensor-level behaviour in normal attack conditions. Table 2 epitomizes the total number of samples under each attack category present in the dataset. Table 2Summary of the WSN-DS dataset.CategoryTotal numberof samplesNormal340,066Blackhole10,049Grayhole14,596Flooding3,312Scheduling6,638 Table 2Summary of the WSN-DS dataset.CategoryTotal numberof samplesNormal340,066Blackhole10,049Grayhole14,596Flooding3,312Scheduling6,638 Summary of the WSN-DS dataset. From Table 2 , it is observed that WSN-DS is an imbalanced dataset, where the number of samples in each category of classification differs. Let the intrusion detection dataset be denoted as expressed in Eq. (1). 1\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} D = \left\{ (x_1,y_1),(x_2,y_2),....(x_n,y_n) \right\} \end{aligned}$$\end{document} where \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$x_i = x_1, x_2,...x_n \in R_m$$\end{document} represents the feature vector of the \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$i^{th}$$\end{document} sample; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$R_m$$\end{document} denotes the m-dimensional feature vector of the \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$i^{th}$$\end{document} sample. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$y_i = y_1, y_2,...y_n \in \left\{ 0,1,2,3,....K\right\}$$\end{document} represents the category of attack. n and m denote the total number of samples and features respectively; K denotes the total number of distinguished attack categories. Data preprocessing (a) Data normalization: To avoid the instability in the network, the dataset has to be normalized for better acceleration and convergence along with imputation of missing values. For each missing feature \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$x_i^{(j)}$$\end{document},the mean of the respective feature is computed as represented in Eq. (2). 2\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} x_i^{(j)} = \frac{1}{n}\sum _{k=1}^{n}x_k^{(j)} \end{aligned}$$\end{document} Where j stands for feature index. The normalization of the dataset is carried out by Z-score normalization which is expressed in equation (3). 3\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} x_i^{(j)} = \frac{x_i^{(j)}-{\mu }_j}{\sigma _j} \end{aligned}$$\end{document} Where, the mean and the standard deviation of \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$j^{th}$$\end{document} feature is represented by \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\mu _j$$\end{document} and \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\sigma _j$$\end{document} respectively. Once the imputation and feature normalization is carried out, Synthetic Minority Oversampling technique is applied to convert the imbalanced dataset into a balanced dataset. This technique will generate the synthetic samples for minority classes using Eq. (4): 4\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} x_{new} = x + \delta \times (x_{neighbor}-x) \end{aligned}$$\end{document} where x represents the minority class sample; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\delta$$\end{document} denotes random scalar in the range of 0 to 1; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$x_{neighbor}$$\end{document} represents one of its k-nearest neighbours of same class; and the operation\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$(x_{neighbor}-x)$$\end{document} signifies the vector difference used to create a new synthetic instance. (b) Synthetic minority oversampling technique: To convert the dataset to be balanced, SMOTE is applied to 80% of the training dataset and 20% of the dataset remains the same. The detailed split-up of the samples under each attack category is given in Table 3. Table 3Summary of the WSN-DS dataset after SMOTE.CategoryOriginal trainingsamplesTraining samplesafter SMOTENumber of testingsamplesTotal samplesafter SMOTENormal272,052272,05268,014340,066Blackhole8,039272,0522,010274,062Grayhole11,676272,0522,920274,972Flooding2,649272,052663272,715Scheduling5,310272,0521,328273,380 Table 3Summary of the WSN-DS dataset after SMOTE.CategoryOriginal trainingsamplesTraining samplesafter SMOTENumber of testingsamplesTotal samplesafter SMOTENormal272,052272,05268,014340,066Blackhole8,039272,0522,010274,062Grayhole11,676272,0522,920274,972Flooding2,649272,052663272,715Scheduling5,310272,0521,328273,380 Summary of the WSN-DS dataset after SMOTE. Formation of graph neural network The GNN operates as a specific DL algorithm, which analyzes data configurations and it requires graph-based representations. Traditional ML algorithms work with structured data formats including tables and images, yet GNNs demonstrate superiority when processing complex systems containing both nodes and edges. The feature vectors pertaining to the above are represented as a graphical structure (G), as given in Eq. (5) 5\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} G = (V,E) \end{aligned}$$\end{document} Here, \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$V = \left\{ x_1,x_2,x_3,..x_n\right\}$$\end{document} where V denotes the nodes and\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\left\{ x_1,x_2,x_3,..x_n\right\}$$\end{document} denotes transformed feature vector; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$E\subseteq V \times V$$\end{document} denotes the edges based on the similarity; Adjacency matrix ‘A’ is computed using similarity thresholds ‘\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\theta$$\end{document}’ and is given in Eq. (6) 6\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} A_{ij} = {\left\{ \begin{array}{ll} 1, & \text {if } similarity(i,j) \ge \theta \\ 0, & \text {otherwise} \end{array}\right. } \end{aligned}$$\end{document} Here similarity(i, j) represents the similarity among the attack patterns. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$A_{ij}$$\end{document} captures the network topology that is utilized as the input to the GNN. The adjacency matrix \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$A_{ij}$$\end{document} represents the connections among sensor nodes and is calculated based on a similarity threshold \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\theta$$\end{document}. Particularly, \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$A_{ij}$$\end{document}= 1, when similarity of node i and j is more than \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\theta$$\end{document}, and \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$A_{ij}$$\end{document}= 0, otherwise. This matrix with a threshold value captures necessary details from the dataset which are fed to the GNN to learn inter-node dependencies that predict accurate attack detection. For each layer ‘l’ of GNN, the embedded nodes are updated using Eq. (7). 7\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} H^{(l+1)} = \sigma (D^{(-1/2)} AD^{(-1/2)}H^{(l)}W^{(l)}) \end{aligned}$$\end{document} where \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$H(l+1)$$\end{document} denotes the updated matrix at layer \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$(l+1)$$\end{document}; Aij is the adjacency matrix; D is the degree matrix; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$W^{(l)}$$\end{document} are trainable weight matrices; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\sigma$$\end{document} is an activation function (ReLU) and \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$H^{(0)} = X$$\end{document}. The final embedding after L layers is represented by Eq. (8). 8\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} Z = H^{(L)} \end{aligned}$$\end{document} where \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$H^{(L)}$$\end{document} is the final embedded node after ‘L’ GNN layers; Z is the output matrix used for classification of nodes. Optimizing using Osprey Optimization Algorithm The OOA takes its inspiration from osprey wildlife behaviour to solve optimization problems. OOA implements the natural phases of searching, diving and capturing to find balance between exploration and exploitation, thus attaining effective global optimization.OOA offers adaptive parameter control and global search which is better than the conventional PSO or GA. This is due to its dynamic movement strategy and selective predation behaviour, which can allow it to explore well and not get stuck in local minima. Due to its ability to adapt and converge successfully, OOA demonstrates effectiveness when resolving complicated optimization problems which include feature selection and hyperparameter tuning tasks. The ensemble classifier weights \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\alpha = [\alpha _1,\alpha _2,\alpha _3,...,\alpha _n ]$$\end{document} are tuned by OOA. The objective function helps in minimizing the weighted ensemble loss, which is given in Eq. (9). 9\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} \displaystyle \min _{\alpha }L_{ensemble}=\frac{1}{N}\sum _{j=1}^{N}L\left( y_{i},\sum _{k=1}^{n}\alpha _kf_k(x_i) \right) \end{aligned}$$\end{document} subjected to \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\sum _{k=1}^{n}\alpha _k =1$$\end{document}, where \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\alpha _k \ge 0$$\end{document}. Where N is total number of training samples; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$y_i$$\end{document} and \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$x_i$$\end{document} are the true label and feature vector of \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$i^{th}$$\end{document} sample respectively; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$f_k(x_i)$$\end{document} is the prediction of the base classifier; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\alpha _k$$\end{document} is the weight assigned to classifier; n is the number of base classifiers; L(yi, (.)) is the loss function; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$L_{ensemble}$$\end{document} is the overall loss of the model across the training samples. Ensemble model and prediction The ensemble prediction \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\hat{y}$$\end{document} is computed as expressed in Eq. (10): 10\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\begin{aligned} \hat{y} = arg \displaystyle \max _{c}\sum _{k=1}^{n}\alpha _kp_k(c|x) \end{aligned}$$\end{document} where \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\hat{y}$$\end{document} denotes predicted class label for input sample x; c denotes the candidate class label; \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$p_k(c|x)$$\end{document} is the probability of class c from the \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$k^{th}$$\end{document} cluster and \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\alpha _k$$\end{document} is the optimized weight for classifier. Pseudocode of the proposed model: OOA-GNN with SMOTE balancing Begin 1. Load dataset \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$D(WSN-DS)$$\end{document} \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Read the full dataset with all labelled categories 2. Preprocess Dataset \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Handle missing values using mean imputation. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Normalize/standardize the features (e.g., using Z-score). 3. Split dataset D into training set D_train and testing set D_test (80/20) \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Apply stratified sampling to preserve class proportions. 4. Apply SMOTE on D_train: \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Use SMOTE to generate synthetic samples for minority classes. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Display class distribution after balancing. 5. Initialize OOA (Osprey Optimization Algorithm) parameters: \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Set number of individuals (population size). \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Set maximum number of iterations (e.g., 20). \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Define binary representation for feature selection. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Define fitness function based on classification performance. 6. Perform feature selection using OOA: \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Evaluate fitness of each feature subset using GNN performance. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Select optimal subset of features for classification. 7. Transform selected features into graph structure: \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Represent each instance as a node. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Create edges based on similarity (e.g., Euclidean distance or kNN). 8. Train GNN model on SMOTE-balanced D_train with selected features. 9. Evaluate GNN on D_train: \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Compute confusion matrix. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Calculate training accuracy, specificity, sensitivity, F1_score and AU-ROC 10. Evaluate GNN on D_test (untouched test data): \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Compute confusion matrix. \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\rightarrow$$\end{document} Calculate testing accuracy, loss, precision, recall, F1_score, and AU-ROC. 11. Compare performance with traditional classifiers. End Computational environment The proposed model was simulated using Python integrated with Intel Cloud Console installed on 12th Gen Intel(R) Core (TM) i7-12700H, 2.30 GHz, 16 GB RAM, and 1 TB HDD. The input parameters for OOA and GNN are listed here. For OOA: population size – 30; number of iterations - 50; exploration and exploitation rate – 0.5; convergence_threshold – 1e-5; evaluation (fitness) function – accuracy / loss function; velocity update – custom (based on the osprey flight behaviour model). For GNN: input_dim – 50; number of neurons in hidden layer – 64; output_dim – 5; num_layers (GNN) – 3; learning rate – 0.001; batch_size – 128; epochs – 50; activation function – ReLU; optimizer – Adam; loss_function – CrossEntropyLoss. With the assigned values, the proposed OOA-GNN technique classified the attacks more efficiently than the other reported models. In order to avoid overfitting, stratified sampling technique was utilized to subdivide the dataset as training (80%) and testing (20%) sets. The OOA-GNN hyperparameters were only tuned on the training folds and 5-fold cross-validation was done while training phase. Dropout (rate = 0.3) and early stopping were used to regularize it. Results and discussion This section represents and analyzes the performance outcomes of suggested OOA-GNN applied to the WSN-DS dataset. The experiments were conducted to assess the system’s capability to detect various routing attacks in WSNs under class imbalance conditions. Key assessment measures like accuracy, specificity, sensitivity, f1_score, confusion matrix and AU-ROC were utilized to validate the efficacy of the projected methodology. The model’s performance is further contrasted against several baseline ML classifiers to establish its superiority with regard to detection capability and computational efficiency.Table 4 displays the outcome of the suggested method on training and testing sets. Table 4Outcome of the proposed classifier (OOA-GNN) on training and testing dataset.CategoryAccuracySensitivitySpecificityF1_scoreAU-ROCTraining set Normal99.2799.2799.5499.6499.45 Grayhole99.6598.5699.6596.4599.32 Blackhole99.7098.5499.7895.7699.23 Flooding99.8796.7899.6792.4597.87 Scheduling99.8697.9599.8393.5698.95Testing set Normal99.1899.1899.3499.5699.42 Grayhole99.6898.8699.7896.6599.87 Blackhole99.7598.6599.5495.8799.56 Flooding99.8395.7699.8787.5697.67 Scheduling99.5597.8799.7893.9798.95 Table 4Outcome of the proposed classifier (OOA-GNN) on training and testing dataset.CategoryAccuracySensitivitySpecificityF1_scoreAU-ROCTraining set Normal99.2799.2799.5499.6499.45 Grayhole99.6598.5699.6596.4599.32 Blackhole99.7098.5499.7895.7699.23 Flooding99.8796.7899.6792.4597.87 Scheduling99.8697.9599.8393.5698.95Testing set Normal99.1899.1899.3499.5699.42 Grayhole99.6898.8699.7896.6599.87 Blackhole99.7598.6599.5495.8799.56 Flooding99.8395.7699.8787.5697.67 Scheduling99.5597.8799.7893.9798.95 Outcome of the proposed classifier (OOA-GNN) on training and testing dataset. For the testing set, accuracy obtained for all categories of attacks is more than 99%, sensitivity ranges between 95% to 97%, specificity is more than 99%, and f1_score is more than 90% except flooding which stands at 87%. This confirms that SMOTE improved minority-class representation without bias toward majority classes.These findings prove that the proposed approach generates balanced sensitivity and accuracy between classes, which means that SMOTE successfully helped in reducing imbalance without introducing overfitting and over-representation of majority classes. Fig. 2Comparison of performance metrics on training data. Comparison of performance metrics on training data. Fig. 3Comparison of performance metrics on testing data. Comparison of performance metrics on testing data. Figures 2 and 3 compares the training and testing performance of the projected OOA-GNN model across five attack categories using four key evaluation metrics namely, accuracy, sensitivity, specificity, and f1_score. The model exhibits consistently high accuracy and specificity (>99%) for both training and testing datasets, indicating strong classification capability and low false positive rates. Although f1_score and sensitivity are slightly lower for flooding and blackhole attacks, they still remain above 87%, reflecting balanced specificity and sensitivity. The close alignment between training and testing bars across all metrics suggests minimal overfitting, demonstrating the model’s strong generalization capability on unseen data. Fig. 4Confusion matrix of training data by OOA-GNN. Confusion matrix of training data by OOA-GNN. During OOA-GNN training, the confusion matrix reveals the detailed assessment of attack classification as shown in Fig. 4. The training phase of the model shows results with exceptional accuracy because majority of the predictions fall on the diagonal parts of the matrix which demonstrate proper classification. The algorithm succeeded in classifying 272,058 normal samples while mistakenly detecting 13 cases as blackhole attacks from the entire sample set. The predictions regarding flooding attacks and blackhole attacks were accurate in 271,705 and 271,861 cases although 49 instances of blackhole attacks were misidentified as normal attack. Total misclassifications for grayhole attacks amounted to 5 normal samples and 240 flooding cases along with 196 blackhole and 87 scheduling attacks. 88 scheduling attack samples were incorrectly predicted as grayhole attacks according to the model analysis. The OOA-GNN model effectively captures the distinctive characteristics of each attack type, as evidenced by the confusion matrix, demonstrating low predictive errors. Fig. 5Confusion Matrix of testing data by OOA-GNN. Confusion Matrix of testing data by OOA-GNN. The confusion matrix for the model during the testing phase as depicted in Fig. 5, demonstrates exceptional capability in accurately detecting various intrusion types under unseen data. The matrix reveals that the majority of the instances were classified correctly, as indicated by the dominant diagonal values. Specifically, 67,991 normal traffic samples were rightly identified, with only 4 instances incorrectly classified as blackhole attacks. Likewise, 68,360 flooding attacks were accurately detected, with just a single misclassification as a grayhole attack. The model successfully predicted 68,120 blackhole attacks, with only 36 samples misclassified as normal attacks. Grayhole attacks show slightly higher misclassification rates, with 65 instances misclassified as flooding, 79 as blackhole, and 55 as scheduling attacks. For the scheduling attack class, 67,851 instances were correctly classified, with a minimal misclassification of 145 samples as grayhole attacks and 1 as normal. The low rate of misclassification across all categories confirms the model’s capability to well generalize unseen data, ensuring reliable ID with high precision and minimal errors during deployment. Table 5Comparison of OOA-GNN with other reported models.Models / methodsAccuracySensitivitySpecificityF1_scoreOOA-GNN (proposed)99.6898.0199.7394.56BCOA-MLID399.6397.9199.6794.52AdaBoost2495.6995.7795.0090.31GB Model2494.5895.2594.0993.31XGBoost2496.8396.1094.4391.52KNN-AOA2597.2096.4996.3490.23KNN-PSO2592.8995.6395.0892.99 Table 5Comparison of OOA-GNN with other reported models.Models / methodsAccuracySensitivitySpecificityF1_scoreOOA-GNN (proposed)99.6898.0199.7394.56BCOA-MLID399.6397.9199.6794.52AdaBoost2495.6995.7795.0090.31GB Model2494.5895.2594.0993.31XGBoost2496.8396.1094.4391.52KNN-AOA2597.2096.4996.3490.23KNN-PSO2592.8995.6395.0892.99 Comparison of OOA-GNN with other reported models. Table 5 explains different ML and optimization-based models which perform ID in WSNs. A total of four main performance measures namely, accuracy, sensitivity, specificity and f1_score are considered for assessment of the models. OOA-GNN proves itself to be the most effective ID method through its highest accuracy of 99.68%, f1_score of 94.56%, sensitivity of 98.01% and specificity of 99.73%, which indicate its remarkable capacity to detect attack and normal instances with balanced metrics performance. The BCOA-ID method adheres closely to OOA-GNN by achieving 99.63% accuracy, strong sensitivity and specificity values thus warranting its position as an effective ID solution. The performance metrics from traditional ML models including AdaBoost, GB Model, XGBoost, KNN-AOA, and KNN-PSO performed at lower levels than other models. The AdaBoost delivers 95.69% accuracy and GB Model reaches 94.58% accuracy, while their f1_scores stay below 94%, which demonstrate weaker reliability and robustness than optimization-driven and DL-based approaches. The accuracy of KNN-PSO is 92.89% and f1_score is 92.99%, which indicates competence in specific classification tasks. Optimization frameworks like OOA-GNN and BCOA-ID provide the most beneficial detection outcomes in sophisticated intrusion scenarios, because these systems outperform traditional classifiers with improved accuracy and other performance metrics. Table 6Comparison of computational time by OOA-GNN and reported models.ModelComputational time (s)BCOA-MLID37.26AdaBoost2415.65GB Model2412.75GXGBoost241.905XGBoost2413.67KNN-AOA25Not reportedKNN-PSO25Not reportedOOA-GNN (proposed)204 Table 6Comparison of computational time by OOA-GNN and reported models.ModelComputational time (s)BCOA-MLID37.26AdaBoost2415.65GB Model2412.75GXGBoost241.905XGBoost2413.67KNN-AOA25Not reportedKNN-PSO25Not reportedOOA-GNN (proposed)204 Comparison of computational time by OOA-GNN and reported models. From Table 6, it is noticed that the total computational time of the suggested OOA-GNN model was around 204 seconds (3.4 minutes) on training set and processed 10,000 test samples in about 0.2 seconds. This is high when compared to the existing models, but this is explained by the fact that it is a two-stage framework. The first step of the model is feature selection by OOA, followed by learning based on graphs with a GNN. These measures, although computationally expensive, are quite helpful in improving detection, robustness and generalization of the model in complex WSN settings. The computational time was reported on a standard Intel i7 with 16 GB RAM and without any form of GPU acceleration. This increased training cost is offset by lightweight inference phase which only takes a fraction of a second to perform classification and the model can be utilized in real-time or near-real-time ID when deployed. Overall, the computational time is slightly higher, and it is a reasonable trade-off against considerable gains in performance related to detection accuracy, reduction of false-positives and stability under network conditions. In real-time WSN deployment, the OOA-GNN model can operate at the sink node or gateway, where features are aggregated from distributed sensors. This architecture reduces per-node computation to simple data forwarding, thereby conserving energy. In addition, the proposed OOA-GNN model was statistically validated to ensure the consistency of its performance in different runs. The model was run five times with varying random inputs leading to the computation of mean and standard deviation of the accuracy and f1_score. As the other baseline models BCOA-ID3, GB Model24, AdaBoost24, XGBoost24, KNN-AOA and KNN-PSO25 were considered from previously reported articles, experimental data is unavailable for statistical test. As an alternative, comparative analysis was done using their reported mean performance metrics. The OOA-GNN with a low variance (± 0.09% in accuracy & ± 0.11% in f1_score) between all runs resulted in consistent and statistically significant outputs. These results along with the steady improvement over the reported baselines prove that the observed improvements are statistically significant and not attributed to random fluctuations. The comparative analysis of the proposed model’s performance against other reported models is shown in Fig. 6. Fig. 6Performance comparison of OOA-GNN with other reported models. Performance comparison of OOA-GNN with other reported models. Conclusion This study proposes the OOA-GNN as an effective and strong intrusion detection model of the WSNs. The GNN can identify different types of attacks on WSNs with high accuracy by incorporating the OOA to optimize its features and hyperparameters. The OOA-GNN model has been shown to achieve high testing accuracies of over 99%, high sensitivity, specificity and f1_score using extensive testing on the WSN-DS dataset and is better than conventional and optimization-based classifiers including AdaBoost, GB Model, BCOA-ID, GXGBoost, XGBoost and KNN. These findings are an indication that the model is efficient in countering key problems in the intrusion detection field such as imbalance of data, dynamic traffic patterns, and redundancy of features. The suggested OOA-GNN design is scalable, adaptable and energy-efficient, which is applicable in the real-world deployment of WSN in critical infrastructure. It has an effective learning mechanism that has improved its resistance to changing network attacks, besides optimization-based training that guarantees low false alarms and high generalization. Further, the current study can be extended in several directions in the future. One of these directions is the integration of real-time adaptive learning mechanisms, that enables the IDS to dynamically redefine the boundaries of its decisions when new attack patterns appear. Alternatively, it is also possible to research lightweight variants of GNN or attention-based graph models to decrease computational complexity even more, allowing the deployment to edges or sensor level. Also, decentralized WSN settings may enhance privacy and security of data by incorporating federated or distributed learning methods. To increase the applicability of the model in wide-range networks and mission-critical networks, it is also possible to investigate multi-objective optimization strategies to trade energy consumption, latency and detection accuracy. The suggested OOA-GNN framework will provide an efficient and effective resolution to the protection of WSNs that will serve as the basis of building next-generation intelligent and autonomous security systems. It can be anticipated that the findings and recommendations made in this study will shape future work towards developing adaptive, energy-aware, scalable intrusion detection systems in future IoT and sensor-driven environments.