GraphShapIQ Implementation - #550
Open
Proman9000 wants to merge 171 commits into
Open
Conversation
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 448a849.
This reverts commit 3962259.
test: added more tests for graph game
|
@mmschlk could you review the changes please? :) |
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
requested changes
Jul 14, 2026
mmschlk
left a comment
Owner
There was a problem hiding this comment.
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.
added some minor changes to the code
Add shapiq.graph to API reference
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.
feat: added graphshapiq example
Support coalitions with more than 63 members in Moebius transform
fix: fixed doc building
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
MoebiusConverterThis PR adds a new
shapiq.graphsubpackage implementing this algorithm.GraphGame: This class wraps a GNN model (GCN, GIN, or GAT) together with an input graph. Players are graph nodes, andvalue_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 aGraphGame, computes Moebius coefficients, and converts them to the target interaction index using the existingMoebiusConverter.GraphExplainer: This class integratesGraphSHAPIQinto shapiq's explainer framework, following theTreeExplainerpattern. Constructs theGraphGameinternally and exposes a cleanexplain(x)API.Public API Changes
New
shapiq.graphsubpackage exposingGraphGame,GraphSHAPIQ, andGraphExplainer.How Has This Been Tested?
The
GraphSHAPIQalgorithm has been thoroughly tested, including correctness againstExactComputeron small graphs, the efficiency axiom, all three GNN architectures (GCN, GIN, GAT), and edge cases (disconnected graphs, single-node graphs, fully connected graphs).GraphGamehas also been thoroughly tested.GraphExplainerand the L-Shapley algorithm have been only slightly tested so far. Overall test coverage is above 90%.Checklist
CHANGELOG.md(if relevant for users).