class_docstr: A perturbation based approach to compute attribution, which
  takes each input feature, permutes the feature values within a batch,
  and computes the difference between original and shuffled outputs for
  the given batch. This difference signifies the feature importance
  for the permuted feature.
  
  Example pseudocode for the algorithm is as follows::
  
      perm_feature_importance(batch):
          importance = dict()
          baseline_error = error_metric(model(batch), batch_labels)
          for each feature:
              permute this feature across the batch
              error = error_metric(model(permuted_batch), batch_labels)
              importance[feature] = baseline_error - error
              "un-permute" the feature across the batch
  
          return importance
  
  It should be noted that the `error_metric` must be called in the
  `forward_func`. You do not need to have an error metric, e.g. you
  could simply return the logits (the model output), but this may or may
  not provide a meaningful attribution.
  
  This method, unlike other attribution methods, requires a batch
  of examples to compute attributions and cannot be performed on a single example.
  
  By default, each scalar value within
  each input tensor is taken as a feature and shuffled independently. Passing
  a feature mask, allows grouping features to be shuffled together.
  Each input scalar in the group will be given the same attribution value
  equal to the change in target as a result of shuffling the entire feature
  group.
  
  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.
  
  More information can be found in the permutation feature
  importance algorithm description here:
  https://christophm.github.io/interpretable-ml-book/feature-importance.html
docstr: Args:
  
      forward_func (Callable): The forward function of the model or
          any modification of it.
      perm_func (Callable, optional): A function that accepts a batch of
          inputs and a feature mask, and "permutes" the feature using
          feature mask across the batch. This defaults to a function
          which applies a random permutation, this argument only needs
          to be provided if a custom permutation behavior is desired.
          Default: `_permute_feature`
code: def __init__(
      self,
      forward_func: Callable,
      perm_func: Callable = _permute_feature,
  ) -> None:
      r"""
      Args:
  
          forward_func (Callable): The forward function of the model or
              any modification of it.
          perm_func (Callable, optional): A function that accepts a batch of
              inputs and a feature mask, and "permutes" the feature using
              feature mask across the batch. This defaults to a function
              which applies a random permutation, this argument only needs
              to be provided if a custom permutation behavior is desired.
              Default: `_permute_feature`
      """
      FeatureAblation.__init__(self, forward_func=forward_func)
      self.perm_func = perm_func
  
file_path: captum/captum/attr/_core/feature_permutation.py
imports: from typing import Any, Callable, Tuple, Union
  import torch
  from captum._utils.typing import TargetType, TensorOrTupleOfTensorsGeneric
  from captum.attr._core.feature_ablation import FeatureAblation
  from captum.log import log_usage
  from torch import Tensor
label_desc: Use image node_id 1 to create a new FeaturePermutation object from inherited base classes: FeatureAblation with example: obj = FeaturePermutation(forward_func, perm_func)