graphtoolbox.interpretability.diagnostics¶
Reusable edge-attribution and ALE diagnostics.
- class graphtoolbox.interpretability.diagnostics.RegressionExplanationWrapper(model)[source][source]¶
Bases:
ModuleExpose a GraphToolbox model as a plain node-regression callable.
- forward(x, edge_index, **kwargs)[source][source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- graphtoolbox.interpretability.diagnostics.make_edge_explainer(model, epochs: int = 100)[source][source]¶
Build a PyG
GNNExplainerconfigured for node regression.
- graphtoolbox.interpretability.diagnostics.compute_edge_masks(dataset, model, epochs: int = 100, limit: int | None = None, output_path: str | None = None) ndarray[source][source]¶
Run an edge explainer on graph snapshots and optionally cache its masks.
- graphtoolbox.interpretability.diagnostics.topk_indices(values, count: int) set[int][source][source]¶
Indices of the
countlargest values.
- graphtoolbox.interpretability.diagnostics.explainer_reproducibility(dataset, model, day: int = 0, runs: int = 2, epochs: int = 100) dict[str, float][source][source]¶
Measure agreement between independent explanations of one snapshot.
- graphtoolbox.interpretability.diagnostics.dump_attention_batches(model, dataset, output_dir: str, batch_size: int = 32, require_full_batch: bool = True) int[source][source]¶
Save attention dictionaries for successive PyG mini-batches.
- graphtoolbox.interpretability.diagnostics.load_attention_batches(attention_dir: str)[source][source]¶
Load cached attention as a
[snapshots, edges]tensor.Heads and message-passing layers are averaged. The returned edge index is checked for consistency across cached batches.
- graphtoolbox.interpretability.diagnostics.aggregate_ale_importance(table, group_col: str = 'group', value_col: str = 'importance', reduction: str = 'mean')[source][source]¶
Aggregate feature-level ALE importance into normalized group shares.
The default is a mean so groups with many lag columns are not rewarded merely for containing more features. Pass
reduction='sum'when total feature importance, rather than typical within-group importance, is desired.