class_docstr: A perturbation based approach to compute attribution, based on the concept
  of Shapley Values from cooperative game theory. This method involves taking
  a random permutation of the input features and adding them one-by-one to the
  given baseline. The output difference after adding each feature corresponds
  to its attribution, and these difference are averaged when repeating this
  process n_samples times, each time choosing a new random permutation of
  the input features.
  
  By default, each scalar value within
  the input tensors are taken as a feature and added independently. Passing
  a feature mask, allows grouping features to be added together. This can
  be used in cases such as images, where an entire segment or region
  can be grouped together, measuring the importance of the segment
  (feature group). Each input scalar in the group will be given the same
  attribution value equal to the change in output as a result of adding back
  the entire feature group.
  
  More details regarding Shapley Value sampling can be found in these papers:
  https://www.sciencedirect.com/science/article/pii/S0305054808000804
  https://pdfs.semanticscholar.org/7715/bb1070691455d1fcfc6346ff458dbca77b2c.pdf
class_docstr_tok: ["A","perturbation","based","approach","to","compute","attribution",",","based","on","the","concept","of","Shapley","Values","from","cooperative","game","theory",".","This","method","involves","taking","a","random","permutation","of","the","input","features","and","adding","them","one-by-one","to","the","given","baseline",".","The","output","difference","after","adding","each","feature","corresponds","to","its","attribution",",","and","these","difference","are","averaged","when","repeating","this","process","n_samples","times",",","each","time","choosing","a","new","random","permutation","of","the","input","features",".","By","default",",","each","scalar","value","within","the","input","tensors","are","taken","as","a","feature","and","added","independently",".","Passing","a","feature","mask",",","allows","grouping","features","to","be","added","together",".","This","can","be","used","in","cases","such","as","images",",","where","an","entire","segment","or","region","can","be","grouped","together",",","measuring","the","importance","of","the","segment","(","feature","group",")",".","Each","input","scalar","in","the","group","will","be","given","the","same","attribution","value","equal","to","the","change","in","output","as","a","result","of","adding","back","the","entire","feature","group",".","More","details","regarding","Shapley","Value","sampling","can","be","found","in","these","papers",":","https",":","\/\/www.sciencedirect.com\/science\/article\/pii\/S0305054808000804","https",":","\/\/pdfs.semanticscholar.org\/7715\/bb1070691455d1fcfc6346ff458dbca77b2c.pdf"]
docstr: Args:
  
      forward_func (Callable): The forward function of the model or
                  any modification of it. The forward function can either
                  return a scalar per example, or a single scalar for the
                  full batch. If a single scalar is returned for the batch,
                  `perturbations_per_eval` must be 1, and the returned
                  attributions will have first dimension 1, corresponding to
                  feature importance across all examples in the batch.
docstr_tok: ["Args",":","forward_func","(","Callable",")",":","The","forward","function","of","the","model","or","any","modification","of","it",".","The","forward","function","can","either","return","a","scalar","per","example",",","or","a","single","scalar","for","the","full","batch",".","If","a","single","scalar","is","returned","for","the","batch",",","`","perturbations_per_eval","`","must","be","1",",","and","the","returned","attributions","will","have","first","dimension","1",",","corresponding","to","feature","importance","across","all","examples","in","the","batch","."]
code: def __init__(self, forward_func: Callable) -> None:
      r"""
      Args:
  
          forward_func (Callable): The forward function of the model or
                      any modification of it. The forward function can either
                      return a scalar per example, or a single scalar for the
                      full batch. If a single scalar is returned for the batch,
                      `perturbations_per_eval` must be 1, and the returned
                      attributions will have first dimension 1, corresponding to
                      feature importance across all examples in the batch.
      """
      PerturbationAttribution.__init__(self, forward_func)
      self.permutation_generator = _perm_generator
  
imports: import itertools
  import math
  import warnings
  from typing import Any, Callable, Iterable, Sequence, Tuple, Union
  import torch
  from captum._utils.common import _expand_additional_forward_args, _expand_target, _format_additional_forward_args, _format_feature_mask, _format_output, _format_tensor_into_tuples, _get_max_feature_index, _is_mask_valid, _is_tuple, _run_forward
  from captum._utils.progress import progress
  from captum._utils.typing import BaselineType, TargetType, TensorOrTupleOfTensorsGeneric
  from captum.attr._utils.attribution import PerturbationAttribution
  from captum.attr._utils.common import _find_output_mode_and_verify, _format_input_baseline, _tensorize_baseline
  from captum.log import log_usage
  from torch import Tensor
label_desc: Use image node_id 1 to create a new ShapleyValueSampling object from inherited base classes: PerturbationAttribution with example: obj = ShapleyValueSampling(forward_func)