Adaptation method for graph neural network during testing oriented to out-of-distribution offset

By introducing prototype graph contrastive learning and multi-level domain alignment constraints into graph neural networks, the problem of insufficient generalization ability of graph neural networks when there is out-of-distribution offset is solved, and stable prediction and improved adversarial robustness in complex environments are achieved.

CN121997977APending Publication Date: 2026-05-08CHONGQING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHONGQING UNIV OF POSTS & TELECOMM
Filing Date
2026-01-20
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Existing graph neural networks struggle to effectively distinguish between covariate shifts and concept shifts when faced with out-of-distribution shifts, resulting in limited generalization ability. Furthermore, existing methods are unable to simulate complex structural shifts in complex environments, and their generalization ability is insufficient when facing dynamic scenarios due to reliance on training data knowledge.

Method used

By acquiring a graph dataset with related category label information, it is divided into a training set, a validation set, and a test set. The graph neural network model is trained using the training set with the main task loss and the self-supervised auxiliary task loss to obtain initial category prototypes. On the test set, prototype graph contrast learning and multi-level domain alignment constraints are performed to optimize the model parameters, including prototype contrast learning loss and prototype clustering loss, combined with global distribution differences and prototype distribution alignment constraints.

Benefits of technology

It improves the prediction accuracy and generalization ability of graph neural networks under distribution offset conditions, enhances adversarial robustness, and can maintain stable prediction performance in dynamic scenes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121997977A_ABST
    Figure CN121997977A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an adaptive method for a graph neural network during testing oriented to out-of-distribution offset. The method is applied to the field of graph neural networks, and comprises the following steps: acquiring a graph data set with relational category label information, and dividing the acquired graph data set into a training set, a verification set and a test set; using the training set to train the target graph neural network model based on the main task loss and the self-supervised auxiliary task loss to obtain a trained graph neural network model and a plurality of initial category prototypes; using the test set to optimize parameters of the trained graph neural network model based on the prototype graph comparison learning loss and the multi-level domain alignment constraint; and analyzing and processing the input data through the optimized graph neural network model to obtain a prediction result. The method improves the accuracy of the prediction result when the data has the distribution offset.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of graph neural networks, and more particularly to a test-time adaptation method for graph neural networks oriented towards out-of-distribution offset. Background Technology

[0002] To address the out-of-distribution shift problem encountered with graph data, existing research can be broadly categorized into three paradigms. The first is data-level approaches, which construct diverse samples during training to simulate potential shifts and improve the model's adaptability to distribution changes. Typical methods include feature perturbation, structural perturbation, and multi-view generation. These methods aim to expose the model to different types of pseudo-environments during training, enabling it to learn more invariant representations. The second is model-level approaches, which directly incorporate specific prior knowledge or causal assumptions into the design of GNNs, aiming to enhance the representational capabilities of GNNs at the architectural level and improve generalization. The third is training strategy-level approaches, which guide the model to learn stable features or decision-making patterns across environments by designing new learning objectives or optimization strategies. Among these, domain adaptation methods are relatively common, typically employing adversarial domain discriminators or statistical alignment techniques such as Maximum Mean Discrepancy (MMD) to make the source and target domain distributions converge in the latent space. In recent years, the research field has proposed a new learning strategy to address the problem of out-of-distribution shift, namely the Test-Time Adaptation (TTA) method. This method uses test samples to adaptively update the model online during the testing phase, enabling it to dynamically adjust the representation during deployment to cope with distribution shift.

[0003] While the aforementioned methods alleviate the performance degradation caused by distribution shift to some extent, several challenges remain. First, data augmentation-based methods rely on artificially designed perturbation strategies, which have limited coverage of the shift space and often struggle to simulate complex structural shifts that may occur in complex environments. Second, model-based methods, although capable of enhancing representational capabilities at their source, typically suffer from excessive model complexity. Third, methods based on training strategies often implicitly assume stable environments or consistent conditional distributions, making it difficult to maintain the stability of category semantic boundaries when test data evolves dynamically over time or in different scenarios. Furthermore, all three types of methods generally treat distribution shift as a single, holistic phenomenon, failing to differentiate between the different impacts of covariate shift and concept shift, making it difficult to specifically mitigate the effects of both types of shift. Summary of the Invention

[0004] To address the aforementioned problems, this application provides a test-time adaptation method for graph neural networks oriented towards out-of-distribution offsets, the method comprising:

[0005] Obtain a graph dataset containing related category label information, and divide the graph dataset into a training set, a validation set, and a test set;

[0006] The target graph neural network model is trained using the training set based on the main task loss and the self-supervised auxiliary task loss, resulting in a trained graph neural network model and multiple initial class prototypes. The self-supervised auxiliary task loss is the prototype graph contrast learning loss.

[0007] The parameters of the graph neural network model are optimized using a test set based on prototype graph contrastive learning loss and multi-level domain alignment constraints. The prototype graph contrastive learning loss includes prototype contrastive learning loss and prototype clustering loss. The multi-level domain alignment constraints include global distribution difference constraints between the source domain and the target domain and prototype distribution alignment constraints between the source domain and the target domain.

[0008] The optimized graph neural network model is used to analyze and process the input data to obtain the prediction results.

