class_docstr: Implements gradient SHAP for a neuron in a hidden layer based on the
  implementation from SHAP's primary author. For reference, please, view:
  
  https://github.com/slundberg/shap\
  #deep-learning-example-with-gradientexplainer-tensorflowkeraspytorch-models
  
  A Unified Approach to Interpreting Model Predictions
  https://papers.nips.cc/paper\
  7062-a-unified-approach-to-interpreting-model-predictions
  
  GradientShap approximates SHAP values by computing the expectations of
  gradients by randomly sampling from the distribution of baselines/references.
  It adds white noise to each input sample `n_samples` times, selects a
  random baseline from baselines' distribution and a random point along the
  path between the baseline and the input, and computes the gradient of the
  neuron with index `neuron_selector` with respect to those selected random
  points. The final SHAP values represent the expected values of
  `gradients * (inputs - baselines)`.
  
  GradientShap makes an assumption that the input features are independent
  and that the explanation model is linear, meaning that the explanations
  are modeled through the additive composition of feature effects.
  Under those assumptions, SHAP value can be approximated as the expectation
  of gradients that are computed for randomly generated `n_samples` input
  samples after adding gaussian noise `n_samples` times to each input for
  different baselines/references.
  
  In some sense it can be viewed as an approximation of integrated gradients
  by computing the expectations of gradients for different baselines.
  
  Current implementation uses Smoothgrad from :class:`.NoiseTunnel` in order to
  randomly draw samples from the distribution of baselines, add noise to input
  samples and compute the expectation (smoothgrad).
class_docstr_tok: ["Implements","gradient","SHAP","for","a","neuron","in","a","hidden","layer","based","on","the","implementation","from","SHAP","'s","primary","author",".","For","reference",",","please",",","view",":","https",":","\/\/github.com\/slundberg\/shap\\","#","deep-learning-example-with-gradientexplainer-tensorflowkeraspytorch-models","A","Unified","Approach","to","Interpreting","Model","Predictions","https",":","\/\/papers.nips.cc\/paper\\","7062-a-unified-approach-to-interpreting-model-predictions","GradientShap","approximates","SHAP","values","by","computing","the","expectations","of","gradients","by","randomly","sampling","from","the","distribution","of","baselines\/references",".","It","adds","white","noise","to","each","input","sample","`","n_samples","`","times",",","selects","a","random","baseline","from","baselines","'","distribution","and","a","random","point","along","the","path","between","the","baseline","and","the","input",",","and","computes","the","gradient","of","the","neuron","with","index","`","neuron_selector","`","with","respect","to","those","selected","random","points",".","The","final","SHAP","values","represent","the","expected","values","of","`","gradients","*","(","inputs","-","baselines",")","`",".","GradientShap","makes","an","assumption","that","the","input","features","are","independent","and","that","the","explanation","model","is","linear",",","meaning","that","the","explanations","are","modeled","through","the","additive","composition","of","feature","effects",".","Under","those","assumptions",",","SHAP","value","can","be","approximated","as","the","expectation","of","gradients","that","are","computed","for","randomly","generated","`","n_samples","`","input","samples","after","adding","gaussian","noise","`","n_samples","`","times","to","each","input","for","different","baselines\/references",".","In","some","sense","it","can","be","viewed","as","an","approximation","of","integrated","gradients","by","computing","the","expectations","of","gradients","for","different","baselines",".","Current","implementation","uses","Smoothgrad","from",":","class",":","`",".NoiseTunnel","`","in","order","to","randomly","draw","samples","from","the","distribution","of","baselines",",","add","noise","to","input","samples","and","compute","the","expectation","(","smoothgrad",")","."]
docstr: Args:
  
      forward_func (Callable): The forward function of the model or any
                  modification of it
      layer (torch.nn.Module): Layer for which neuron attributions are computed.
                  The output size of the attribute method matches the
                  dimensions of the inputs or outputs of the neuron with
                  index `neuron_selector` in this layer, depending on whether
                  we attribute to the inputs or outputs of the neuron.
                  Currently, it is assumed that the inputs or the outputs
                  of the neurons in this layer, depending on which one is
                  used for attribution, can only be a single tensor.
      device_ids (list[int]): Device ID list, necessary only if forward_func
                  applies a DataParallel model. This allows reconstruction of
                  intermediate outputs from batched results across devices.
                  If forward_func is given as the DataParallel model itself,
                  then it is not necessary to provide this argument.
      multiply_by_inputs (bool, optional): Indicates whether to factor
                  model inputs' multiplier in the final attribution scores.
                  In the literature this is also known as local vs global
                  attribution. If inputs' multiplier isn't factored in
                  then that type of attribution method is also called local
                  attribution. If it is, then that type of attribution
                  method is called global.
                  More detailed can be found here:
                  https://arxiv.org/abs/1711.06104
  
                  In case of Neuron Gradient SHAP,
                  if `multiply_by_inputs` is set to True, the
                  sensitivity scores for scaled inputs are
                  being multiplied by (inputs - baselines).
docstr_tok: ["Args",":","forward_func","(","Callable",")",":","The","forward","function","of","the","model","or","any","modification","of","it","layer","(","torch.nn.Module",")",":","Layer","for","which","neuron","attributions","are","computed",".","The","output","size","of","the","attribute","method","matches","the","dimensions","of","the","inputs","or","outputs","of","the","neuron","with","index","`","neuron_selector","`","in","this","layer",",","depending","on","whether","we","attribute","to","the","inputs","or","outputs","of","the","neuron",".","Currently",",","it","is","assumed","that","the","inputs","or","the","outputs","of","the","neurons","in","this","layer",",","depending","on","which","one","is","used","for","attribution",",","can","only","be","a","single","tensor",".","device_ids","(","list","[","int","]",")",":","Device","ID","list",",","necessary","only","if","forward_func","applies","a","DataParallel","model",".","This","allows","reconstruction","of","intermediate","outputs","from","batched","results","across","devices",".","If","forward_func","is","given","as","the","DataParallel","model","itself",",","then","it","is","not","necessary","to","provide","this","argument",".","multiply_by_inputs","(","bool",",","optional",")",":","Indicates","whether","to","factor","model","inputs","'","multiplier","in","the","final","attribution","scores",".","In","the","literature","this","is","also","known","as","local","vs","global","attribution",".","If","inputs","'","multiplier","is","n't","factored","in","then","that","type","of","attribution","method","is","also","called","local","attribution",".","If","it","is",",","then","that","type","of","attribution","method","is","called","global",".","More","detailed","can","be","found","here",":","https",":","\/\/arxiv.org\/abs\/1711.06104","In","case","of","Neuron","Gradient","SHAP",",","if","`","multiply_by_inputs","`","is","set","to","True",",","the","sensitivity","scores","for","scaled","inputs","are","being","multiplied","by","(","inputs","-","baselines",")","."]
code: def __init__(
      self,
      forward_func: Callable,
      layer: Module,
      device_ids: Union[None, List[int]] = None,
      multiply_by_inputs: bool = True,
  ) -> None:
      r"""
      Args:
  
          forward_func (Callable): The forward function of the model or any
                      modification of it
          layer (torch.nn.Module): Layer for which neuron attributions are computed.
                      The output size of the attribute method matches the
                      dimensions of the inputs or outputs of the neuron with
                      index `neuron_selector` in this layer, depending on whether
                      we attribute to the inputs or outputs of the neuron.
                      Currently, it is assumed that the inputs or the outputs
                      of the neurons in this layer, depending on which one is
                      used for attribution, can only be a single tensor.
          device_ids (list[int]): Device ID list, necessary only if forward_func
                      applies a DataParallel model. This allows reconstruction of
                      intermediate outputs from batched results across devices.
                      If forward_func is given as the DataParallel model itself,
                      then it is not necessary to provide this argument.
          multiply_by_inputs (bool, optional): Indicates whether to factor
                      model inputs' multiplier in the final attribution scores.
                      In the literature this is also known as local vs global
                      attribution. If inputs' multiplier isn't factored in
                      then that type of attribution method is also called local
                      attribution. If it is, then that type of attribution
                      method is called global.
                      More detailed can be found here:
                      https://arxiv.org/abs/1711.06104
  
                      In case of Neuron Gradient SHAP,
                      if `multiply_by_inputs` is set to True, the
                      sensitivity scores for scaled inputs are
                      being multiplied by (inputs - baselines).
      """
      NeuronAttribution.__init__(self, forward_func, layer, device_ids)
      GradientAttribution.__init__(self, forward_func)
      self._multiply_by_inputs = multiply_by_inputs
  
file_path: captum/captum/attr/_core/neuron/neuron_gradient_shap.py
imports: from typing import Any, Callable, List, Tuple, Union
  from captum._utils.gradient import construct_neuron_grad_fn
  from captum._utils.typing import TensorOrTupleOfTensorsGeneric
  from captum.attr._core.gradient_shap import GradientShap
  from captum.attr._utils.attribution import GradientAttribution, NeuronAttribution
  from captum.log import log_usage
  from torch.nn import Module
label_desc: Use image node_id 1 to create a new NeuronGradientShap object from inherited base classes: NeuronAttribution, GradientAttribution with example: obj = NeuronGradientShap(forward_func, layer, device_ids, multiply_by_inputs)