xai4tsc.xai.wrappers

Wrapper explainers that extend a base method (e.g. SIGN).

Attributes

logger

Classes

SignExplainer

SIGN extension of a gradient-based attribution method.

Module Contents

xai4tsc.xai.wrappers.logger
class xai4tsc.xai.wrappers.SignExplainer(base: dict | str, mu: float = 0.0)

Bases: xai4tsc.xai.base.WrapperExplainer

SIGN extension of a gradient-based attribution method.

Implements the SIGN rule of Gumpfer et al. (Information Fusion 2023, doi:10.1016/j.inffus.2023.101883): replace a gradient method’s conventional “x input” weighting with the binarized sign of the input, raw_gradient * s_mu(input) where s_mu(x) = -1 if x < mu else +1.

For the gradient-attribution family this is exactly the paper’s SIGN variant. The sign step is the final operation of these methods, so applying it to the raw-gradient output is mathematically identical to an in-pass rule.

Notes

Correctness condition. The base must emit a raw gradient-space map, i.e. it must not already multiply by the input. SIGN therefore enforces multiply_by_inputs=False on the base (Integrated Gradients, DeepLIFT), overriding a user-supplied True with a warning; gradient-only methods (Guided Backpropagation, Deconvolution) already satisfy this. A non-gradient base cannot produce the SIGN variant and is flagged with a warning.

LRP-SIGN is not expressible this way — for LRP, SIGN is an input-layer relevance rule applied during the backward pass. That variant would be a separate WrapperExplainer subclass and is out of scope here.

Parameters:
  • base (dict or str) – The gradient base explainer to extend. Either a bare method name or a config dict with a "method" key plus that method’s hyperparameters (e.g. {"method": "integrated_gradients", "multiply_by_inputs": False}).

  • mu (float) – Sign threshold. Inputs < mu map to -1, the rest to +1.

mu = 0.0
explain(model: torch.nn.Module, exp: xai4tsc.xai._types.Explanation, device: str | torch.device, targets: list | None, **kwargs: object) numpy.ndarray

Run the base method, then weight it by sign(input - mu).