[0009] Optionally, the step of training the target graph neural network model using the training set based on the main task loss and the self-supervised auxiliary task loss yields the trained graph neural network model and multiple initial category prototypes, including:

[0010] The parameters of the target graph neural network model are updated using gradient descent on the source domain graph by combining the main task loss and the prototype graph comparative learning loss until the performance of the target graph neural network model on the validation set no longer improves. The updated network parameters, the embedding representation of the source domain, and the prototype distribution are retained. The network parameters include shared encoder parameters, main task head parameters, and self-supervised auxiliary task head parameters.

[0011] Optionally, the prototype comparison learning includes:

[0012] Determine the similarity between each node in the target domain and the category prototype in the source domain, and assign pseudo-labels to the nodes based on the similarity.

[0013] Determine the homogeneity score of the connecting edge between any two nodes, and perform homogeneity enhancement on the connecting edge based on the homogeneity score to obtain an enhanced view;

[0014] Initialize a set of trainable class prototype vectors, perform graph contrastive learning based on the initialized class prototype vectors and the augmented view, and introduce prototype clustering loss.

[0015] Optionally, determining the similarity between each node in the target domain and the category prototype in the source domain, and assigning pseudo-labels to the nodes based on the similarity, includes:

[0016] Determine the cosine similarity between the embedding vector of each node in the target domain and the prototype vector in the source domain, and determine the soft assignment probability of the node in the target domain relative to each category of prototype in the source domain based on the cosine similarity.

[0017] The source domain category with the highest soft probability to which the target domain node belongs is used as the pseudo-label of the target domain node.

[0018] Optionally, determining the homogeneity score of the connecting edge between any two nodes, and performing homogeneity enhancement on the connecting edge based on the homogeneity score to obtain an enhanced view, includes:

[0019] The homogeneity score of the connecting edge is determined based on the neighbor set of one of the nodes corresponding to the connecting edge and the pseudo-labels of the two nodes corresponding to the connecting edge.

[0020] Determine whether the homogeneity score is higher than a preset threshold;

[0021] If so, the connecting edge is retained;

[0022] If not, then the connecting edge is perturbed.

[0023] Optionally, the prototype contrastive learning loss satisfies the following formula:

[0024] ,

[0025] in, Prototype-based contrastive learning loss, This is the original node embedding vector. To enhance the node embedding vector in the view, For temperature coefficient, For nodes The allocation prototype, Indicates the first One prototype vector.

[0026] Optionally, the prototype clustering loss satisfies the following formula:

[0027] ,

[0028] in, For clustering loss, The total number of nodes. The square of the vector norm. For nodes The assigned prototype vector, For hyperparameters, For margin, For the first The prototype vector of a class. For the first The prototype vector of the class.

[0029] Optionally, the global distribution difference constraint between the source domain and the target domain satisfies the following formula:

[0030] ,

[0031] in, The global distribution alignment loss between the source and target domains is given. The mean of the target domain. The mean of the source domain is . The covariance of the target domain, Let the covariance of the source domain be , The square of the L2 norm, It is the square of the Frobenius norm.

[0032] Optionally, the prototype distribution alignment constraint between the source domain and the target domain satisfies the following formula:

[0033] ,

[0034] in, The prototype distribution alignment loss between the source and target domains is denoted as . For the prototype distribution of the target domain, This represents the prototype distribution of the source domain. Let KL divergence be denoted as KL divergence.

[0035] This application provides a test-time adaptation method for graph neural networks (GNNs) oriented towards out-of-distribution offsets. It acquires a graph dataset containing related category label information and divides the dataset into training, validation, and test sets. The training set is used to train the target GNN model based on the main task loss and the self-supervised auxiliary task loss, resulting in a trained GNN model and multiple initial category prototypes. The self-supervised auxiliary task loss is a prototype graph contrastive learning loss. The test set is used to optimize the parameters of the GNN model based on the prototype graph contrastive learning loss and multi-level domain alignment constraints. The prototype graph contrastive learning loss includes prototype contrastive learning loss and prototype clustering loss, while the multi-level domain alignment constraints include global distribution difference constraints between the source and target domains and prototype distribution alignment constraints between the source and target domains. The optimized GNN model is then used to analyze and process the input data to obtain prediction results. This method improves the accuracy of prediction results when data distribution offsets exist. Attached Figure Description

[0036] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0037] Figure 1A flowchart illustrating the test-time adaptation method for graph neural networks oriented towards out-of-distribution offsets provided in an embodiment of this application;

[0038] Figure 2 A schematic diagram illustrating the process of prototype comparison and learning provided in the embodiments of this application;

[0039] Figure 3 A schematic diagram of the prototype distribution alignment process provided in the embodiments of this application;

[0040] Figure 4 Experimental results of multiple OOD test graphs of the Cora dataset provided in this application embodiment;

[0041] Figure 5 The figures show the experimental results for two offsets on the GOOD-Cora dataset provided in this application embodiment;

[0042] Figures 6(a), (b), and (c) show the performance of each method under different perturbation ratios provided in the embodiments of this application.

[0043] Figure 7 The experimental results diagrams provided in the embodiments of this application are shown after the ablation of each module;

[0044] Figure 8 A diagram illustrating the impact of different values ​​of multi-level alignment weights on the adaptation during testing, provided in an embodiment of this application.

[0045] Figure 9 The diagram illustrates the effect of the number of adaptation steps during testing on the adaptation during testing, as provided in the embodiments of this application.

[0046] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0047] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0048] The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein.

[0049] In this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.

[0050] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0051] Reliable inference of graph neural networks under out-of-distribution bias conditions is a core challenge restricting the stable deployment of graph models in open environments. Existing research mainly focuses on graph data augmentation, generalization model architecture design, and improved training strategies. Although some progress has been made, shortcomings remain. On the one hand, existing methods treat distribution bias as a single phenomenon, lacking the ability to distinguish and specifically handle covariate bias and concept bias, thus making it difficult to explain and suppress the impact of these two types of bias on the model. On the other hand, existing methods still rely heavily on training data knowledge, and their generalization ability is limited when facing strong bias scenarios. When there are few tests, the adaptation methods mostly focus on processing low-order statistics of test features, failing to effectively utilize the clustering structure information contained in the test data.

[0052] To address the aforementioned issues, this application proposes a test-time adaptation method for graph neural networks oriented towards out-of-distribution bias. A novel prototype clustering graph contrastive learning method is designed for test-time adaptation scenarios. This method mines clustering information from test data by explicitly modeling class distributions through prototype-based homogeneity enhancement and representation contrast. A multi-level alignment mechanism combining global feature distribution alignment and class prototype distribution alignment is designed to simultaneously constrain representation distribution and class conditional distribution without relying on target domain labels, effectively mitigating the impact of covariate bias and concept bias. Adversarial attacks are incorporated into the out-of-distribution bias framework, revealing their consistency with concept bias in disrupting decision boundaries. Experiments verify that this method can simultaneously improve the model's out-of-distribution generalization and adversarial robustness within a unified framework.

[0053] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0054] Figure 1 This is a flowchart illustrating the testing adaptation method for graph neural networks oriented towards out-of-distribution offsets provided in an embodiment of this application. Figure 1 As shown, the test-time adaptation method for graph neural networks oriented towards out-of-distribution offsets provided in this embodiment includes:

[0055] S1: Obtain a graph dataset with related category label information, and divide the graph dataset into a training set, a validation set, and a test set.

[0056] Graph datasets can be, for example, social network datasets.

[0057] Understandably, the training set is used for model training, the validation set is used for hyperparameter tuning, and the test set is used to evaluate the final performance of the model.

[0058] S2: Train the target graph neural network model using the training set based on the main task loss and the self-supervised auxiliary task loss to obtain the trained graph neural network model and multiple initial category prototypes.

[0059] The self-supervised auxiliary task loss is the prototype graph contrastive learning loss. The target graph neural network model can be, for example, GCN, GAT, etc.

[0060] Specifically, the target graph neural network model is trained using the training set based on the main task loss and the self-supervised auxiliary task loss to obtain the trained graph neural network model and multiple initial class prototypes. This includes updating the parameters of the target graph neural network model using gradient descent on the source domain graph by combining the main task loss and the prototype graph comparison learning loss, until the performance of the target graph neural network model on the validation set no longer improves. The updated network parameters, the embedding representation of the source domain, and the prototype distribution are retained. The network parameters include the shared encoder parameters, the main task head parameters, and the self-supervised auxiliary task head parameters.

[0061] For example, the primary task typically uses cross-entropy loss, while the self-supervised auxiliary task typically uses contrastive loss to optimize model parameters. The model is trained using gradient descent methods (such as the Adam optimizer) until its performance on the validation set no longer improves. The training process jointly optimizes the primary task loss and the graph contrastive learning loss based on prototype clustering on the source domain graph to learn a shared encoder and initial class prototypes. GradNorm adaptively balances the gradients of the two tasks to obtain node representations that are both discriminative and semantically convergent, and uses each class prototype as a semantic prior for subsequent testing. The loss at this stage is:

[0062] ,

[0063] in, Losses during the training phase Loss to the main task The learning loss is compared with the prototype image. The weighting coefficients for the main task loss. The weighting coefficients for the prototype-image contrast learning loss are... , GradNorm adaptively adjusts the gradient norm based on the two tasks.

[0064] Save the trained model parameters, which are the shared encoder parameters. Main task head and self-supervised task head , The mean and covariance matrix of the source domain embedding.

[0065] S3: Optimize the parameters of the graph neural network model using the test set based on the prototype graph contrastive learning loss and multi-level domain alignment constraints.

[0066] Among them, the prototype graph contrastive learning loss includes: prototype contrastive learning loss and prototype clustering loss; the multi-level domain alignment constraints include: global distribution difference constraints between the source domain and the target domain and prototype distribution alignment constraints between the source domain and the target domain.

[0067] Figure 2 This is a schematic diagram of the prototype comparison learning process provided in the embodiments of this application. The prototype comparison learning includes the following steps:

[0068] (1) Determine the similarity between each node in the target domain and the category prototype in the source domain, and assign pseudo-labels to the nodes based on the similarity.

[0069] Specifically, the cosine similarity between the embedding vector of each node in the target domain and the prototype vector in the source domain is determined, and the soft assignment probability of the target domain node relative to each category prototype in the source domain is determined based on the cosine similarity; the source domain category to which the target domain node belongs with the highest soft probability is used as the pseudo-label of the target domain node.

[0070] More specifically, assuming that during the training phase... One prototype vector (corresponding to) (each category) forms the prototype matrix ,in For the embedding dimension, for each node in the target domain Let the embedding of its encoder output be denoted as Then, its soft assignment probability relative to each class of prototypes is defined as:

[0071] ,

[0072] in, Represents cosine similarity. For temperature coefficient, For the first Each prototype vector. Therefore, the nodes can be... The pseudo-tag is defined as:

[0073] ,

[0074] This means that nodes are more likely to belong to the prototype cluster with the highest soft probability. By introducing source domain prototype priors, the category-level knowledge of the source domain is explicitly transferred to the target domain, which can provide more stable semantic anchoring when OOD offset exists.

[0075] (2) Determine the homogeneity score of the connecting edge between any two nodes, and enhance the homogeneity of the connecting edge according to the homogeneity score to obtain the enhanced view.

[0076] Specifically, the homogeneity score of the connecting edge is determined based on the neighbor set of one of the nodes corresponding to the connecting edge and the pseudo-labels of the two nodes corresponding to the connecting edge; it is then determined whether the homogeneity score is higher than a preset threshold; if so, the connecting edge is retained; otherwise, the connecting edge is perturbed.

[0077] More specifically, for each edge Construct its homogeneity score to measure its semantic reliability. Denote the node... The neighbor set is Define its homogeneity score as follows:

[0078] ,

[0079] in, For indicator functions, For nodes pseudo-tags For nodes The pseudo-label. Then the edge The homogeneity score is defined as "semantic consistency" and weighted by combining the degree of consistency within its local neighborhood. Each edge is assigned a probability of retention or perturbation. Edges with high homogeneity have a higher probability of retention to protect critical structures within the class, while edges with low homogeneity have a higher probability of perturbation to weaken cross-class noisy connections.

[0080] (3) Initialize a set of trainable class prototype vectors, perform graph comparison learning based on the initialized class prototype vectors and the augmented view, and introduce prototype clustering loss.

[0081] Specifically, a set of trainable class prototype vectors is introduced. During both training and testing, these parameters are updated together as model parameters during the training phase. To provide a reasonable semantic starting point, Initialize to the class mean of node embeddings for each category in the source domain. Simultaneously, introduce the prototype into the comparison target, and evaluate the node embeddings. Its enhanced view embedding Form positive sample pairs, and other prototypes besides their respective prototypes as negative samples. Define prototype contrastive loss:

[0082] ,

[0083] in, Prototype-based contrastive learning loss, This is the original node embedding vector. To enhance the node embedding vector in the view, For temperature coefficient, For nodes The allocation prototype, Indicates the first Each prototype vector. This loss, on the one hand, encourages nodes to maintain consistent prototype attribution under different augmented views, and on the other hand, provides a more stable category semantic anchor for subsequent domain alignment by explicitly moving away from out-of-category prototypes.

[0084] Understandably, to enhance the intra-class compactness and inter-class separability of prototype clustering and improve the discriminative ability of the prototype itself, prototype clustering consistency loss is introduced:

[0085] ,

[0086] in, For clustering loss, The total number of nodes. The square of the vector norm. For nodes The assigned prototype vector, For hyperparameters, For margin, For the first The prototype vector of a class. For the first The prototype vector of the class. The first term minimizes the Euclidean distance between the node embedding and its assigned prototype, strengthening intra-class compactness; the second term is determined by margins. Constrain the minimum interval between different prototypes, maximize the distance between classes, and prevent prototype collapse.

[0087] Combining the comparison and clustering terms, the total loss for prototype image comparison learning is:

[0088] ,

[0089] in, The weighting hyperparameters are used to balance the two losses.

[0090] Understandably, to minimize the global distribution difference between the source and test domains, alignment constraints are imposed on the first and second-order statistics of the two domains. Specifically, the global distribution difference constraint between the source and target domains satisfies the following formula:

[0091] ,

[0092] in, The global distribution alignment loss between the source and target domains is given. The mean of the target domain. The mean of the source domain is . The covariance of the target domain, Let the covariance of the source domain be , The square of the L2 norm, This loss is the square of the Frobenius norm. This loss encourages the overall distribution of the target domain embeddings to closely approximate the source domain, enabling the model to learn a consistent representation in the latent space. This alignment strategy effectively reduces the bias caused by feature distribution shifts, thereby mitigating the impact of covariate shifts on model performance.

[0093] Specifically, the formulas for calculating the mean and covariance are as follows:

[0094] ,

[0095] ,

[0096] in, The mean vector of the node embedding. The total number of nodes. For the first Embedded representation of each node, The covariance matrix of the node embedding. Represents matrix transpose. Represents the source domain. Represents the target domain.

[0097] Figure 3 This is a schematic diagram of the prototype distribution alignment process provided in an embodiment of this application. In an optional embodiment, the source domain and the target domain are denoted as follows: ... The clustering proportions on the prototype categories are respectively and ,in The parameters are determined by the prototype layer parameters cached after training in the source domain, serving as a stable semantic prior. The calculation is based on the soft assignment results of the nodes to the prototype during the training phase at the time of testing, and its definition is as follows:

[0098] ,

[0099] in, Represents the target domain node Assigned to the The probability of a prototype.

[0100] To align the prototype distributions of the source and target domains, the difference between the prototype distributions of the two domains is minimized using symmetric KL divergence. Therefore, the prototype distribution alignment loss is defined as:

[0101] ,

[0102] in, The prototype distribution alignment loss between the source and target domains is denoted as . For the prototype distribution of the target domain, , This represents the prototype distribution of the source domain. , The KL divergence is used. This alignment constraint, on the one hand, suppresses drastic changes in the target domain prototype distribution, avoiding the adaptation of category semantics during the process; on the other hand, it aligns the target domain to the source domain at the category conditional distribution level, thereby effectively mitigating the negative impact of concept shift on the decision boundary.

[0103] By combining global embedding distribution alignment and category prototype distribution alignment, a multi-level domain alignment loss function is constructed:

[0104] ,

[0105] Among them, hyperparameters This strategy is used to balance the proportions of the two alignments. The joint optimization strategy enables the model to correct covariate shifts caused by changes in feature distribution during the adaptation process, while maintaining a stable class discrimination structure. This effectively mitigates the combined effects of covariate and concept shifts under unlabeled conditions.

[0106] By combining the multi-level alignment loss and the prototype contrast loss, the total loss is determined as follows:

[0107] ,

[0108] in, This is a hyperparameter.

[0109] S4: The input data is analyzed and processed using the optimized graph neural network model to obtain the prediction results.

[0110] The present invention provides a test-time adaptation method for out-of-distribution offset graph neural networks. The overall process is divided into three stages: training stage, test-time training stage, and test stage. (1) In the training stage, the main task loss and the graph contrastive learning loss based on prototype clustering are jointly optimized on the source domain graph to learn the shared encoder and the initial category prototype. GradNorm adaptively balances the gradients of the two tasks to obtain node representations that are both discriminative and semantically aggregated, and each category prototype is used as the semantic prior for subsequent test-time adaptation. (2) In the test-time training stage, the parameters of the main task classification head and the self-supervised head are frozen. The target domain nodes are softly assigned using the source domain prototypes to construct a prototype-guided pseudo-label view. On this basis, self-supervised contrastive learning optimization is performed. At the same time, a multi-level domain alignment mechanism of global statistical alignment and prototype distribution alignment is introduced. On the one hand, the mean and covariance of the embeddings of the source domain and the target domain are aligned to alleviate the covariate bias. On the other hand, the category prototype distributions of the two domains are aligned to reduce the impact of concept bias on the decision boundary. (3) In the test stage, the updated encoder and the classification head of the main task are used to predict the continuously arriving test nodes. This method improves the accuracy of prediction results and the generalization ability of the model when the data has distributional bias.

[0111] The present invention also experimentally verifies that the method can simultaneously improve the out-of-distribution generalization and adversarial robustness of the model within a unified framework.

[0112] The experiment systematically evaluates the performance of the proposed method using the graph OOD evaluation datasets used in the EERM work and the graph OOD evaluation datasets proposed by GOOD. The EERM evaluation datasets cover various typical distribution migration scenarios, including: (1) the artificially constructed migrations Cora and Amazon-Photo datasets, used to simulate migrations such as node features and structural perturbations; (2) the temporally evolved OGB-Arxiv and Elliptic datasets, used to characterize temporal migrations in real-world scenarios; and (3) the cross-domain migration Twitch-E dataset, used to evaluate the model's generalization ability across different domains. Furthermore, to further systematically analyze the differences in model behavior under different types of distribution migrations, the GOOD evaluation datasets explicitly divide migrations into covariate migrations and concept migrations, including the GOOD-Cora, GOOD-Arxiv, and GOOD-Twitch datasets. Statistical information for the above datasets is shown in Tables 1 and 2.

[0113] Table 1. Statistical Information of the EERM Benchmark Dataset

[0114]

[0115] Table 2 Statistical Information of the GOOD Benchmark Dataset

[0116]

[0117] To verify the effectiveness of the proposed method, this work compares it with five baseline methods and the proposed Graph Neural Network Test-Time Adaptation (ProGTA) method for out-of-distribution generalization:

[0118] ERM (Empirical Risk Minimization): Train model parameters by minimizing the average loss (empirical risk) on the training data.

[0119] DropEdge: Data augmentation is achieved by randomly removing or adding a certain proportion of edges in the input graph during training, thereby increasing the randomness and diversity of the input data. It aims to alleviate the oversmoothing problem during training and improve the robustness of GNN models to noise and distribution changes.

[0120] Tent: A fully test-time adaptive method that optimizes model parameters online by minimizing the Shannon entropy (i.e. confidence uncertainty) of the model's predictions of test samples. Its core is to use unlabeled test data to update batch normalized statistics and a small number of parameters, thereby reducing the generalization error caused by distribution bias.

[0121] EERM: It addresses distribution shifts in graph data from an invariant learning perspective. It generates multiple different graphs based on the input graph data and helps the model learn invariant representations across domains by optimizing the mean and variance of risk losses corresponding to different environments.

[0122] GTrans: A test-time graph transformation framework that improves model performance by dynamically adjusting and optimizing graph data during the testing phase. This method mitigates distribution shifts solely through data-level transformations without modifying model parameters.

