InfluenceFunctionExplainer<T>
Models & Types · AiDotNet.Interpretability.Explainers
Influence Function explainer for training data attribution.
Implements: IGPUAcceleratedExplainer<T>
For Beginners
Influence Functions answer the question: “Which training examples were most responsible for this prediction?”
This is different from feature attribution (which features matter) - instead it tells you which TRAINING DATA points matter. This is incredibly useful for:
Use Cases:
- Debugging: Finding mislabeled training data
- Data cleaning: Identifying harmful training examples
- Understanding: Seeing which examples the model learned from
- Fairness: Finding training data that causes biased predictions
How it works: Influence Functions use calculus to efficiently approximate: “What would happen to this test prediction if we removed a specific training example and retrained?”
Instead of actually retraining (which is expensive), we use the Hessian (second derivatives of the loss) to estimate the effect mathematically.
The math (simplified): influence(training_point) = (gradient_test) * (inverse_Hessian) * (gradient_train)
- gradient_test: How the test loss changes with parameters
- inverse_Hessian: How parameter changes propagate through the model
- gradient_train: How this training point affected the parameters
Interpretation:
- Positive influence: Removing this training point would HURT test performance
- Negative influence: Removing this training point would HELP test performance
- Large magnitude: This training point had a big effect
Constructors
| Constructor | Summary |
|---|---|
InfluenceFunctionExplainer(Func<Vector<T>, Vector<T>> predictFunction, Func<Vector<T>, Vector<T>, T> lossFunction, Func<Vector<T>, Vector<T>, Vector<T>> gradientFunction, Matrix<T> trainingData, Vector<T> trainingLabels, InverseHessianMethod method, double damping, int maxIterations, int recursionDepth, double scale, int? randomState, Func<Vector<T>, Vector<T>, Vector<T>, Vector<T>> hvpFunction) |
Initializes a new Influence Function explainer with custom gradient function. |
InfluenceFunctionExplainer(INeuralNetwork<T> network, Func<Vector<T>, Vector<T>, T> lossFunction, Matrix<T> trainingData, Vector<T> trainingLabels, InverseHessianMethod method, double damping, int maxIterations, int recursionDepth, double scale, int? randomState, Func<Vector<T>, Vector<T>, Vector<T>, Vector<T>> hvpFunction) |
Initializes a new Influence Function explainer. |
Properties
| Property | Summary |
|---|---|
bool IsGPUAccelerated { get; } |
|
bool SupportsGlobalExplanations { get; } |
Gets whether this explainer supports global explanations. |
bool SupportsLocalExplanations { get; } |
Gets whether this explainer supports local explanations. |
string MethodName { get; } |
Gets the method name. |
Methods
| Method | Summary |
|---|---|
InfluenceFunctionResult<T> ComputeInfluence(Vector<T> testInput, T testLabel) |
Computes the influence of all training samples on a test sample. |
SelfInfluenceResult<T> ComputeSelfInfluence() |
Computes the self-influence of each training sample. |
TracInResult<T> ComputeTracIn(Vector<T> testInput, T testLabel, List<Matrix<T>> checkpointGradients) |
Computes TracIn-style influence using gradient checkpoints. |
void SetGPUHelper(GPUExplainerHelper<T> helper) |