Skip to content

Commit a37010b

Browse files
committed
Add equations to LRP-rule docstrings
1 parent 8f428c8 commit a37010b

File tree

2 files changed

+79
-18
lines changed

2 files changed

+79
-18
lines changed

docs/src/api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ NoiseAugmentation
2121
InterpolationAugmentation
2222
```
2323

24-
# LRP
25-
## Rules
24+
# Layer-wise Relevance Propagation
25+
## LRP rules
2626
```@docs
2727
ZeroRule
2828
EpsilonRule
2929
GammaRule
3030
WSquareRule
31-
AlphaBetaRule
3231
FlatRule
32+
AlphaBetaRule
33+
ZPlusRule
3334
ZBoxRule
3435
PassRule
3536
```

src/lrp/rules.jl

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ end
115115
116116
LRP-``0`` rule. Commonly used on upper layers.
117117
118+
# Definition
119+
Propagates relevance ``R^{k+1}`` at layer output to ``R^k`` at layer input according to
120+
```math
121+
R_j^k = \\sum_i \\frac{w_{ij}a_j^k}{\\sum_l w_{il}a_l^k+b_i} R_i^{k+1}
122+
```
123+
118124
# References
119125
- $REF_BACH_LRP
120126
"""
@@ -129,7 +135,13 @@ get_layer_resetter(::ZeroRule, layer) = Returns(nothing)
129135
130136
LRP-``ϵ`` rule. Commonly used on middle layers.
131137
132-
# Arguments:
138+
# Definition
139+
Propagates relevance ``R^{k+1}`` at layer output to ``R^k`` at layer input according to
140+
```math
141+
R_j^k = \\sum_i\\frac{w_{ij}a_j^k}{\\epsilon +\\sum_{l}w_{il}a_l^k+b_i} R_i^{k+1}
142+
```
143+
144+
# Optional arguments
133145
- `ϵ`: Optional stabilization parameter, defaults to `1f-6`.
134146
135147
# References
@@ -150,7 +162,14 @@ get_layer_resetter(::EpsilonRule, layer) = Returns(nothing)
150162
151163
LRP-``γ`` rule. Commonly used on lower layers.
152164
153-
# Arguments:
165+
# Definition
166+
Propagates relevance ``R^{k+1}`` at layer output to ``R^k`` at layer input according to
167+
```math
168+
R_j^k = \\sum_i\\frac{(w_{ij}+\\gamma w_{ij}^+)a_j^k}
169+
{\\sum_l(w_{il}+\\gamma w_{il}^+)a_l^k+b_i} R_i^{k+1}
170+
```
171+
172+
# Optional arguments
154173
- `γ`: Optional multiplier for added positive weights, defaults to `0.25`.
155174
156175
# References
@@ -169,7 +188,13 @@ end
169188
"""
170189
WSquareRule()
171190
172-
LRP-``W^2`` rule. Commonly used on the first layer when values are unbounded.
191+
LRP-``w²`` rule. Commonly used on the first layer when values are unbounded.
192+
193+
# Definition
194+
Propagates relevance ``R^{k+1}`` at layer output to ``R^k`` at layer input according to
195+
```math
196+
R_j^k = \\sum_i\\frac{w_{ij}^2}{\\sum_l w_{il}^2+b_i^2} R_i^{k+1}
197+
```
173198
174199
# References
175200
- $REF_MONTAVON_DTD
@@ -184,6 +209,13 @@ modify_input(::WSquareRule, input) = ones_like(input)
184209
LRP-Flat rule. Similar to the [`WSquareRule`](@ref), but with all weights set to one
185210
and all bias terms set to zero.
186211
212+
# Definition
213+
Propagates relevance ``R^{k+1}`` at layer output to ``R^k`` at layer input according to
214+
```math
215+
R_j^k = \\sum_i\\frac{1}{\\sum_l 1} R_i^{k+1} = \\frac{1}{n}\\sum_i R_i^{k+1}
216+
```
217+
where ``n`` is the number of input neurons connected to the output neuron at index ``i``.
218+
187219
# References
188220
- $REF_LAPUSCHKIN_CLEVER_HANS
189221
"""
@@ -196,7 +228,14 @@ modify_input(::FlatRule, input) = ones_like(input)
196228
PassRule()
197229
198230
Pass-through rule. Passes relevance through to the lower layer.
199-
Supports reshaping layers.
231+
232+
Supports layers with constant input and output shapes, e.g. reshaping layers.
233+
234+
# Definition
235+
Propagates relevance ``R^{k+1}`` at layer output to ``R^k`` at layer input according to
236+
```math
237+
R_j^k = R_j^{k+1}
238+
```
200239
"""
201240
struct PassRule <: AbstractLRPRule end
202241
function lrp!(Rₖ, ::PassRule, layer, aₖ, Rₖ₊₁)
@@ -212,12 +251,19 @@ check_compat(::PassRule, layer) = nothing
212251
"""
213252
ZBoxRule(low, high)
214253
215-
LRP-``z^{\\mathcal{B}}``-rule. Commonly used on the first layer for pixel input.
254+
LRP-``zᴮ``-rule. Commonly used on the first layer for pixel input.
216255
217256
The parameters `low` and `high` should be set to the lower and upper bounds
218257
of the input features, e.g. `0.0` and `1.0` for raw image data.
219258
It is also possible to provide two arrays of that match the input size.
220259
260+
# Definition
261+
Propagates relevance ``R^{k+1}`` at layer output to ``R^k`` at layer input according to
262+
```math
263+
R_j^k=\\sum_i \\frac{w_{ij}a_j^k - w_{ij}^{+}l_j - w_{ij}^{-}h_j}
264+
{\\sum_l w_{il}a_l^k+b_i - \\left(w_{il}^{+}l_l+b_i^{+}\\right) - \\left(w_{il}^{-}h_l+b_i^{-}\\right)} R_i^{k+1}
265+
```
266+
221267
# References
222268
- $REF_MONTAVON_OVERVIEW
223269
"""
@@ -264,16 +310,24 @@ function zbox_input(in::AbstractArray{T}, A::AbstractArray) where {T}
264310
end
265311

266312
"""
267-
AlphaBetaRule(alpha, beta)
268-
AlphaBetaRule([alpha=2.0], [beta=1.0])
313+
AlphaBetaRule([α=2.0], [β=1.0])
269314
270-
LRP-``\\alpha\\beta`` rule. Weights positive and negative contributions according to the
271-
parameters `alpha` and `beta` respectively. The difference `alpha - beta` must be equal one.
315+
LRP-``αβ`` rule. Weights positive and negative contributions according to the
316+
parameters `α` and `β` respectively. The difference `α-β` must be equal to one.
272317
Commonly used on lower layers.
273318
274-
# Arguments:
275-
- `alpha`: Multiplier for the positive output term, defaults to `2.0`.
276-
- `beta`: Multiplier for the negative output term, defaults to `1.0`.
319+
# Definition
320+
Propagates relevance ``R^{k+1}`` at layer output to ``R^k`` at layer input according to
321+
```math
322+
R_j^k = \\sum_i\\left(
323+
\\alpha\\frac{\\left(w_{ij}a_j^k\\right)^+}{\\sum_l\\left(w_{il}a_l^k+b_i\\right)^+}
324+
-\\beta\\frac{\\left(w_{ij}a_j^k\\right)^-}{\\sum_l\\left(w_{il}a_l^k+b_i\\right)^-}
325+
\\right) R_i^{k+1}
326+
```
327+
328+
# Optional arguments
329+
- `α`: Multiplier for the positive output term, defaults to `2.0`.
330+
- `β`: Multiplier for the negative output term, defaults to `1.0`.
277331
278332
# References
279333
- $REF_BACH_LRP
@@ -331,14 +385,20 @@ end
331385
"""
332386
ZPlusRule()
333387
334-
LRP-``z^{+}`` rule. Commonly used on lower layers.
388+
LRP-``z`` rule. Commonly used on lower layers.
335389
336390
Equivalent to `AlphaBetaRule(1.0f0, 0.0f0)`, but slightly faster.
337391
See also [`AlphaBetaRule`](@ref).
338392
393+
# Definition
394+
Propagates relevance ``R^{k+1}`` at layer output to ``R^k`` at layer input according to
395+
```math
396+
R_j^k = \\sum_i\\frac{\\left(w_{ij}a_j^k\\right)^+}{\\sum_l\\left(w_{il}a_l^k+b_i\\right)^+} R_i^{k+1}
397+
```
398+
339399
# References
340-
- [1] $REF_BACH_LRP
341-
- [2] $REF_MONTAVON_DTD
400+
- $REF_BACH_LRP
401+
- $REF_MONTAVON_DTD
342402
"""
343403
struct ZPlusRule <: AbstractLRPRule end
344404
function lrp!(Rₖ, rule::ZPlusRule, layer::L, aₖ, Rₖ₊₁) where {L}

0 commit comments

Comments
 (0)