LayerwiseRelevancePropagationExplainer<T>
Models & Types · AiDotNet.Interpretability.Explainers
Layer-wise Relevance Propagation (LRP) explainer for neural networks.
Implements: ILocalExplainer<T, LRPExplanation<T>>
For Beginners
LRP explains neural network predictions by propagating “relevance” scores backward from the output to the input.
Key idea:
- Start with the prediction score as the total “relevance”
- At each layer, distribute relevance to neurons in the previous layer
- Continue until you reach the input features
- Each input feature gets a relevance score
Conservation principle:
- The total relevance is conserved at each layer
- Relevance in = Relevance out (like energy conservation)
- This means attributions sum to the prediction value
LRP rules (how to distribute relevance):
- LRP-0 (Basic): Distribute proportional to contribution
- LRP-ε (Epsilon): Adds stability with small epsilon
- LRP-γ (Gamma): Emphasizes positive contributions
- LRP-αβ: Separately handles positive and negative contributions
When to use LRP:
- You want to understand which inputs were “responsible” for the output
- You need attributions that sum exactly to the prediction
- You want a principled way to handle different layer types
Example: For image classification:
- LRP shows which pixels contributed positively or negatively
- Red = positive relevance (supported the prediction)
- Blue = negative relevance (contradicted the prediction)
Constructors
| Constructor | Summary |
|---|---|
LayerwiseRelevancePropagationExplainer(Func<Vector<T>, Vector<T>> predictFunction, Func<Vector<T>, Vector<T>[]> getLayerActivations, Func<int, Matrix<T>> getLayerWeights, int numFeatures, int[] layerSizes, string[] featureNames, LRPRule rule, double epsilon, double gamma) |
Initializes a new LRP explainer. |
Properties
| Property | Summary |
|---|---|
bool SupportsGlobalExplanations { get; } |
|
bool SupportsLocalExplanations { get; } |
|
string MethodName { get; } |
Methods
| Method | Summary |
|---|---|
LRPExplanation<T> Explain(Vector<T> instance) |
Computes LRP relevance scores for an input. |
LRPExplanation<T> Explain(Vector<T> instance, int outputIndex) |
Computes LRP relevance scores for a specific output. |
LRPExplanation<T>[] ExplainBatch(Matrix<T> instances) |