IG_i(x) = (x_i - baseline_i) * (1/steps) * sum_{k=1}^{steps} d(F(baseline + (k/steps)(x - baseline)))/dx_i – a Riemann-sum approximation of the straight-line path integral from baseline to input.
More...
#include <integrated_gradients.hpp>
IG_i(x) = (x_i - baseline_i) * (1/steps) * sum_{k=1}^{steps} d(F(baseline + (k/steps)(x - baseline)))/dx_i – a Riemann-sum approximation of the straight-line path integral from baseline to input.
- Note
- Reuses Saliency::explain per interpolation step (each step's gradient IS exactly a raw-gradient saliency computation at one interpolated point) rather than reimplementing the forward/backward mechanics.
-
Correctness is verified via the completeness axiom (sum(IG(x)) == F(x) - F(baseline)), not just "it runs" – see vision_integrated_gradients.md.
-
A pure graph walker built entirely against ExplainerContext/Saliency's public interfaces – no core (Tensor/ComputationGraph/Autograd/Module) changes needed.
-
Device-generic host boundary: input/baseline are read to the host once, each interpolated point is uploaded beside the input, gradients accumulate on the device, and the final (x - baseline) * avg_grad product runs on one host read of the sum.
◆ capabilities()
◆ explain()
Computes the Integrated Gradients attribution for one output index.
- Parameters
-
| ctx | Context to run each interpolation step's forward/backward pass through. |
| input | Input to explain. |
| baseline | Reference "uninformative" input. Must match input's shape. |
| target_index | Which output element to attribute (0-based, flat index). |
| steps | Number of Riemann-sum interpolation steps (50-300 typical; more steps tightens the completeness-axiom approximation error). |
| backend | Backend to allocate intermediate tensors through. |
- Returns
- An Attribution with method "integrated_gradients", values = the IG map, and metadata recording steps and target index used.
The documentation for this class was generated from the following file: