Skip to content

Adapt fidelity and unfaithfulness to HeteroExplanation#10677

Open
Mellandd wants to merge 2 commits intopyg-team:masterfrom
Mellandd:hetero-explain-metrics
Open

Adapt fidelity and unfaithfulness to HeteroExplanation#10677
Mellandd wants to merge 2 commits intopyg-team:masterfrom
Mellandd:hetero-explain-metrics

Conversation

@Mellandd
Copy link
Copy Markdown

@Mellandd Mellandd commented Apr 28, 2026

Adapts the explainability metrics in torch_geometric.explain.metric to heterogeneous graphs (#9112 ).

fidelity and unfaithfulness previously assumed a homogeneous Explanation and accessed explanation.x / explanation.edge_index with plain tensor masks. When called with a HeteroExplanation they failed, masks live per node/edge type and complement masks need to be computed per-type.

Changes

  • fidelity.py: early dispatch to a new _hetero_fidelity helper for HeteroExplanation; the homogeneous body is left unchanged. Adds a private _hetero_model_kwargs helper that reconstructs the original model kwargs from _model_args, respecting the *_dict suffix convention used by the explainer.

  • faithfulness.py: same dispatch pattern with _hetero_unfaithfulness. In the heterogeneous branch top_k is applied per node type and clamped to the number of features available for that type.

  • New tests test_fidelity_hetero (2) and test_unfaithfulness_hetero (24, parametrised on top_k × explanation_type × node_mask_type × return_type).

Dependency

Full kwargs propagation (e.g. edge_attr_dict) requires _model_args to be populated on HeteroExplanation, which is the subject of #10676 . This PR uses getattr(explanation, '_model_args', []) so it degrades gracefully when running against a base without that change.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant