Skip to content

GraphShapIQ Implementation - #550

Open
Proman9000 wants to merge 171 commits into
mmschlk:mainfrom
luffdavid:main
Open

GraphShapIQ Implementation#550
Proman9000 wants to merge 171 commits into
mmschlk:mainfrom
luffdavid:main

Conversation

@Proman9000

@Proman9000 Proman9000 commented Jun 16, 2026

Copy link
Copy Markdown

Motivation and Context

GraphSHAP-IQ is an algorithm for computing exact Shapley interaction values for Graph Neural Networks (GNNs), by Muschalik et. al https://arxiv.org/abs/2501.16944. It is the graph analogue of TreeSHAP-IQ and exploits the locality of message passing in GNNs. A node's embedding after L layers depends only on its L-hop neighborhood (its receptive field), which means Moebius interactions between nodes are zero unless all nodes fall within a single receptive field. This reduces the complexity from O(2^n) to O(n * 2^r), where r is the maximum receptive field size.

The algorithm works by:

  1. Computing the L-hop receptive field for each node via BFS
  2. Enumerating only coalitions within these receptive fields (not all 2^n)
  3. Batch-evaluating these coalitions through the GNN game
  4. Computing Moebius coefficients from the evaluations
  5. Converting Moebius coefficients to the target interaction index via shapiq's existing MoebiusConverter

This PR adds a new shapiq.graph subpackage implementing this algorithm.

  • GraphGame: This class wraps a GNN model (GCN, GIN, or GAT) together with an input graph. Players are graph nodes, and value_function(coalitions) evaluates the GNN's prediction for each coalition by masking absent nodes' features to a baseline while keeping the graph structure intact. Supports both classification and regression GNNs.
  • GraphSHAPIQ: The core algorithm. Computes each node's L-hop receptive field via BFS, enumerates and deduplicates the union of powersets over these receptive fields, batch-evaluates them through a GraphGame, computes Moebius coefficients, and converts them to the target interaction index using the existing MoebiusConverter.
  • GraphExplainer: This class integrates GraphSHAPIQ into shapiq's explainer framework, following the TreeExplainer pattern. Constructs the GraphGame internally and exposes a clean explain(x) API.

Public API Changes

  • Yes, Public API changes (Details below)

New shapiq.graph subpackage exposing GraphGame, GraphSHAPIQ, and GraphExplainer.

How Has This Been Tested?

The GraphSHAPIQ algorithm has been thoroughly tested, including correctness against ExactComputer on small graphs, the efficiency axiom, all three GNN architectures (GCN, GIN, GAT), and edge cases (disconnected graphs, single-node graphs, fully connected graphs). GraphGame has also been thoroughly tested. GraphExplainer and the L-Shapley algorithm have been only slightly tested so far. Overall test coverage is above 90%.

Checklist

  • The changes have been tested locally.
  • Documentation has been updated (if the public API or usage changes).
  • An entry has been added to CHANGELOG.md (if relevant for users).
  • The code follows the project's style guidelines.
  • I have considered the impact of these changes on the public API.

Finn Jacob Eliyah Krammer and others added 30 commits May 1, 2026 20:02
Skeleton for GraphSHAPIQXAI
…ors, and four different replacement strategies: averaging over each feature, taking the min or max feature value, or a feature vector of zeros. Also added a test model to try out the setup. Added a testing script to run tests from.
This reverts commit 3962259.
@amndzdzdz

Copy link
Copy Markdown

@mmschlk could you review the changes please? :)

@mmschlk

mmschlk commented Jul 14, 2026

Copy link
Copy Markdown
Owner

@amndzdzdz, I will review/make changes to the methodological aspects of this PR again after the 17th for preparing the final merge into shapiq. :)

@mmschlk mmschlk left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The graph package is still not getting displayed in the existing documentation. For this you have to change the api reference list for sphinx. Also, there are still no example scripts inside the examples folder.

amndzdzdz and others added 12 commits July 15, 2026 15:39
added some minor changes to the code
The subset enumeration in moebius.cc used a single uint64_t as the local
subset counter, which is undefined behaviour for coalitions of size k >= 64
(shift by >= 64 bits). Replace it with a multi-word counter: an array of
uint64_t words acting as one arbitrarily wide integer, where bit b lives in
word b >> 6 at position b & 63. Incrementing propagates the carry across word
boundaries, so the 2^k enumeration is correct for any k.

The rest of the Moebius logic is unchanged; for k <= 63 the counter is a
single word, so the existing Python-equivalence tests cover the same code
path. The practical bound on k is now the 2^k runtime, not the counter width.

Add test-only _counter_increment / _counter_test_bit exports to cext.cc and
tests exercising the carry across uint64 word boundaries and the termination
bit at k = 64, which cannot be reached end-to-end.
Support coalitions with more than 63 members in Moebius transform
@mmschlk mmschlk self-assigned this Aug 11, 2026
@mmschlk mmschlk added feature 💡 New feature or enhancement request explainer 🔍 All issues that are linked to explainers labels Aug 11, 2026
@mmschlk mmschlk added this to the v1.8.0 milestone Aug 24, 2026
@mmschlk

mmschlk commented Aug 24, 2026

Copy link
Copy Markdown
Owner

I will be bringing this in for 1.8.0. The next release contains a lot of work on the shapiq.tree side and I do not want to mix concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

explainer 🔍 All issues that are linked to explainers feature 💡 New feature or enhancement request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

7 participants