Robust graph comparative learning method and system for traffic adversarial attack of Internet of Vehicles
By combining locality-sensitive hashing and dual-memory, the problems of graph structure quality and semantic relationships in the Internet of Vehicles are solved, the robustness and discriminative ability of the model are improved, and effective defense against adversarial attacks is achieved.
Patent Information
- Application Number
- CN202511638610.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-10
- Publication Date
- 2026-02-03
AI Technical Summary
Existing technologies cannot effectively address the issues of low graph structure quality and lack of consideration for semantic relationships between samples in the Internet of Vehicles, resulting in insufficient robustness and discriminativeness of the model when facing adversarial attacks.
By filtering neighbors using the locality-sensitive hashing algorithm and calculating the optimal number of neighbors using one-dimensional structural entropy, a robust optimized graph structure is constructed. Furthermore, a hard example mining method based on dual memory and class prototype alignment based on low-rank decomposition are employed to enhance the robust embedding representation of the model.
It improves the model's robustness and discriminative ability in the face of adversarial attacks, significantly enhances the security and robustness of the vehicle-to-everything (V2X) system, and can effectively defend against attacks in complex environments.
Smart Images

Figure CN121457514A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a robust graph contrastive learning method and system for combating traffic attacks in the Internet of Vehicles (IoV), belonging to the fields of graph representation learning and network security technology. Background Technology
[0002] The Internet of Vehicles (IoV), as a core pillar of intelligent transportation systems, achieves unprecedented traffic efficiency and convenience by connecting vehicles, roadside units, mobile devices, and cloud platforms. However, this highly interconnected and dynamically changing architecture inherently brings significant security risks. IoV systems handle massive and heterogeneous data flows, including real-time sensing data, control commands, and location information. Once subjected to cyberattacks (such as denial-of-service attacks, data tampering, and malicious injection), it could lead to traffic system paralysis, privacy breaches, and even endanger lives.
[0003] Traditional cybersecurity measures, primarily relying on signature-based matching, struggle to address the rapidly evolving and mutating zero-day attacks and low-frequency, covert anomalies in the IoV (Internet of Vehicles) environment. To overcome these limitations, researchers have begun incorporating machine learning and deep learning techniques into anomaly detection for IoV traffic, aiming to achieve data-driven intelligent defense. Deep learning models demonstrate significant advantages in handling the high-dimensionality, temporal dependencies, and non-linear characteristics of IoV traffic data. In particular, graph neural networks (GNNs) can abstract the complex interactions between vehicles, RSUs (Remote Service Units), and base stations into a graph structure, effectively capturing deep spatial and temporal relationships between nodes. This is crucial for detecting collaborative or propagation-based attacks.
[0004] Despite the superior performance of deep learning models, they face new challenges in real-world adversarial environments of IoV (Internet of Vehicles): malicious attackers can subtly contaminate raw network traffic data by constructing tiny, imperceptible perturbations (i.e., adversarial examples). These examples appear harmless to the human eye or traditional defense mechanisms, but can effectively deceive deep learning models deployed in connected vehicles, causing detectors to output incorrect judgments with extremely high confidence. This attack pattern not only directly undermines the reliability of the model's decisions but also significantly diminishes the practical deployment value and credibility of deep learning-based intelligent safety systems.
[0005] There are many studies on effective defense measures against the above adversarial attacks. These are mainly divided into three categories: (1) active defense methods; (2) passive defense methods; and (3) methods to improve the inherent robustness of the model. Active defense methods, such as adversarial training, enhance the robustness of the model against known attacks by integrating adversarial samples or their variants during the training process. Passive defense methods, such as adversarial sample detection, establish an external detection mechanism to determine whether an input sample is adversarial. Unsupervised learning-based methods design defense methods that can directly detect attackers based on unsupervised learning. (3) Methods to improve the inherent robustness of the model, such as Graph Contrastive Learning (GCL), aim to generate stable features that are invariant to perturbations by redesigning the model's learning objectives and representation mechanisms.
[0006] However, all of the above methods have shortcomings. First, active defense methods suffer from high training costs and limited generalization ability to unknown attacks, and may also impair model performance on clean data. Second, passive defense methods rely on predefined attack features, making them easily evaded by adaptive attackers. Furthermore, robustness enhancement methods based on GCL typically operate on a pre-given graph structure, which is insufficient to capture complex interaction patterns embedded in network traffic data. The quality of the graph structure heavily depends on the edge connection strategy. Most current methods construct adjacency matrices based on similarity and distance metrics, which cannot dynamically adjust edge connections according to the actual distribution of the data. Simultaneously, existing GCL methods perform random sampling when selecting negative samples, ignoring the inherent semantic relationships between samples. This can lead to semantically similar instances being incorrectly classified as negative samples, thus weakening the model's ability to learn discriminative representations. Summary of the Invention
[0007] The purpose of this invention is to solve the problems of low graph structure quality and lack of consideration for semantic relationships between samples in the prior art.
[0008] To achieve the above objectives, the first aspect of the present invention discloses a robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) network, characterized by comprising: Based on the pre-screened neighbor results and one-dimensional structural entropy of the provided data, the optimal number of neighbors for the provided data is calculated. Based on the optimal number of neighbors, local linear reconstruction is used to calculate the neighbor weights and construct a robust optimization graph structure. Based on the robust optimization graph structure, a hard example mining method based on dual memory is adopted, and the robust embedding representation of the model is enhanced by class prototype alignment through low-rank decomposition.
[0009] Furthermore, the step of calculating the optimal number of neighbors for the provided data based on the pre-screened neighbor results and the one-dimensional structural entropy includes: Based on the Locality Sensitive Hashing (LSH) algorithm, a k-NN graph is constructed using the candidate neighbor set provided with the data. The one-dimensional structural entropy is then calculated, and the k value with the minimum structural entropy is selected as the final optimal number of neighbors. Here, the optimal k value is k... * The options are as follows:
[0010] In the formula: H(G) k ) is a k-NN graph G k One-dimensional structural entropy; V is the k-NN graph G k The set of all nodes; d i It is the degree of node i; vol(G) k ) is a k-NN graph G k The sum of the degrees of all nodes.
[0011] Furthermore, the candidate neighbor set for providing data obtained according to the locality-sensitive hashing algorithm includes: A single hyperplane hash function is defined according to the following formula:
[0012] In the formula: x i It provides data, which is a high-dimensional data vector; r is a random normal vector, independently sampled from the standard normal distribution, used to define the random hyperplane; Based on the provided data and α independent random hyperplane hash functions h concatenated, a single LSH signature function is obtained:
[0013] In the formula, It is the j-th locality-sensitive hash function. It is the α-th random hyperplane hash function; Based on the LSH enhancement mechanism, and combining L independent families of LSH hash functions (j=0 to L), L LSH signatures are obtained. Each LSH signature is used to build a separate hash table:
[0014] In the formula, G is the set of hash functions; Based on L LSH signatures The mapping result yields the key value of the data point in the j-th hash table, and provides the data x. i Stored to the corresponding key-value pair The data index is constructed within the hash bucket it points to.
[0015] In the formula: T j It is the j-th hash table; It is T j Corresponding key The hash bucket it points to is a data set; it provides data x. i Stored in L hash tables T j middle; Based on the hash of the data index obtained by the Locality Sensitive Hash algorithm, and the retrieval of candidate neighbors:
[0016]
[0017] In the formula: C is the query hash code; C is the union of the contents of all hash buckets pointed to by the corresponding query hash code in L tables. This indicates that the key in the j-th hash table is... All data points in the bucket; Calculate the provided data x using the formula below. i Calculate the exact distance to each data vector in the candidate set C, and select the k closest points:
[0018]
[0019] In the formula, x j It is the j-th data vector in the candidate set C.
[0020] Furthermore, the step of calculating neighbor weights and constructing a robust optimization graph structure based on the optimal number of neighbors using local linear reconstruction includes: According to the provided data x i The optimal k * Given 10 nearest neighbors, optimize the following problem to obtain the optimal weights of edges in a robust optimization graph:
[0021]
[0022] In the formula: λ is the regularization parameter; , It is x i of A set of nearest neighbors; w ij It is made by x j Point to x i The weight of the directed edge; w i It is composed of various w ijThe vector formed, i.e., x i The reconstructed weight vector; Robust optimization of edge weights in a graph This is the analytical solution obtained from the above optimization problem, and its analytical solution form is as follows:
[0023] In the formula: It is the local covariance matrix of the differences between neighbors. It is the neighbor difference matrix, which consists of all neighbors x j With center point x i The difference vectors between them are used to form the matrix; I is the identity matrix; 1 is a matrix of all ones.
[0024] Furthermore, the step of strengthening the robust embedding representation of the model by employing a hard example mining method based on a dual-memory library according to the robust optimization graph structure and by aligning class prototypes through low-rank decomposition includes: Based on the adjacency matrix of the robust optimization graph structure, edge perturbation data augmentation is performed on the robust optimization graph structure:
[0025] In the formula: A is the perturbed adjacency matrix; A0 is the initial adjacency matrix of the robust optimization graph. ; It is an XOR operation; T is the perturbation matrix. ; Integrated adversarial enhancement is performed on the feature matrix X of the robust optimized graph structure:
[0026] In the formula, x i It is the i-th eigenvector in the eigenmatrix X. ; It is the perturbed eigenvector; It is an adversarial perturbation generated by an adversarial attack algorithm; Based on two views, one after perturbation data augmentation and the other after integrated adversarial augmentation. and The embedding representation of the two views is calculated using the following formula:
[0027] In the formula: This represents the embedding representation of node i in the (l+1)th layer of the GAT model; K is the number of attention heads; It is the normalized attention coefficient; W k It is the feature transformation weight matrix of the k-th head; The embedding representation of node j at layer l; It is a node The set of neighbors.
[0028] Furthermore, after strengthening the robust embedding representation of the model by employing a hard example mining method based on a dual-memory library according to the robust optimization graph structure and by class prototype alignment through low-rank decomposition, the method further includes: The method involves embedding two views of the same node using two enhancement operations based on the embedding representation of the two views, pairing them to form a positive sample pair, thereby obtaining all positive sample pairs for comparison. Based on the embedded representations of the two views, apply a first-in-first-out update strategy to update the short-term memory for each category providing data, and also update the long-term memory:
[0029] Where: μ batch It is the average embedding representation of samples belonging to this category in the current batch; μ old It is a historical average embedding representation; η is a momentum coefficient used to balance the influence of historical information and current batch information; Based on the short-term memory bank and the long-term memory bank, for category c i Positive anchor point sample z i Negative samples are selected from all other categories according to a preset ratio. Samples are taken from the short-term and long-term memory banks to form a negative sample pool. .
[0030] Furthermore, based on the negative sample pool of all classes other than the true class of the current positive anchor sample, the following similarity calculation formula is applied to calculate the Top-M cross-class difficult negative samples:
[0031] In the formula, Represents vector z i and z n dot product between and Then they represent vectors z respectively i and z n The Euclidean norm.
[0032] Furthermore, based on the constructed positive and negative sample pairs, a supervised contrastive loss function is constructed. Category prototype alignment loss function and regularization loss function The final loss function is adopted. Pre-train the GAT model and optimize the model embedding representation:
[0033] In the formula, , and These are the weight values corresponding to the loss, where: The supervised contrastive loss function is defined as:
[0034]
[0035] In the formula: Indicates batch size; and This represents the embedding vector of the i-th node in two different views; This indicates that the true category c is excluded. i A collection of categories; This refers to node i and relative to category c. i The set of difficult negative samples; M is the number of difficult negative samples in each category; n g τ is the embedding vector of the hard negative sample; τ is the temperature parameter. The category prototype alignment loss function is defined as:
[0036] In the formula: This represents one of two different enhanced views; It is a category The low-rank prototype vector; c i It is the true category of node i; The regularization loss function is defined as:
[0037] In the formula: I R yes The identity matrix; It is the squared Frobenius norm; U and V are matrices after low-rank decomposition.
[0038] Furthermore, based on the embeddings of the long short-term memory (LSM) database, the mean of the corresponding memory database is calculated. and :
[0039]
[0040] In the formula: and This represents the number of currently valid entries for category c in both short-term and long-term memory; 0 m Represents an m-dimensional zero vector; and These represent the i-th and j-th values of category c stored in the short-term memory and long-term memory, respectively. Based on the gating value, the fusion prototype P of category c is calculated by weighted summation. c :
[0041] In the formula, It is the gate value, P c It is the c-th column vector of the prototype matrix P of all classes, where the gating value is defined as:
[0042] In the formula, and These are learnable parameters, where σ represents the Sigmoid activation function; The prototype matrix P of all categories is decomposed into a low-rank form using the following formula:
[0043] In the formula, U is the factor matrix and V is the coefficient matrix; Instead of using P, we use the decomposed U and V to represent the category prototypes and calculate the prototype alignment loss, which reduces computational complexity.
[0044] The second aspect of this invention discloses a robust graph contrastive learning system for combating traffic attacks in the Internet of Vehicles (IoV) network, used to implement the above-mentioned method, characterized in that the system comprises: The optimal nearest neighbor selection module is used to calculate the number of optimal neighbors of the provided data based on the pre-screened neighbor results and the one-dimensional structural entropy. The local reconstruction graph construction module is used to calculate the neighbor weights and construct a robust optimization graph structure based on the optimal number of neighbors using local linear reconstruction. The robust embedding enhancement module is used to enhance the robust embedding representation of the model by adopting a hard example mining method based on a dual memory bank according to the robust optimization graph structure and by class prototype alignment through low-rank decomposition.
[0045] This invention provides a robust graph contrastive learning method and system for defending against adversarial attacks on vehicle network traffic. By constructing a high-quality graph structure and GCL negative samples, this invention achieves a balance between model robustness and feature discriminativeness while resisting adversarial attacks. This significantly improves the robustness and security of the system in complex vehicle network intrusion detection environments. Compared with existing technologies, this invention can maintain the robustness and discriminative ability of the model embedding representation in the presence of adversarial traffic attacks, and can also enhance the quality of feature representation by combining short-term and long-term trend prototype alignment mechanisms. This effectively overcomes the various shortcomings of existing technologies and has high industrial application value. Attached Figure Description
[0046] Figure 1 The diagram shown is a schematic diagram of the comparative learning architecture in one embodiment of the present invention; Figure 2 This is a schematic diagram illustrating the adversarial attack in the vehicle networking system architecture of one embodiment of the present invention; Figure 3 The diagram shows a flowchart of a robust graph comparison learning method for combating traffic attacks in the Internet of Vehicles, as disclosed in an embodiment of the present invention. Figure 4 The diagram shown is a schematic diagram illustrating the principle and structure of a robust graph comparison learning method for combating traffic attacks in the Internet of Vehicles (IoV) as disclosed in an embodiment of the present invention. Figure 5 This is a schematic diagram illustrating the category prototype alignment enhancement contrastive learning process in one embodiment of the present invention; Figure 6 The diagram shown is a schematic representation of the principle structure of the robust graph comparison learning system for combating traffic attacks in the Internet of Vehicles (IoV) according to the present invention. Detailed Implementation
[0047] The present invention will be further illustrated below with reference to specific embodiments. It should be understood that these embodiments are for illustrative purposes only and are not intended to limit the scope of the invention. Furthermore, it should be understood that after reading the teachings of this invention, those skilled in the art can make various alterations or modifications to the invention, and these equivalent forms also fall within the scope defined by the appended claims.
[0048] Figure 1As shown, in one embodiment of the present invention, the dense and complex interactive characteristics of the vehicle-to-everything (V2X) system allow for a more effective capture of the intrinsic connections and deep semantics between V2X traffic by representing their relationships in the form of a graph structure. Graph contrastive learning learns robust and discriminative node representations by maximizing the consistency of positive sample pairs (i.e., representations with the same underlying identity or semantics but from different views) under different views, while minimizing the consistency with negative sample pairs. Graph neural network encoders are applied to G1 and G2 respectively to obtain their respective node representations. The model forces the representations learned by these two views to align and corroborate each other. Ultimately, these representations integrate multi-dimensional information from physical connections, logical relationships, and high-level semantics, effectively resisting noise or minor perturbations in a single view. Therefore, this cross-view contrastive learning method effectively resists noise or minor perturbations in a single view, making the learned representations more stable and generalizable. It not only accurately captures the intrinsic connections between V2X entities but is also a powerful tool for processing large-scale, dynamic, and heterogeneous V2X data.
[0049] While graph contrastive learning can enhance model robustness to some extent at present, fully leveraging its potential to significantly improve the robustness and resilience of defense models still faces two fundamental challenges. First, existing robustness methods based on graph contrastive learning typically operate on a given graph structure, which is insufficient to capture the complex interaction patterns embedded in traffic data. The quality of the graph structure heavily depends on the edge connection strategy. Most current methods construct adjacency matrices based on similarity and distance metrics. These methods cannot dynamically adjust edge connections according to the actual distribution of the data, which may distort the underlying semantic structure and increase the number of noisy edges, thereby weakening the expressiveness and contrast effectiveness of the graph representation. Furthermore, the scale of traffic data in connected vehicles is enormous. Adopting fine-grained graph construction strategies to enhance structural integrity would lead to a sharp increase in computational and storage overhead, making such methods impractical for real-time applications operating in resource-constrained environments.
[0050] Secondly, graph contrastive learning methods suffer from semantic blind spots when selecting negative samples because random sampling ignores the inherent relationships between samples. This inevitably leads to the misclassification of semantically similar instances as negative samples, thus impairing the learning of discriminative representations. Furthermore, hard negative sample mining is typically limited to intra-batch operations, lacking global modeling across batches. This limitation results in three cascading problems: insufficient coverage of informative hard negative samples, incomplete semantic structure learning, and training instability due to negative sample distribution bias. These limitations fundamentally constrain the performance ceiling of contrastive learning in downstream classification tasks.
[0051] Figure 2This section describes the communication architecture, participating entities, and security threats faced by the Internet of Vehicles (IoV). The main communication entities in this system include vehicles, pedestrians, roadside units (RSUs), and base stations. They communicate through various interfaces, including vehicle-to-vehicle (V2V), vehicle-to-pedestrian (V2P), vehicle-to-infrastructure (V2I), and vehicle-to-network (V2N). Attackers can impersonate legitimate vehicles, pedestrians, or RSUs to inject false information into the network, such as fake accident alerts, traffic congestion information, or false location information, misleading other vehicles' decisions. Furthermore, attackers may send a large number of malicious requests to base stations, RSUs, or cloud platforms, exhausting their resources, causing network congestion or service interruptions, affecting the transmission of real-time traffic data and the availability of critical functions. More seriously, attackers can compromise the IoV cloud platform, exploit its vulnerabilities, and steal or tamper with large amounts of sensitive data stored in the cloud (such as user identities, vehicle trajectories, and diagnostic data), or implant malware. By exploiting vulnerabilities in the vehicle's terminal or infotainment system through remote communication, malicious commands can be sent to the vehicle's electronic control unit, thereby enabling remote control of critical functions such as door unlocking, engine start, and even braking or steering.
[0052] like Figure 3 As shown, the first aspect of this invention is to provide a robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) network, comprising the following steps: S1: Calculate the optimal number of neighbors provided based on the pre-screened neighbor results and one-dimensional structural entropy of the provided data; S2: Based on the optimal number of neighbors, use local linear reconstruction to calculate the neighbor weights and construct a robust optimization graph structure; S3: Based on the robust optimization graph structure, a hard example mining method based on dual memory is adopted, and the robust embedding representation of the model is enhanced by class prototype alignment through low-rank decomposition.
[0053] The robust graph comparison learning method for resisting traffic attacks in the Internet of Vehicles provided by this invention is as follows: Figure 4 As shown, the first part: First, we utilize Locality Sensitive Hash (LSH) technology to reduce the dimensionality and index the traffic data, efficiently filtering neighbors and constructing a candidate neighbor set. Next, we introduce one-dimensional structural entropy to guide... The selection of values adaptively determines the optimal number of neighbors for each node. Next, weights are assigned to the selected edges using a local linear reconstruction method. This helps to remove noisy edges and refine connections while maintaining the expressiveness of the graph structure. This stage outputs a robust and optimized graph structure, solving the problems of fixed graph structure and noisy edges in traditional methods.
[0054] Part Two: We enhance the optimized robust graph structure with edge perturbation and ensemble adversarial enhancements, making the model more robust to potential attacks and noise in both key aspects of structure and features. Subsequently, these two enhanced views are fed into a graph attention network for feature encoding and then processed by a projector head to generate representations for contrastive learning. Next, the representations of the two views are fed into a dual-memory system (containing a Short-Term Memory Bank, STM; Long-Term Memory Bank, LTM). This system provides representations for each class. By maintaining an independent memory to store representative hard negative samples, the semantic blind spot problem in random sampling is addressed. When mining negative samples, the system dynamically identifies and selects the most difficult Top-M negative samples by combining representations from the memory and class prototypes. Simultaneously, we dynamically fuse class prototypes to guide contrastive learning in efficiently optimizing the feature space. The model is trained by minimizing supervised contrastive loss and prototype alignment loss; the former ensures the discriminativeness of the representations, while the latter optimizes the quality of the class prototypes, ensuring they accurately capture the core semantic features of each class. This approach significantly improves the model's robustness to structural and feature perturbations and strengthens the model's discriminative embedding representations by dynamically mining semantically discriminative hard negative samples, thus effectively defending against adversarial attacks against the model.
[0055] In this embodiment of the invention, step S1 includes: S11: Using the Locality-sensitive hashing (LSH) algorithm, a k-NN graph is constructed from the candidate neighbor set providing the data, and the one-dimensional structural entropy is calculated. The k with the smallest structural entropy is selected as the final optimal number of neighbors. The optimal k is chosen as follows:
[0056] In the formula: H(G) k ) is a k-NN graph G k One-dimensional structural entropy; V is the k-NN graph G k The set of all nodes; d i It is the degree of node i; vol(G) k ) is a k-NN graph G k The sum of the degrees of all nodes.
[0057] Furthermore, the candidate neighbor set for providing data is obtained based on the locality-sensitive hashing algorithm: Define a single hyperplane hash function according to the following formula:
[0058] In the formula: x i is the data provided, which is a high-dimensional data vector; r is a random normal vector, which is independently sampled from the standard normal distribution and used to define the random hyperplane.
[0059] Based on the provided data and α independent random hyperplane hash functions This yields a single LSH signature function:
[0060] In the formula, It is the j-th locality-sensitive hash function. It is the αth random hyperplane hash function.
[0061] Based on the LSH enhancement mechanism, and combining L independent families of LSH hash functions (i.e., j=0 to L), L LSH signatures are obtained. Each signature will be used to build a separate hash table:
[0062] Where G is a family of hash functions.
[0063] Based on L LSH signatures The mapping result yields the key value of the data point in the j-th hash table, and the data point x is then mapped... i (i.e., the provided high-dimensional data vector) is stored in the corresponding key-value pair. The data index is constructed within the hash bucket it points to.
[0064] In the formula: T j It is the j-th hash table; It is T j Corresponding key The hash bucket it points to is a data set; it provides data x. i Stored in L hash tables T j middle.
[0065] Based on the hash of the data index obtained by the Locality Sensitive Hash algorithm, and the retrieval of candidate neighbors:
[0066]
[0067] In the formula: x i It provides a high-dimensional data vector; C is the query hash code; C is the union of the contents of all hash buckets pointed to by the corresponding query hash code in L tables. This indicates that the key in the j-th hash table is... All data points in the bucket.
[0068] Calculate x using the formula below. i Calculate the exact distance to each data vector in the candidate set C, and select the k closest points:
[0069]
[0070] Where, x j It is the j-th data vector in the candidate set C.
[0071] In one embodiment of the invention, we efficiently pre-filter a small subset of candidate neighbors for a given query point in a traffic dataset using the Locality Sensitive Hash (LSH) algorithm. The method relies on the design of a family of hash functions: the probability of a hash collision between any two points is directly related to their similarity. The method employs LSH based on a random hyperplane, where similarity is measured by the angle between vectors. By hashing similar samples into the same bucket, LSH significantly reduces the candidate neighbor set. This makes the search complexity for each sample primarily dependent on the overhead of distance calculation for the retrieved candidates. The complexity for each sample is approximately O(ID), where I is the number of candidate samples in each query, while... This is the data dimension. Therefore, the overall complexity of graph construction is reduced to approximately O(NID), thus achieving efficient and scalable approximate neighbor search on large-scale datasets. This LSH-filtered subset of neighbors thus becomes the basis for subsequent graph structure construction.
[0072] This hashing process ensures that samples within the same bucket share significant feature similarities. Therefore, for any given sample, we construct an initial candidate set of neighbors by taking the union of all other samples in the corresponding buckets across all hash tables. Then, we select the final neighbors from this reduced and highly correlated set to construct the edges of the graph. In a special case, if the number of samples in a node's candidate set is less than the required number of neighbors, all candidate samples are used.
[0073] Furthermore, to avoid heuristic parameter setting, this invention adaptively guides the optimal approach by minimizing the one-dimensional structural entropy (1-DSE) of the graph structure. The choice of values. One-dimensional structural entropy measures the uncertainty of a node set, and it also serves as an upper limit on the amount of information embedded within it. Low entropy corresponds to high information content; therefore, based on the principle of minimizing 1-DSE, this invention constructs a graph structure that captures the core semantic structure of the data, is the most information-rich, and has the lowest redundancy. This allows each node to establish connections with its optimal number of nearest neighbors, thereby obtaining the graph. The edge set.
[0074] In this embodiment of the invention, step S2 includes: S21: Based on the data obtained for each sample Given 10 nearest neighbors, optimize the following problem to obtain the optimal weights of the edges in the graph:
[0075]
[0076] In the formula: λ is the regularization parameter; , It is x i of A set of nearest neighbors; w ij It is made by x j Point to x i The weight of the directed edge; w i It is composed of various w ij The vector formed, i.e., x i The reconstructed weight vector.
[0077] S22: The weight w of the edge in the robust graph. i This is the analytical solution obtained from the above optimization problem, and its analytical solution form is as follows:
[0078] In the formula: It is the local covariance matrix of the differences between neighbors. It is the neighbor difference matrix, which consists of all neighbors x j With center point x i The difference vectors between them are used to form the matrix; I is the identity matrix; 1 is a matrix of all ones.
[0079] In one embodiment of the invention, we utilize the Local Linear Reconstruction (LLR) method to effectively capture the local geometry of the data, thereby determining the edge weights W. For each node, its weight is obtained by solving a local optimization problem with Tikhonov regularization:
[0080] The first term of the objective function measures the error of a node being linearly reconstructed by its neighbors; minimizing this term ensures the best preservation of local geometry. The second regularization term enhances the robustness of the solution, especially when neighbor vectors are highly correlated (collinear), preventing numerical instability.
[0081] In a high-dimensional space, we reconstruct each data point (node) linearly by its nearest neighbors. The weights of the reconstruction reflect the contribution of the neighbors to the point, thus accurately capturing the local geometric relationships around the point. The LLR of this invention, after determining the optimal neighbor set, provides a data-driven and robust way to assign edge weights, enabling the graph structure to be based not only on distance but also on a precise representation of the local manifold geometry, which is crucial for subsequent feature learning in graph neural networks.
[0082] In this embodiment of the invention, step S3 includes: S31: Based on the adjacency matrix of the robust graph structure, perform edge perturbation data augmentation on the robust graph structure:
[0083] In the formula: A is the perturbed adjacency matrix; A0 is the initial adjacency matrix of the robust optimization graph. ; It is an XOR operation; T is the perturbation matrix. .
[0084] Based on the feature matrix X of the robust graph structure, an integrated adversarial enhancement is performed on the feature matrix:
[0085] In the formula, x i It is the i-th eigenvector in the eigenmatrix X. ; It is the perturbed eigenvector; It is an adversarial perturbation generated by an adversarial attack algorithm.
[0086] Based on the two enhanced views G1 and G2, the embedding representation of the two views is calculated using the following formula:
[0087] In the formula: This represents the embedding representation of node i in the (l+1)th layer of the GAT model; K is the number of attention heads; It is the normalized attention coefficient; W k It is the feature transformation weight matrix of the k-th head; The embedding representation of node j at layer l; It is a node The set of neighbors.
[0088] S32: Based on the embedding representation of the two views, embed the two views obtained by the same node through two enhancement operations, pair them to form a positive sample pair, and thus obtain all positive sample pairs for comparison.
[0089] Based on the embedded representations of the two views, apply a first-in-first-out update strategy to update the Short-Term Memory Bank (STM) and the Long-Term Memory Bank (LTM) for each category providing data:
[0090] Where: μ batch It is the average embedding representation of samples belonging to this category in the current batch; μ old It is a historical average embedding representation; η is a momentum coefficient used to balance the influence of historical information and current batch information.
[0091] Based on the two memory banks, for category c i Positive anchor point sample z i Negative samples will be selected from all other categories according to a preset ratio. Samples are taken from the STM and LTM libraries to form a negative sample pool. .
[0092] Based on the negative sample pool of all classes other than the true class of the current positive anchor sample, the following similarity calculation formula is applied to calculate the Top-M cross-class hard negative samples:
[0093] In the formula, Represents vector z i and z n dot product between and Then they represent vectors z respectively i and z n The Euclidean norm.
[0094] S33: Construct a supervised contrastive loss function based on the constructed positive and negative sample pairs. Category prototype alignment loss function and regularization loss function The final loss function is adopted. Pre-train the GAT model and optimize the model embedding representation:
[0095] in, , and This is the weight value corresponding to the loss.
[0096] Furthermore, the supervised contrastive loss function is defined as follows:
[0097]
[0098] In the formula: Indicates batch size; and This represents the embedding vector of the i-th node in two different views; This indicates that the true category c is excluded. i A collection of categories; This refers to node i and relative to category c. i The set of difficult negative samples; M is the number of difficult negative samples in each category; n g τ is the embedding vector of the difficult negative sample; τ is the temperature parameter.
[0099] Furthermore, the category prototype alignment loss function is defined as follows:
[0100] In the formula: This represents one of two different enhanced views; It is a category The low-rank prototype vector; c i It is the true category of node i.
[0101] Furthermore, the regularization loss function is defined as follows:
[0102] Where: I R yes The identity matrix; It is the squared Frobenius norm; U and V are matrices after low-rank decomposition.
[0103] Furthermore, the category prototype alignment includes the following steps: Calculate the mean of the corresponding memory bank based on the embedding of the long short-term memory bank. and :
[0104]
[0105] In the formula: and This represents the number of currently valid (i.e., filled) entries for category c in both LTM and STM; 0m Represents an m-dimensional zero vector; and These represent the i-th and j-th values of category c stored in STM and LTM, respectively.
[0106] The category is calculated by weighted summation based on the gate value. Fusion Prototype :
[0107] In the formula, It is the gate value, P c It is the c-th column vector of the prototype matrix P of all categories.
[0108] Furthermore, the threshold value is defined as follows:
[0109] In the formula, and These are learnable parameters, where σ represents the Sigmoid activation function.
[0110] Furthermore, the prototype matrix of all categories is calculated using the following formula. Perform low-rank decomposition:
[0111] In the formula, U is the factor matrix and V is the coefficient matrix. Instead of using P, the decomposed U and V are used to represent the category prototypes and the calculation of the prototype alignment loss, reducing computational complexity.
[0112] In one embodiment of the invention, the robustness of the framework is achieved through two core innovations in the construction of the contrast pair: one for positive sample pairs and the other for negative samples. For positive sample pairs, we abandon traditional data augmentation techniques and instead reuse adversarial attacks themselves as an augmentation strategy to create more challenging and semantically rich views. Two distinct but complementary views, G1 and G2, are generated by perturbing the graph structure and node features. This dual augmentation makes the model more robust to potential attacks and noise in both the key aspects of structure and features. For any node in the graph, its projected embedding representation in view G1 and its embedding representation in view G2 are considered a positive sample pair. In this way, the model is forced to learn a common, robust embedding space. In this space, even if the same node has undergone different perturbations derived from adversarial attacks (one structural and one feature-based), its final representation must be similar and aligned. This strengthens the invariance and robustness of the representation, enabling it to resist potential attacks and noise from both the structural and feature levels.
[0113] Furthermore, for negative sample pairs, we introduce a hard negative sample mining process driven by a dual-memory system (STM and LTM). STM uses a fixed-size FIFO queue to capture recent feature changes, storing the latest batch of embeddings for each class. LTM, on the other hand, continuously aggregates historical information through an exponential moving average strategy, thereby refining highly stable long-term class representations. STM provides recent, instance-level candidate samples, allowing the model to access challenging instance-level negative samples in the current or most recent batches. These samples are closest to the decision boundary, helping the model adapt more quickly to the latest feature distribution changes. LTM provides stable negative sample candidates aggregated from previous batches, allowing the model to access stable, long-term average class negative samples across multiple historical batches, representing the core semantic prototypes of each class. This solves the batch limitation problem, avoiding insufficient negative sample coverage and semantic blind spots caused by sampling only within small batches. The dual-memory mechanism of this invention enables the model to perform more effective and robust hard negative sample mining from a global perspective that considers both short-term feature changes and long-term semantic stability.
[0114] Furthermore, this invention employs a category prototype-based alignment method. Adaptive category prototypes are extracted from STM and LTM libraries using a gating mechanism. This method integrates information across multiple time scales (short-term and long-term), ensuring that the prototypes can adapt to both current data fluctuations and long-term stability. This fusion is achieved through short-term and long-term means, which respectively characterize the recent and historical trends of different categories. Figure 5 As shown, category prototype alignment integrates category-level global semantic information into instance-level contrastive learning, resulting in a learned embedding space with the following advantages: sample clusters from different categories are more compact in the feature space, and their boundaries are clearer. Therefore, category prototypes act as powerful semantic anchors and repulsive forces, greatly enhancing the discriminativeness, cohesion, and robustness of the learned representation to downstream classification tasks.
[0115] By constructing high-quality graph structures and GCL negative samples, this invention achieves a balance between model robustness and feature discriminability while resisting adversarial attacks, thereby significantly improving the robustness and security of the system in complex vehicle network intrusion detection environments.
[0116] The steps described above are for clarity only. In practice, they can be combined into one step or some steps can be split into multiple steps. As long as they contain the same logical relationship, they are all within the protection scope of this invention. Adding insignificant modifications or introducing insignificant designs to the algorithm or process, without changing the core design of the algorithm and process, are also within the protection scope of this invention.
[0117] like Figure 6As shown, a second aspect of this invention discloses a robust graph contrastive learning system for combating traffic attacks in the Internet of Vehicles (IoV) network, comprising: an optimal nearest neighbor selection module, a local reconstruction graph construction module, and a robust embedding reinforcement module. Specifically, the system calculates the number of optimal neighbors for the provided data based on the pre-screened neighbor results and one-dimensional structural entropy; the local reconstruction graph construction module is used to calculate neighbor weights and construct a robust optimized graph structure based on the number of optimal neighbors using local linear reconstruction; and the local reconstruction graph construction module is used to calculate neighbor weights and construct a robust optimized graph structure based on the number of optimal neighbors using local linear reconstruction.
[0118] It should be noted that, in order to highlight the innovative aspects of this invention, this embodiment does not include modules that are not closely related to solving the technical problems proposed by this invention, but this does not mean that there are no other modules in this embodiment.
[0119] Furthermore, those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here. In the embodiments provided by this invention, it should be understood that the disclosed system and method can be implemented in other ways. For example, the division of modules is merely a logical functional division, and in actual implementation, there may be other division methods; for example, multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0120] The modules described as separate components may or may not be physically separate. Similarly, the components shown as modules may or may not be physical modules; they may be located in one place or distributed across multiple network modules. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0121] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional units.
[0122] If the integrated module is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0123] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.
Claims
1. A robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV), characterized in that, include: Based on the pre-screened neighbor results and one-dimensional structural entropy of the provided data, the optimal number of neighbors for the provided data is calculated. Based on the optimal number of neighbors, local linear reconstruction is used to calculate the neighbor weights and construct a robust optimization graph structure. Based on the robust optimization graph structure, a hard example mining method based on dual memory is adopted, and the robust embedding representation of the model is enhanced by class prototype alignment through low-rank decomposition.
2. The robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) as described in claim 1, characterized in that, The step of calculating the optimal number of neighbors for the provided data based on the pre-screened neighbor results and one-dimensional structural entropy includes: constructing a k-NN graph using the locality-sensitive hashing algorithm to obtain the candidate neighbor set of the provided data, calculating the one-dimensional structural entropy, and selecting the k value with the smallest structural entropy as the final optimal number of neighbors, where the optimal k value is k * The options are as follows: In the formula: H(G) k ) is a k-NN graph G k One-dimensional structural entropy; V is the k-NN graph G k The set of all nodes; d i It is the degree of node i; vol(G) k ) is a k-NN graph G k The sum of the degrees of all nodes.
3. A robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) as described in claim 2, characterized in that, The candidate neighbor set for providing data obtained according to the locality-sensitive hashing algorithm includes: a single hyperplane hash function defined according to the following formula: In the formula: xi is the provided data, a high-dimensional data vector; r is a random normal vector, independently sampled from the standard normal distribution, used to define the random hyperplane; based on the provided data and α independent random hyperplane hash functions h concatenated, a single LSH signature function is obtained: In the formula, It is the j-th locality-sensitive hash function. It is the α-th random hyperplane hash function; according to the LSH enhancement mechanism, combined with L independent LSH hash function families, i.e., j=0 to L, we obtain L LSH signatures. Each LSH signature is used to build a separate hash table: In the formula, G is the set of hash functions; based on L LSH signatures The mapping result yields the key value of the data point in the j-th hash table, and the provided data xi is stored in the corresponding key value. The data index is constructed within the hash bucket it points to. In the formula: Tj is the j-th hash table; It is the corresponding key in Tj The pointed-to hash bucket is a data set; it provides that data xi is stored in L hash tables Tj; the hash of the data is retrieved and candidate neighbors are searched based on the data index obtained by the locality-sensitive hashing algorithm. ; In the formula: C is the query hash code; C is the union of the contents of all hash buckets pointed to by the corresponding query hash code in L tables. This indicates that the key in the j-th hash table is... Given all data points in the bucket; calculate the precise distance between the provided data xi and each data vector in the candidate set C according to the following formula, and select the k closest points: ; In the formula, xj is the j-th data vector in the candidate set C.
4. The robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) as described in claim 1, characterized in that, The process of calculating neighbor weights and constructing a robust optimization graph structure based on the optimal number of neighbors using local linear reconstruction includes: optimizing the following problem to obtain the optimal weights of edges in the robust optimization graph based on the optimal k* nearest neighbors of the provided data xi: ; In the formula: λ is the regularization parameter; , It is Xi's The nearest neighbor set; wij is the weight of the directed edge from xj to xi; wi is the vector composed of each wij, i.e., the reconstructed weight vector of xi; the weights of the edges in the robust optimization graph. This is the analytical solution obtained from the above optimization problem, and its analytical solution form is as follows: In the formula: It is the local covariance matrix of the differences between neighbors. is the neighbor difference matrix, which consists of the difference vectors between all neighbors xj and the center point xi; I is the identity matrix; 1 is a matrix of all ones.
5. A robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) as described in claim 1, characterized in that, The step of strengthening the robust embedding representation of the model by employing a hard example mining method based on a dual-memory library and aligning class prototypes through low-rank decomposition, based on the robust optimized graph structure, includes: performing edge perturbation data augmentation on the robust optimized graph structure according to the adjacency matrix of the robust optimized graph structure. In the formula: A is the perturbed adjacency matrix; A0 is the initial adjacency matrix of the robust optimization graph. ; It is an XOR operation; T is the perturbation matrix. ; Perform integrated adversarial enhancement on the feature matrix X of the robust optimized graph structure: In the formula, x i It is the i-th eigenvector in the eigenmatrix X. ; It is the perturbed eigenvector; It is an adversarial perturbation generated by an adversarial attack algorithm; based on two views, one after perturbation data augmentation and the other after integrated adversarial augmentation. and The embedding representation of the two views is calculated using the following formula: In the formula: This represents the embedding representation of node i in the (l+1)th layer of the GAT model; K is the number of attention heads; It is the normalized attention coefficient; W k It is the feature transformation weight matrix of the k-th head; The embedding representation of node j at layer l; It is a node The set of neighbors.
6. A robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) as described in claim 5, characterized in that, After strengthening the robust embedding representation of the model by employing a hard example mining method based on a dual-memory bank according to the robust optimization graph structure and by class prototype alignment through low-rank decomposition, the method further includes: embedding the two views obtained by performing two enhancement operations on the same node according to the embedding representation of the two views, pairing them to form a positive sample pair, thereby obtaining all positive sample pairs for comparison; and updating the short-term memory bank and the long-term memory bank according to the embedding representation of the two views for each category providing data by applying a first-in-first-out update strategy. In the formula: μ batch It is the average embedding representation of samples belonging to this category in the current batch; μ old It is a historical average embedding representation; η is a momentum coefficient used to balance the influence of historical information and current batch information; based on the short-term memory bank and the long-term memory bank, for category c i Positive anchor point sample z i Negative samples are selected from all other categories according to a preset ratio. Samples are taken from the short-term and long-term memory banks to form a negative sample pool. .
7. A robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) as described in claim 6, characterized in that, Based on the negative sample pool of all classes other than the true class of the current positive anchor sample, the following similarity calculation formula is applied to calculate the Top-M cross-class hard negative samples: In the formula, Represents vector z i and z n dot product between and Then they represent vectors z respectively i and z n The Euclidean norm.
8. A robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) as described in claim 7, characterized in that, Based on the constructed positive and negative sample pairs, a supervised contrastive loss function is constructed. Category prototype alignment loss function and regularization loss function The final loss function is adopted. Pre-train the GAT model and optimize the model embedding representation: In the formula, , and These are the weight values corresponding to the loss, where: the supervised contrastive loss function is defined as: ; In the formula: Indicates batch size; and This represents the embedding vector of the i-th node in two different views; This indicates that the true category c is excluded. i A collection of categories; This refers to node i and relative to category c. i The set of difficult negative samples; M is the number of difficult negative samples in each category; n g The embedding vector of the hard negative sample; τ is the temperature parameter; the class prototype alignment loss function is defined as: In the formula: This represents one of two different enhanced views; It is a category The low-rank prototype vector; c i It is the true class of node i; the regularization loss function is defined as: In the formula: I R yes The identity matrix; It is the squared Frobenius norm; U and V are matrices after low-rank decomposition.
9. A robust graph contrastive learning method for combating traffic attacks in the Internet of Vehicles (IoV) according to claim 6, characterized in that, Calculate the mean of the corresponding memory bank based on the embedding of the long short-term memory bank. and : ; In the formula: and This represents the number of currently valid entries for category c in both short-term and long-term memory; 0 m Represents an m-dimensional zero vector; and Let i and j represent the i-th and j-th values of category c stored in the short-term and long-term memory banks, respectively; and calculate the fusion prototype P of category c by weighted summation based on the gating value. c : In the formula, It is the gate value, P c It is the c-th column vector of the prototype matrix P of all classes, where the gating value is defined as: In the formula, and These are learnable parameters, where σ represents the Sigmoid activation function; the prototype matrix P of all classes is decomposed into a low-rank form using the following formula: In the formula, U is the factor matrix and V is the coefficient matrix; P is no longer used thereafter, but the decomposed U and V are used to represent the calculation of the category prototype and the prototype alignment loss, which reduces the computational complexity.
10. A robust graph contrastive learning system for combating traffic attacks in the Internet of Vehicles (IoV), used to implement the method described in claim 1, characterized in that, The system includes: an optimal nearest neighbor selection module, used to calculate the number of optimal neighbors of the provided data based on the pre-screened neighbor results and one-dimensional structural entropy; a local reconstruction graph construction module, used to calculate the neighbor weights and construct a robust optimized graph structure based on the number of optimal neighbors using local linear reconstruction; and a robust embedding enhancement module, used to enhance the robust embedding representation of the model by adopting a hard example mining method based on a dual-memory library and by class prototype alignment through low-rank decomposition, based on the robust optimized graph structure.
