class_docstr: A SaliencyMask class that implements the integrated gradients method.
class_docstr_tok: ["A","SaliencyMask","class","that","implements","the","integrated","gradients","method","."]
docstr: Args:
      node_idx: the index of the node to calculate gradients for.
      class_of_interest: the index for the class probability that the gradients will be calculated for.
      features_baseline: For integrated gradients, X_baseline is the reference X to start with. Generally we should set
          X_baseline to a all-zero matrix with the size of the original feature matrix.
      steps (int): The number of values we need to interpolate. Generally steps = 20 should give good enough results.
  
  Returns
      (Numpy array): Integrated gradients for the node features.
docstr_tok: ["Args",":","node_idx",":","the","index","of","the","node","to","calculate","gradients","for",".","class_of_interest",":","the","index","for","the","class","probability","that","the","gradients","will","be","calculated","for",".","features_baseline",":","For","integrated","gradients",",","X_baseline","is","the","reference","X","to","start","with",".","Generally","we","should","set","X_baseline","to","a","all-zero","matrix","with","the","size","of","the","original","feature","matrix",".","steps","(","int",")",":","The","number","of","values","we","need","to","interpolate",".","Generally","steps","=","20","should","give","good","enough","results",".","Returns","(","Numpy","array",")",":","Integrated","gradients","for","the","node","features","."]
code: def get_integrated_node_masks(
      self,
      node_idx,
      class_of_interest,
      features_baseline=None,
      steps=20,
  ):
      """
      Args:
          node_idx: the index of the node to calculate gradients for.
          class_of_interest: the index for the class probability that the gradients will be calculated for.
          features_baseline: For integrated gradients, X_baseline is the reference X to start with. Generally we should set
              X_baseline to a all-zero matrix with the size of the original feature matrix.
          steps (int): The number of values we need to interpolate. Generally steps = 20 should give good enough results.
  
      Returns
          (Numpy array): Integrated gradients for the node features.
      """
      if features_baseline is None:
          features_baseline = np.zeros(self._features.shape)
  
      features_diff = self._features - features_baseline
      total_gradients = np.zeros(self._features.shape)
  
      for alpha in np.linspace(0, 1, steps):
          features_step = features_baseline + alpha * features_diff
  
          if self._is_sparse:
              model_input = [
                  features_step,
                  np.array([[node_idx]]),
                  self._adj_inds,
                  self._adj,
              ]
          else:
              model_input = [
                  features_step,
                  np.array([[node_idx]]),
                  self._adj,
              ]
  
          model_input = [tf.convert_to_tensor(x) for x in model_input]
          grads = self._compute_gradients(
              model_input, class_of_interest, wrt=model_input[0]
          )
  
          total_gradients += grads
  
      return np.squeeze(total_gradients * features_diff, 0)
  
file_path: stellargraph/stellargraph/interpretability/saliency_maps/integrated_gradients.py
imports: import numpy
  from tensorflow.keras import backend
  from scipy.sparse import csr_matrix
  import tensorflow
  from stellargraph.mapper import SparseFullBatchSequence, FullBatchSequence
label_desc: Use image node_id 2 for calling the IntegratedGradients obj's underlying member method code with example usage: obj.get_integrated_node_masks(node_idx, class_of_interest, features_baseline, steps) and returns: np