pulsatrix
Loading...
Searching...
No Matches
pulsatrix::IntegratedGradients Class Reference

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>

Public Member Functions

Attribution explain (ExplainerContext &ctx, const Tensor &input, const Tensor &baseline, int64_t target_index, int64_t steps, DeviceBackend *backend) const
 Computes the Integrated Gradients attribution for one output index.
 

Detailed Description

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.

Member Function Documentation

◆ explain()

Attribution pulsatrix::IntegratedGradients::explain ( ExplainerContext &  ctx,
const Tensor &  input,
const Tensor &  baseline,
int64_t  target_index,
int64_t  steps,
DeviceBackend *  backend 
) const
inline

Computes the Integrated Gradients attribution for one output index.

Parameters
ctxContext to run each interpolation step's forward/backward pass through.
inputInput to explain.
baselineReference "uninformative" input. Must match input's shape.
target_indexWhich output element to attribute (0-based, flat index).
stepsNumber of Riemann-sum interpolation steps (50-300 typical; more steps tightens the completeness-axiom approximation error).
backendBackend 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: