IntegratedGradientsExplainer<T>
Models & Types · AiDotNet.Interpretability.Explainers
Integrated Gradients explainer for neural networks with gradient access.
Implements: IGPUAcceleratedExplainer<T>, IGlobalAttributionExplainer<T>, ILocalExplainer<T, IntegratedGradientsExplanation<T>>
For Beginners
Integrated Gradients is a method for explaining neural network predictions that satisfies two important mathematical properties:
- Completeness (Axiom of Completeness): The attributions sum up to the difference
between the prediction at the input and the prediction at a baseline (usually zeros).
- Sensitivity: If a feature differs between input and baseline and affects the output,
it gets a non-zero attribution.
How it works:
- Start with a “baseline” (typically all zeros or a neutral input)
- Create a path from baseline to your actual input
- Integrate the gradients along this path
- The result shows how much each feature contributed to moving from baseline to final prediction
Why use Integrated Gradients?
- Theoretically sound (satisfies axioms that other methods don’t)
- Works with any differentiable model
- Attributions have clear meaning: contribution to prediction difference from baseline
Example: For an image classifier predicting “cat”:
- Baseline: black image (all zeros)
- Input: image of a cat
- Integrated Gradients shows which pixels contributed most to the “cat” prediction
Constructors
| Constructor | Summary |
|---|---|
IntegratedGradientsExplainer(Func<Vector<T>, Vector<T>> predictFunction, Func<Vector<T>, int, Vector<T>> gradientFunction, int numFeatures, int numSteps, Vector<T> baseline, string[] featureNames) |
Initializes a new Integrated Gradients explainer. |
IntegratedGradientsExplainer(INeuralNetwork<T> neuralNetwork, int numFeatures, int numSteps, Vector<T> baseline, string[] featureNames) |
Initializes a new Integrated Gradients explainer from a neural network model. |
Properties
| Property | Summary |
|---|---|
bool IsGPUAccelerated { get; } |
|
bool SupportsGlobalExplanations { get; } |
|
bool SupportsLocalExplanations { get; } |
|
string MethodName { get; } |
Methods
| Method | Summary |
|---|---|
IntegratedGradientsExplanation<T> Explain(Vector<T> instance) |
Computes Integrated Gradients attributions for an input. |
IntegratedGradientsExplanation<T> Explain(Vector<T> instance, int outputIndex) |
Computes Integrated Gradients attributions for a specific output class. |
IntegratedGradientsExplanation<T>[] ExplainBatch(Matrix<T> instances) |
|
Vector<T> ComputeGlobalAttributions(Matrix<T> data) |
|
void SetGPUHelper(GPUExplainerHelper<T> helper) |