Bounded and Uniform Energy-based Out-of-distribution Detection for Graphs

Shenzhi Yang, Bin Liang, An Liu, Lin Gui, Xingkai Yao, Xiaofang Zhang

Abstract

Given the critical role of graphs in real-world applications and their high-security requirements, improving the ability of graph neural networks (GNNs) to detect out-of-distribution (OOD) data is an urgent research problem. The recent work GNNSAFE proposes a framework based on the aggregation of negative energy scores that significantly improves the performance of GNNs to detect node-level OOD data. However, our study finds that score aggregation among nodes is susceptible to extreme values due to the unboundedness of the negative energy scores and logit shifts, which severely limits the accuracy of GNNs in detecting node-level OOD data. In this paper, we propose NODESAFE: reducing the generation of extreme scores of nodes by adding two optimization terms that make the negative energy scores bounded and mitigate the logit shift. Experimental results show that our approach dramatically improves the ability of GNNs to detect OOD data at the node level, e.g., in detecting OOD data induced by Structure Manipulation, the metric of FPR95 in scenarios without (with) OOD data exposure are reduced from the current SOTA by 28.4% (22.7%).

Introduction

In real-world applications like fraud detection or social network analysis, Graph Neural Networks (GNNs) often encounter data that does not match their training distribution. If a model lacks the "self-awareness" to recognize novel data, it may produce confident but erroneous predictions.

Previous state-of-the-art methods, such as GNNSAFE, employ energy-based models where a "negative energy score" is calculated for each node and aggregated across its neighborhood to leverage graph structure. However, this approach has two critical flaws:

  1. Unbounded Scores: Negative energy scores can theoretically be infinite. A single outlier node with an extreme score can propagate "noise" to its entire neighborhood, undermining detection accuracy for many nodes.
  2. Logit Shift: Softmax classification is shift-invariant; adding a constant to logits preserves the class prediction but significantly alters the energy score. This makes energy-based detection unstable and sensitive to internal numerical shifts.

Methodology: The NODESAFE Framework

To overcome these limitations, we propose NODESAFE, which introduces two optimization terms to the GNN training process:

  • Bounded Energy ($L_{bound}$): This term constrains the 2-norm of the logit vector, mathematically forcing negative energy scores to remain within a predictable range.
  • Uniform Energy ($L_{uniform}$): This term minimizes the variance of the sum of the logits, mitigating the logit shift problem and ensuring that energy scores are more uniform and stable across different samples.

Together, these constraints ensure that when scores are aggregated across the graph, the variance remains low, making it much easier to distinguish between In-Distribution (ID) and OOD nodes.

Figure 5: Visualization of (a) Out-of-Distribution and (b) In-Distribution graph structures, and (c) the effect of NODESAFE's variance reduction on energy score distributions.

Experimental Evaluation

We evaluated NODESAFE on five diverse graph datasets: citation networks (Cora, Citeseer, Pubmed), the large-scale ogbn-Arxiv dataset (partitioned by time), and the Twitch-Explicit social network. The framework was tested against three types of OOD "attacks": Structure Manipulation (changing edges), Feature Interpolation (blending node features), and Label Leave-out (introducing new categories).

Key Results and Insights

The performance gains were substantial across all benchmarks:

  • Error Reduction: On the Cora dataset (Structure Manipulation), the FPR95 (False Positive Rate at 95% True Positive Rate) dropped from 73.15% (previous SOTA) to just 25.63%.
  • Efficiency: The method adds negligible computational overhead. Training and inference times are nearly identical to standard GNNs, while the model converges faster to a stable state.
  • Visualization: Logit visualizations show that NODESAFE creates much tighter, more distinct clusters for different classes compared to standard training.
Figure 6: Logit visualization using standard cross-entropy loss ($L_{CE}$), illustrating the baseline cluster distribution before applying NODESAFE constraints.

Conclusion

While neighbor aggregation is a core strength of GNNs, it acts as a double-edged sword for OOD detection. Without bounds, a single outlier can "blind" an entire subgraph. NODESAFE addresses this by effectively distributing logits on a hypersphere, providing mathematical guarantees on energy score bounds. Future work will explore how these constraints apply to more complex structures, such as heterophily or dynamic graphs.

Summary updated

BibTeX
@inproceedings{yang2024bounded,
  author = {Shenzhi Yang and Bin Liang and An Liu and Lin Gui and Xingkai Yao and Xiaofang Zhang},
  title = {{Bounded and Uniform Energy-based Out-of-distribution Detection for Graphs}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=mjh7AOWozN},
}
Figure