import tensorflow as tf

class Saliency(GradientBasedMethod):
    def get_symbolic_attribution(self):
        return [tf.abs(g) for g in tf.gradients(ys=self.T, xs=self.X)]


"""
Gradient * Input
https://arxiv.org/pdf/1704.02685.pdf - https://arxiv.org/abs/1611.07270
"""


class GradientXInput(GradientBasedMethod):
    def get_symbolic_attribution(self):
        return [g * x for g, x in zip(
            tf.gradients(ys=self.T, xs=self.X),
            self.X if self.has_multiple_inputs else [self.X])]

"""
Layer-wise Relevance Propagation with epsilon rule
http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0130140
"""


class EpsilonLRP(GradientBasedMethod):
    eps = None

    def __init__(self, T, X, session, keras_learning_phase, epsilon=1e-4, Y_shape=None):
        assert epsilon > 0.0, 'LRP epsilon must be greater than zero'
