Skip to content

feat(metric): add Symmetric Relevance Gain (SRG)#374

Draft
adrhill wants to merge 5 commits into
understandable-machine-intelligence-lab:mainfrom
adrhill:ah/srg
Draft

feat(metric): add Symmetric Relevance Gain (SRG)#374
adrhill wants to merge 5 commits into
understandable-machine-intelligence-lab:mainfrom
adrhill:ah/srg

Conversation

@adrhill

@adrhill adrhill commented Jun 11, 2026

Copy link
Copy Markdown

Description

  • Adds the Symmetric Relevance Gain (SRG) faithfulness metric by Blücher et al., TMLR 2024. SRG runs two pixel-flipping experiments that share one feature ordering — most influential first (MIF) and least influential first (LIF) — and scores the area between the two prediction curves, SRG = AUC(LIF) − AUC(MIF). The random-ordering baseline cancels in the difference, which makes attribution rankings largely insensitive to the occlusion strategy (baseline value, step size).

Implemented changes

  • Metric implementation: quantus.SymmetricRelevanceGain in quantus/metrics/faithfulness/symmetric_relevance_gain.py, registered in AVAILABLE_METRICS and the faithfulness __init__.py
    • Arguments follow the established pixel-flipping metric conventions (features_in_step, perturb_func, perturb_baseline, ...); supports both PyTorch and TensorFlow models
    • Constant imputer as in the paper: perturb_func is applied once per batch to the unperturbed input and every occlusion step copies values from that snapshot, so stochastic baselines are drawn once and results are independent of how the default perturbation function is passed
    • The default perturb_baseline=0.0 reproduces the paper's channel-wise data set mean imputer for inputs normalized to zero channel mean (e.g. standard ImageNet preprocessing); the docstring documents this assumption and the alternatives for unnormalized inputs
    • The abs docstring and parameterisation warning give method-conditional guidance: keep abs=False where the attribution's sign encodes evidence for/against the class (e.g. LRP, Shapley, IG); use abs=True for sensitivity maps whose sign reflects a direction in color space (e.g. raw gradients)
    • Both curves are evaluated with one concatenated forward pass per occlusion step; a torch-resident fast path keeps perturbed inputs on-device, with a framework-agnostic numpy fallback for other models
  • Tests: fixture-based and invariant tests in tests/metrics/test_faithfulness_metrics.py (sign-flip antisymmetry, shared curve endpoints, torch-path vs. numpy-path equivalence, explicit default perturb_func equals perturb_func=None)
  • Docs: API page added under docs/source/docs_api/

CC @bluecher31 (paper author)

🤖 Generated with Claude Code

adrhill and others added 5 commits June 11, 2026 12:05
Implements the SRG faithfulness metric (Blücher et al., TMLR 2024): the
area between the LIF and MIF pixel-flipping curves computed from a
shared feature ordering. The random-ordering baseline cancels in the
difference, making rankings robust to the occlusion strategy.

- `quantus.SymmetricRelevanceGain` evaluates both curves with one
  concatenated forward pass per occlusion step, plus a torch-resident
  fast path that keeps perturbed inputs on-device
- `n_steps` parameter for coarse stepping; the baseline imputer is
  computed once per batch from the unperturbed input
- registered in `AVAILABLE_METRICS`, docs page added, fixture-based
  tests and invariant tests (sign-flip antisymmetry, shared curve
  endpoints, torch path vs. numpy path equivalence)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Review follow-ups for the SRG metric:

- declare TensorFlow support in `model_applicability`: the numpy path
  only uses the framework-agnostic `ModelInterface` API
- make the constant imputer the single perturbation contract:
  `perturb_func` is applied once per batch to the unperturbed input and
  all occlusion steps copy from that snapshot, so passing the default
  function explicitly now matches `perturb_func=None` and the torch
  fast path works with any perturbation function (regression test added)
- replace `n_steps` with the conventional `features_in_step` knob and
  assert against `x_batch.shape[2:]` like `PixelFlipping`
- drop the `last_mif_curves`/`last_lif_curves` accessors and per-call
  curve storage so `get_params()` only reports configuration
- add the `warn_perturbation_caused_no_change` check, document the
  "random" baseline option, drop the redundant `int` from the
  `perturb_baseline` annotation

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
For inputs normalized to zero channel mean (standard ImageNet
preprocessing), imputing zeros exactly reproduces the paper's
channel-wise data set mean imputer, whereas the previous default
`perturb_baseline="mean"` (per-sample mean over flattened features)
only approximated it. Documented the normalization assumption and the
alternatives for unnormalized inputs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Drop "random" from the documented `perturb_baseline` options: it is
  deprecated and `get_baseline_value` rejects it with a `ValueError`.
- Replace the "array of channel means" advice: with the all-indices call
  pattern of `batch_baseline_replacement_by_indices`, an `np.ndarray`
  baseline must be 0-dimensional; also clarify that "mean" is the
  per-sample mean over all features, not the paper's channel-wise mean.
- Make the `abs` guidance method-conditional in the docstring and the
  parameterisation warning: signed ranking presumes the attribution's
  sign encodes evidence for/against the class (LRP, Shapley, IG); for
  sensitivity maps whose sign is a direction in color space (raw
  gradients), `abs=True` or channel aggregation is appropriate.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The `warn_parameterisation` template hardcodes "is likely to be
sensitive to the choice of {sensitive_params}", so listing
`perturb_baseline` and `features_in_step` followed by "(SRG rankings
are designed to be robust to both)" rendered as a sentence that negated
itself. Headline `abs` as the genuinely sensitive parameter instead,
and state the robustness to occlusion-strategy choices — SRG's main
selling point — in its own sentence, qualified by the paper's finding
that absolute scores still vary across setups.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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