New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LRP: AlphaBeta and Zplus #42
Comments
I agree, well detected, I think there is a todo for that? The biases are part of the get_weights. Therefore the list-comprehension. Yes, this should quite easily be fixable. I will come back to this, I don't manage today to give you complete response. I follow up! |
Ok the todo is cryptic :-) Yes, this is definitely possible to implement with the gradients. So the point would be that negative inputs times negative weights should be added to the alpha component and negative inputs times positive weights to the beta component. Right? # Distinguish postive and negative inputs.
Xs_pos = kutils.apply(keras.layers.ReLU, Xs)
Xs_neg = kutils.apply(keras.layers.ReLU,
kutils.apply(times_minus_one, Xs))
# Compute positive and negative relevance.
add = keras.layers.Add()
positive_part = add(f(self._layer_wo_act_positive, Xs_pos),
f(self._layer_wo_act_negative, Xs_neg))
negative_part = add(f(self._layer_wo_act_negative, Xs_pos),
f(self._layer_wo_act_positive, Xs_neg))
What do you think about this? If you have a computationally faster implementation, that would also be great! |
looks good. I will try to add this if I find no corresponding commit from you |
There has been another bug with Xs_neg, which has been fixed. ZPlus does now inherit from AlphaBeta, sets alpha=1, beta=0 and ignores the bias. A second pair of eyes going over the code would be nice. |
fyi relevance maps as they are now: note the difference of ZPlus (which inherits from AlphaBeta) and ZPlusFast. Handling the input layer explicitly for both methods should yield the same results. |
I will look into the code and let you know! I think the easiest is if you write an issue and let me know which assertions you want to have and I will add them. |
assertions which come to mind right now, wrt ZPlus are
(2) would greatly help for debugging and optimizing code. |
Please let's discuss this best online. |
I have just updated the AlphaBeta rule class in The new implementation was intended to fix that. Could you please verify it does what it should? As a drawback, the current implementation of |
I have found a bug in the code for the AlphaBeta rules and also the Zplus rule.
The current code creates copies of the layer's weight and thesholds it at zero into positive and negative weight arrays.
However, AlphaBeta and also Zplus require forward transformations thresholded at zero, which, with the current implementation, requires layer inputs x to be greater than or equal to zero.
For a correct implementation of both rules (Zplus can inherit from AlphaBeta and realize alpha=1, beta=0), it would suffice to copy the layer's weights once, but then compute two forward passes which need to be thresholded.
Does this interfere with the computation of the backward gradient?
Also, for correctly considering the positive and negative forward contributions originating from the bias, the bias needs to be thresholded as well.
Please have a look at (this)[https://github.com/sebastian-lapuschkin/lrp_toolbox/blob/python-wip/python/modules/linear.py], lines 219+, which implements the rules using numpy.
Can this (conveniently) be fixed, without negatively interfering with the gradient computations?
The text was updated successfully, but these errors were encountered: