class_docstr: Implements ML framework independent version of Guided IG.
class_docstr_tok: ["Implements","ML","framework","independent","version","of","Guided","IG","."]
docstr: Computes and returns the Guided IG attribution.
  
  Args:
    x_value: an input (ndarray) for which the attribution should be computed.
    call_model_function: A function that interfaces with a model to return
      specific data in a dictionary when given an input and other arguments.
      Expected function signature:
      - call_model_function(x_value_batch,
                            call_model_args=None,
                            expected_keys=None):
        x_value_batch - Input for the model, given as a batch (i.e. dimension
          0 is the batch dimension, dimensions 1 through n represent a single
          input).
        call_model_args - user defined arguments. The value of this argument
          is the value of `call_model_args` argument of the nesting method.
        expected_keys - List of keys that are expected in the output. For this
          method (Guided IG), the expected keys are
          INPUT_OUTPUT_GRADIENTS - Gradients of the output being
            explained (the logit/softmax value) with respect to the input.
            Shape should be the same shape as x_value_batch.
    call_model_args: The arguments that will be passed to the call model
      function, for every call of the model.
    x_baseline: Baseline value used in integration. Defaults to 0.
    x_steps: Number of integrated steps between baseline and x.
    fraction: the fraction of features [0, 1] that should be selected and
      changed at every approximation step. E.g., value `0.25` means that 25%
      of the input features with smallest gradients are selected and changed
      at every step.
    max_dist: the relative maximum L1 distance [0, 1] that any feature can
      deviate from the straight line path. Value `0` allows no deviation and;
      therefore, corresponds to the Integrated Gradients method that is
      calculated on the straight-line path. Value `1` corresponds to the
      unbounded Guided IG method, where the path can go through any point
      within the baseline-input hyper-rectangular.
docstr_tok: ["Computes","and","returns","the","Guided","IG","attribution",".","Args",":","x_value",":","an","input","(","ndarray",")","for","which","the","attribution","should","be","computed",".","call_model_function",":","A","function","that","interfaces","with","a","model","to","return","specific","data","in","a","dictionary","when","given","an","input","and","other","arguments",".","Expected","function","signature",":","-","call_model_function","(","x_value_batch",",","call_model_args=None",",","expected_keys=None",")",":","x_value_batch","-","Input","for","the","model",",","given","as","a","batch","(","i.e",".","dimension","0","is","the","batch","dimension",",","dimensions","1","through","n","represent","a","single","input",")",".","call_model_args","-","user","defined","arguments",".","The","value","of","this","argument","is","the","value","of","`","call_model_args","`","argument","of","the","nesting","method",".","expected_keys","-","List","of","keys","that","are","expected","in","the","output",".","For","this","method","(","Guided","IG",")",",","the","expected","keys","are","INPUT_OUTPUT_GRADIENTS","-","Gradients","of","the","output","being","explained","(","the","logit\/softmax","value",")","with","respect","to","the","input",".","Shape","should","be","the","same","shape","as","x_value_batch",".","call_model_args",":","The","arguments","that","will","be","passed","to","the","call","model","function",",","for","every","call","of","the","model",".","x_baseline",":","Baseline","value","used","in","integration",".","Defaults","to","0.","x_steps",":","Number","of","integrated","steps","between","baseline","and","x.","fraction",":","the","fraction","of","features","[","0",",","1","]","that","should","be","selected","and","changed","at","every","approximation","step",".","E.g.",",","value","`","0.25","`","means","that","25","%","of","the","input","features","with","smallest","gradients","are","selected","and","changed","at","every","step",".","max_dist",":","the","relative","maximum","L1","distance","[","0",",","1","]","that","any","feature","can","deviate","from","the","straight","line","path",".","Value","`","0","`","allows","no","deviation","and",";","therefore",",","corresponds","to","the","Integrated","Gradients","method","that","is","calculated","on","the","straight-line","path",".","Value","`","1","`","corresponds","to","the","unbounded","Guided","IG","method",",","where","the","path","can","go","through","any","point","within","the","baseline-input","hyper-rectangular","."]
code: def GetMask(
      self,
      x_value,
      call_model_function,
      call_model_args=None,
      x_baseline=None,
      x_steps=200,
      fraction=0.25,
      max_dist=0.02,
  ):
      """Computes and returns the Guided IG attribution.
  
      Args:
        x_value: an input (ndarray) for which the attribution should be computed.
        call_model_function: A function that interfaces with a model to return
          specific data in a dictionary when given an input and other arguments.
          Expected function signature:
          - call_model_function(x_value_batch,
                                call_model_args=None,
                                expected_keys=None):
            x_value_batch - Input for the model, given as a batch (i.e. dimension
              0 is the batch dimension, dimensions 1 through n represent a single
              input).
            call_model_args - user defined arguments. The value of this argument
              is the value of `call_model_args` argument of the nesting method.
            expected_keys - List of keys that are expected in the output. For this
              method (Guided IG), the expected keys are
              INPUT_OUTPUT_GRADIENTS - Gradients of the output being
                explained (the logit/softmax value) with respect to the input.
                Shape should be the same shape as x_value_batch.
        call_model_args: The arguments that will be passed to the call model
          function, for every call of the model.
        x_baseline: Baseline value used in integration. Defaults to 0.
        x_steps: Number of integrated steps between baseline and x.
        fraction: the fraction of features [0, 1] that should be selected and
          changed at every approximation step. E.g., value `0.25` means that 25%
          of the input features with smallest gradients are selected and changed
          at every step.
        max_dist: the relative maximum L1 distance [0, 1] that any feature can
          deviate from the straight line path. Value `0` allows no deviation and;
          therefore, corresponds to the Integrated Gradients method that is
          calculated on the straight-line path. Value `1` corresponds to the
          unbounded Guided IG method, where the path can go through any point
          within the baseline-input hyper-rectangular.
      """
  
      x_value = np.asarray(x_value)
      if x_baseline is None:
          x_baseline = np.zeros_like(x_value)
      else:
          x_baseline = np.asarray(x_baseline)
  
      assert x_baseline.shape == x_value.shape
  
      return guided_ig_impl(
          x_input=x_value,
          x_baseline=x_baseline,
          grad_func=self._get_grad_func(
              call_model_function, call_model_args
          ),
          steps=x_steps,
          fraction=fraction,
          max_dist=max_dist,
      )
  
file_path: saliency/saliency/core/guided_ig.py
imports: from .base import CoreSaliency
  from .base import INPUT_OUTPUT_GRADIENTS
  import math
  import numpy
label_desc: Use image node_id 1 for calling the GuidedIG obj's underlying member method code with example usage: obj.GetMask(x_value, call_model_function, call_model_args, x_baseline, x_steps, fraction, max_dist) and returns: guided_ig_impl