[0123] In this experiment, the backbone network adopted the mainstream Graph Convolutional Networks (GCN) and Graph Attention Networks (GAT) architectures. All models were implemented in the PyTorch framework, and training used the Adam optimizer (learning rate 0.01, weight decay 5e-4). Accuracy (ACC) and F1 score were used as metrics to measure the model's out-of-distribution generalization ability. All experiments were repeated 5 times, and the average value was taken as the final result.

[0124] Table 3 summarizes the experimental results on the EERM evaluation dataset. The results show that the proposed ProGTA method achieves optimal or near-optimal performance on different datasets and with different backbone network settings, and exhibits stable generalization superiority in various distribution shift scenarios. Specifically, in artificially constructed shift and cross-domain shift scenarios (Cora, Amazon-Photo, and Twitch-E datasets), ProGTA achieves significant improvements over methods such as DropEdge and Tent, indicating that relying solely on random structure perturbations or prediction entropy minimization is insufficient to adequately handle complex distribution shifts. In contrast, ProGTA introduces prototype-guided homogeneity enhancement and test-time adaptation mechanisms to adjust the target domain data online, enabling the model to more specifically adapt to changes in feature parts and local structures, thus achieving better generalization performance in artificial and cross-domain shift scenarios. Furthermore, Figure 4 The results show that ProGTA maintains higher overall accuracy across multiple OOD test graphs on the Cora dataset and exhibits a more consistent trend, indicating that its performance improvement is stable across test graphs rather than just an occasional gain on individual graphs.

[0125] Table 3. Experimental Results under the EERM Evaluation Dataset

[0126]

[0127] Meanwhile, the experimental results in Table 3 show that ProGTA maintains a relatively stable performance advantage across different backbone network settings in temporal evolution shift scenarios (Elliptic, OGB-Arxiv). The distribution shifts in this type of dataset are often accompanied by potential semantic changes. ProGTA exhibits better stability with smaller performance degradation in test partitions with larger time spans. The results indicate that the distribution and category features of test samples in this type of dataset continuously change over time, making the model more prone to prediction instability during the inference phase. In contrast, ProGTA can guide the target domain representation using category prototypes during test-time adaptation, resulting in more consistent predictions across consecutive time slices and thus achieving superior overall performance in temporal evolution scenarios.

[0128] The experimental results on the GOOD graph OOD evaluation dataset are shown in Table 4. GCN and GAT were used as backbone models for evaluation to verify the generality of the proposed method. Overall, ProGTA achieved best or near-best performance on different datasets and with different offset types, demonstrating relatively stable generalization ability. To further visually demonstrate the performance differences of different methods under the two offset settings, Figure 5 The accuracy of each method on the GOOD-Cora dataset is compared in terms of covariate shift and concept shift scenarios. Specifically,

[0129] In terms of performance under covariate shift, ProGTA achieves a stable improvement over methods such as ERM, DropEdge, and Tent. Experimental results show that covariate shift primarily causes changes in node feature distribution and structural statistics, leading to feature mismatch issues during testing. In contrast, ProGTA continuously adjusts the target domain features during the adaptation process during testing, effectively mitigating the performance degradation caused by changes in feature distribution.

[0130] The performance differences between different methods are even more significant in the context of concept shift. As shown in Table 4, methods such as EERM and GTrans offer limited improvements in this type of scenario, and even experience performance degradation in some settings, indicating that relying solely on feature-level adaptation is insufficient to effectively address changes in category semantics. In contrast, ProGTA demonstrates a clear advantage in concept shift scenarios. Experimental results show that ProGTA maintains higher and more stable prediction performance in this type of task, enabling the model to maintain good discriminative performance even when category semantics change. This phenomenon suggests that introducing category-level constraints has a positive effect on the model's generalization performance in concept shift scenarios, helping to mitigate the performance degradation caused by changes in category semantics.

[0131] Experimental results on the GOOD evaluation dataset for different offset types show that ProGTA exhibits good adaptability in both covariate and concept offset scenarios. Its advantage is particularly pronounced in the concept offset scenario, further validating the stability and effectiveness of this method under complex distributional settings.

[0132] Table 4. Experimental Results under the GOOD Evaluation Dataset

[0133]

[0134] Beyond the conventional out-of-distribution generalization evaluation, this study further examines the robustness of the proposed method in adversarial attack scenarios. Previous research has shown that adversarial attacks alter the distribution of samples by applying targeted perturbations to node features or graph structure, leading to a decline in model prediction performance. From the perspective of distribution learning, adversarial perturbations can be viewed as a directional out-of-distribution shift; therefore, adversarial robustness and out-of-distribution generalization are intrinsically linked to some extent.

[0135] Based on the above understanding, the adversarial robustness of ProGTA was experimentally evaluated under an adversarial attack setting. Specifically, the PR-BCD attack algorithm was used to perturb the test graphs of the Cora, Citeseer, and OGB-Arxiv datasets (i.e., escape attack), with the perturbation ratio gradually increasing from 5% to 25% to simulate adversarial attacks of different intensities. The experiment used GCN as the backbone network and compared it with methods such as RobustGCN, SimPGCN, GCNJaccard, and GTrans.

[0136] The experimental results are shown in Figures 6(a), (b), and (c). It can be observed that ProGTA maintains relatively more stable prediction performance under different perturbation intensities, especially at high perturbation rates, where its performance degradation is significantly less than the comparative methods. This indicates that ProGTA not only possesses a certain degree of robustness against perturbations in adversarial attack scenarios, but its robustness advantage also becomes more pronounced as the attack intensity increases.

[0137] Based on experimental observations, ProGTA's improved robustness in adversarial attack scenarios may be related to its modification of the model's decision boundary during the adaptation process in testing. Adversarial attacks typically apply targeted perturbations to cause samples to cross the original discrimination boundary and lead to incorrect predictions. If the model can adjust its discrimination structure according to the perturbed data distribution during the testing phase, it can help mitigate the performance degradation caused by the attack.

[0138] In ProGTA, the prototype alignment strategy constrains the discriminative regions of samples by introducing stable class semantic centers in the feature space. This compresses the ambiguous regions between classes to some extent, thereby prompting the decision boundary to adjust towards a more discriminative direction. This stabilizing effect on the discriminative structure helps mitigate the impact of adversarial attacks on model predictions, thus improving the model's adversarial robustness.

[0139] To further verify the necessity and relative contribution of each component module of ProGTA, systematic ablation experiments were conducted on five OOD datasets: Cora, OGB-Arxiv, Elliptic-E, Amz-Photo, and GOOD-Cora. ​​All other settings remained consistent with the effectiveness experiments. The ablation settings included:

[0140] (1) TTT: Remove the prototype clustering graph contrast learning module and the multi-level alignment module, and degenerate into the standard test training method.

[0141] (2) ProGTA-w / o Align: Remove the multi-level alignment module and retain the prototype clustering graph contrast learning module.

[0142] (3) ProGTA-w / o Pro-Align: Remove the prototype alignment module, and retain the prototype clustering graph contrast learning and feature distribution alignment modules.

[0143] Figure 7 Experimental results show that removing the prototype clustering contrastive learning module and the multi-level alignment module degenerates into the standard TTT method. At this point, the model's performance on all OOD datasets shows a significant downward trend. This phenomenon indicates that relying solely on instance-level self-supervised signals is insufficient to stabilize the class semantic structure and easily leads to semantic shifts under distribution shift conditions. Furthermore, removing the multi-level alignment module degenerates the model into ProGTA-w / o Align, where performance also declines. Specifically, removing prototype distribution alignment degenerates into ProGTA-w / o Pro-Allign, where the model's performance significantly decreases under concept shift scenarios. This indicates that feature-level adaptation alone is insufficient to cope with changes in class conditional distribution. This result verifies that aligning the prototype distributions of the source and target domains can effectively mitigate the impact of concept shifts on the model's discriminative ability.

[0144] To evaluate ProGTA's generalization ability across different offset scenarios, sensitivity analysis was performed on two key hyperparameters. Specifically, this included the weighting coefficients of the multi-level alignment loss in the target adaptation during testing. The number of steps to adapt and update during testing. .

[0145] The experiments were conducted on the Cora, OGB-Arxiv, GOOD-Cora (Covariate), and GOOD-Cora (Concept) datasets. Except for the parameters being analyzed, all other parameters were consistent with those in the main experiment.

[0146] Multi-level alignment loss weights The experimental results are as follows Figure 8 As shown. Specifically, with Increasing the model size from 0, the performance on all datasets shows a trend of first improving and then decreasing, indicating that during the adaptation process during testing, a balance needs to be maintained between the prototype's self-supervised signals and multi-level alignment constraints. Further comparison of different datasets reveals that the best performance on OGB-Arxiv corresponds to... Slightly higher than Cora, this indicates that in scenarios with more complex and continuously changing distribution shift models, appropriately enhancing multi-level alignment constraints can help improve the model's generalization ability. Meanwhile, the covariate shift and concept shift results from the GOOD-Cora dataset show that the concept shift task is more effective for... The increased sensitivity indicates that appropriate alignment constraints are particularly important for stabilizing category semantics. Overall, values ​​in the range of 0.4–0.6 exhibit good stability across different scenarios.

[0147] Adaptation steps during testing The experimental results are as follows Figure 9 As shown. Specifically, with With each dataset, the model's performance initially improves rapidly before saturating or even slightly declining. This indicates that updating the model with only a few test iterations significantly enhances its adaptability to the target domain distribution, while excessive updates may lead to overfitting to the test samples. These results demonstrate that ProGTA achieves stable gains with a relatively small number of test iterations, eliminating the need for extensive iterations.

[0148] To evaluate the computational cost of ProGTA, this section analyzes the time complexity of its main modules. Let the target domain graph be... ,in , , To represent dimensions, For the number of GNN layers, For the number of categories, To adapt the number of steps during testing, in each TTA update step, the model first performs a GNN forward propagation, with a complexity of O(log n). Subsequently, prototype clustering contrastive learning calculates the loss based on the similarity between node representations and prototypes, with a complexity of O(n). Multi-level alignment includes global statistical alignment and prototype distribution alignment, with complexities of [missing information]. and Therefore, to carry out The complexity of the step update is: .

