class_docstr: Computes conductance with respect to particular hidden neuron. The
  returned output is in the shape of the input, showing the attribution
  / conductance of each input feature to the selected hidden layer neuron.
  The details of the approach can be found here:
  https://arxiv.org/abs/1805.12233
class_docstr_tok: ["Computes","conductance","with","respect","to","particular","hidden","neuron",".","The","returned","output","is","in","the","shape","of","the","input",",","showing","the","attribution","\/","conductance","of","each","input","feature","to","the","selected","hidden","layer","neuron",".","The","details","of","the","approach","can","be","found","here",":","https",":","\/\/arxiv.org\/abs\/1805.12233"]
code: def _attribute(
      self,
      inputs: Tuple[Tensor, ...],
      neuron_selector: Union[int, Tuple[int, ...], Callable],
      baselines: Tuple[Union[Tensor, int, float], ...],
      target: TargetType = None,
      additional_forward_args: Any = None,
      n_steps: int = 50,
      method: str = "riemann_trapezoid",
      attribute_to_neuron_input: bool = False,
      step_sizes_and_alphas: Union[
          None, Tuple[List[float], List[float]]
      ] = None,
  ) -> Tuple[Tensor, ...]:
      num_examples = inputs[0].shape[0]
      total_batch = num_examples * n_steps
  
      if step_sizes_and_alphas is None:
          # retrieve step size and scaling factor for specified approximation method
          step_sizes_func, alphas_func = approximation_parameters(
              method
          )
          step_sizes, alphas = step_sizes_func(n_steps), alphas_func(
              n_steps
          )
      else:
          step_sizes, alphas = step_sizes_and_alphas
  
      # Compute scaled inputs from baseline to final input.
      scaled_features_tpl = tuple(
          torch.cat(
              [
                  baseline + alpha * (input - baseline)
                  for alpha in alphas
              ],
              dim=0,
          ).requires_grad_()
          for input, baseline in zip(inputs, baselines)
      )
  
      additional_forward_args = _format_additional_forward_args(
          additional_forward_args
      )
      # apply number of steps to additional forward args
      # currently, number of steps is applied only to additional forward arguments
      # that are nd-tensors. It is assumed that the first dimension is
      # the number of batches.
      # dim -> (#examples * #steps x additional_forward_args[0].shape[1:], ...)
      input_additional_args = (
          _expand_additional_forward_args(
              additional_forward_args, n_steps
          )
          if additional_forward_args is not None
          else None
      )
      expanded_target = _expand_target(target, n_steps)
  
      # Conductance Gradients - Returns gradient of output with respect to
      # hidden layer and hidden layer evaluated at each input.
      (
          layer_gradients,
          layer_eval,
          input_grads,
      ) = compute_layer_gradients_and_eval(
          forward_fn=self.forward_func,
          layer=self.layer,
          inputs=scaled_features_tpl,
          target_ind=expanded_target,
          additional_forward_args=input_additional_args,
          gradient_neuron_selector=neuron_selector,
          device_ids=self.device_ids,
          attribute_to_layer_input=attribute_to_neuron_input,
      )
  
      mid_grads = _verify_select_neuron(
          layer_gradients, neuron_selector
      )
      scaled_input_gradients = tuple(
          input_grad
          * mid_grads.reshape(
              (total_batch,) + (1,) * (len(input_grad.shape) - 1)
          )
          for input_grad in input_grads
      )
  
      # Mutliplies by appropriate step size.
      scaled_grads = tuple(
          scaled_input_gradient.contiguous().view(n_steps, -1)
          * torch.tensor(step_sizes)
          .view(n_steps, 1)
          .to(scaled_input_gradient.device)
          for scaled_input_gradient in scaled_input_gradients
      )
  
      # Aggregates across all steps for each tensor in the input tuple
      total_grads = tuple(
          _reshape_and_sum(
              scaled_grad, n_steps, num_examples, input_grad.shape[1:]
          )
          for (scaled_grad, input_grad) in zip(
              scaled_grads, input_grads
          )
      )
  
      if self.multiplies_by_inputs:
          # computes attribution for each tensor in input tuple
          # attributions has the same dimensionality as inputs
          attributions = tuple(
              total_grad * (input - baseline)
              for total_grad, input, baseline in zip(
                  total_grads, inputs, baselines
              )
          )
      else:
          attributions = total_grads
  
      return attributions
  
file_path: captum/captum/attr/_core/neuron/neuron_conductance.py
imports: import warnings
  from typing import Any, Callable, List, Tuple, Union
  import torch
  from captum._utils.common import _expand_additional_forward_args, _expand_target, _format_additional_forward_args, _format_output, _is_tuple, _verify_select_neuron
  from captum._utils.gradient import compute_layer_gradients_and_eval
  from captum._utils.typing import BaselineType, TargetType, TensorOrTupleOfTensorsGeneric
  from captum.attr._utils.approximation_methods import approximation_parameters
  from captum.attr._utils.attribution import GradientAttribution, NeuronAttribution
  from captum.attr._utils.batching import _batch_attribution
  from captum.attr._utils.common import _format_input_baseline, _reshape_and_sum, _validate_input
  from captum.log import log_usage
  from torch import Tensor
  from torch.nn import Module
label_desc: Use image node_id 3 for calling the NeuronConductance obj's underlying member method code with example usage: obj._attribute(inputs, neuron_selector, baselines, target, additional_forward_args, n_steps, method, attribute_to_neuron_input, step_sizes_and_alphas) and returns: attributions