[0149] To verify the fine-tuning efficiency of the proposed method, ProGTA was compared with the mainstream invariant learning method EERM and the representative test adaptation framework GTrans in terms of time consumption and content complexity. All experiments were conducted in the same hardware environment (NVIDIA RTX 3090 GPU, 24GB VRAM, Intel(R) Core(TM) i9-10940X CPU 3.30GHz), and the average time required for each model to complete one fine-tuning update was recorded. Table 5 shows the specific experimental results. It can be seen that ProGTA significantly improves the computational efficiency of the testing phase while maintaining adaptation performance. On small-scale graph datasets (such as Cora), it is slightly better than GTrans. On large-scale graph datasets (such as Elliptic and Arxiv), because the prototype guidance mechanism can reduce redundant comparisons and iterations, ProGTA only needs to focus on the test data, so its time consumption is much less than that of the EERM method, which requires retraining. Regarding GPU memory usage, ProGTA requires only a few adaptive adjustments to the test data, resulting in significantly lower memory usage than EERM. However, it is slightly more memory-intensive than GTrans, which only fine-tunes the data.

[0150] Table 5 Complexity Analysis Table

[0151]

[0152] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0153] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A test-time adaptation method for graph neural networks oriented towards out-of-distribution offset, characterized in that, The method includes: Obtain a graph dataset containing related category label information, and divide the graph dataset into a training set, a validation set, and a test set; The target graph neural network model is trained using the training set based on the main task loss and the self-supervised auxiliary task loss, resulting in a trained graph neural network model and multiple initial class prototypes. The self-supervised auxiliary task loss is the prototype graph contrast learning loss. The parameters of the graph neural network model are optimized using a test set based on prototype graph contrastive learning loss and multi-level domain alignment constraints. The prototype graph contrastive learning loss includes prototype contrastive learning loss and prototype clustering loss. The multi-level domain alignment constraints include global distribution difference constraints between the source domain and the target domain and prototype distribution alignment constraints between the source domain and the target domain. The optimized graph neural network model is used to analyze and process the input data to obtain the prediction results.

2. The method according to claim 1, characterized in that, The target graph neural network model is trained using the training set based on the main task loss and the self-supervised auxiliary task loss, resulting in a trained graph neural network model and multiple initial category prototypes, including: The parameters of the target graph neural network model are updated using gradient descent on the source domain graph by combining the main task loss and the prototype graph comparative learning loss until the performance of the target graph neural network model on the validation set no longer improves. The updated network parameters, the embedding representation of the source domain, and the prototype distribution are retained. The network parameters include shared encoder parameters, main task head parameters, and self-supervised auxiliary task head parameters.

3. The method according to claim 1, characterized in that, The prototype comparison learning includes: Determine the similarity between each node in the target domain and the category prototype in the source domain, and assign pseudo-labels to the nodes based on the similarity. Determine the homogeneity score of the connecting edge between any two nodes, and perform homogeneity enhancement on the connecting edge based on the homogeneity score to obtain an enhanced view; Initialize a set of trainable class prototype vectors, perform graph contrastive learning based on the initialized class prototype vectors and the augmented view, and introduce prototype clustering loss.

4. The method according to claim 3, characterized in that, The process of determining the similarity between each node in the target domain and the category prototype in the source domain, and assigning pseudo-labels to the nodes based on the similarity, includes: Determine the cosine similarity between the embedding vector of each node in the target domain and the prototype vector in the source domain, and determine the soft assignment probability of the node in the target domain relative to each category of prototype in the source domain based on the cosine similarity. The source domain category with the highest soft probability to which the target domain node belongs is used as the pseudo-label of the target domain node.

5. The method according to claim 4, characterized in that, The process of determining the homogeneity score of the connecting edge between any two nodes and enhancing the homogeneity of the connecting edge based on the homogeneity score to obtain an enhanced view includes: The homogeneity score of the connecting edge is determined based on the neighbor set of one of the nodes corresponding to the connecting edge and the pseudo-labels of the two nodes corresponding to the connecting edge. Determine whether the homogeneity score is higher than a preset threshold; If so, the connecting edge is retained; If not, then the connecting edge is perturbed.

6. The method according to claim 3, characterized in that, The prototype contrastive learning loss satisfies the following formula: , in, Prototype-based contrastive learning loss, This is the original node embedding vector. To enhance the node embedding vector in the view, For temperature coefficient, For nodes The allocation prototype, Indicates the first One prototype vector.

7. The method according to claim 3, characterized in that, The prototype clustering loss satisfies the following formula: , in, For clustering loss, The total number of nodes. The square of the vector norm. For nodes The assigned prototype vector, For hyperparameters, For margin, For the first The prototype vector of a class. For the first The prototype vector of the class.

8. The method according to claim 1, characterized in that, The global distribution difference constraint between the source domain and the target domain satisfies the following formula: , in, The global distribution alignment loss between the source and target domains is given. The mean of the target domain. The mean of the source domain is . The covariance of the target domain, Let the covariance of the source domain be , The square of the L2 norm, It is the square of the Frobenius norm.

9. The method according to claim 1, characterized in that, The prototype distribution alignment constraint between the source domain and the target domain satisfies the following formula: , in, The prototype distribution alignment loss between the source and target domains is denoted as . For the prototype distribution of the target domain, This represents the prototype distribution of the source domain. Let KL divergence be denoted as KL divergence.