class_docstr: A perturbation based approach to compute attribution, involving
  replacing each contiguous rectangular region with a given baseline /
  reference, and computing the difference in output. For features located
  in multiple regions (hyperrectangles), the corresponding output differences
  are averaged to compute the attribution for that feature.
  
  The first patch is applied with the corner aligned with all indices 0,
  and strides are applied until the entire dimension range is covered. Note
  that this may cause the final patch applied in a direction to be cut-off
  and thus smaller than the target occlusion shape.
  
  More details regarding the occlusion (or grey-box / sliding window)
  method can be found in the original paper and in the DeepExplain
  implementation.
  https://arxiv.org/abs/1311.2901
  https://github.com/marcoancona/DeepExplain/blob/master/deepexplain\
  /tensorflow/methods.py#L401
class_docstr_tok: ["A","perturbation","based","approach","to","compute","attribution",",","involving","replacing","each","contiguous","rectangular","region","with","a","given","baseline","\/","reference",",","and","computing","the","difference","in","output",".","For","features","located","in","multiple","regions","(","hyperrectangles",")",",","the","corresponding","output","differences","are","averaged","to","compute","the","attribution","for","that","feature",".","The","first","patch","is","applied","with","the","corner","aligned","with","all","indices","0",",","and","strides","are","applied","until","the","entire","dimension","range","is","covered",".","Note","that","this","may","cause","the","final","patch","applied","in","a","direction","to","be","cut-off","and","thus","smaller","than","the","target","occlusion","shape",".","More","details","regarding","the","occlusion","(","or","grey-box","\/","sliding","window",")","method","can","be","found","in","the","original","paper","and","in","the","DeepExplain","implementation",".","https",":","\/\/arxiv.org\/abs\/1311.2901","https",":","\/\/github.com\/marcoancona\/DeepExplain\/blob\/master\/deepexplain\\","\/tensorflow\/methods.py","#","L401"]
docstr: This constructs the current occlusion mask, which is the appropriate
  shift of the sliding window tensor based on the ablated feature number.
  The feature number ranges between 0 and the product of the shift counts
  (# of times the sliding window should be shifted in each dimension).
  
  First, the ablated feature number is converted to the number of steps in
  each dimension from the origin, based on shift counts. This procedure
  is similar to a base conversion, with the position values equal to shift
  counts. The feature number is first taken modulo shift_counts[0] to
  get the number of shifts in the first dimension (each shift
  by shift_count[0]), and then divided by shift_count[0].
  The procedure is then continued for each element of shift_count. This
  computes the total shift in each direction for the sliding window.
  
  We then need to compute the padding required after the window in each
  dimension, which is equal to the total input dimension minus the sliding
  window dimension minus the (left) shift amount. We construct the
  array pad_values which contains the left and right pad values for each
  dimension, in reverse order of dimensions, starting from the last one.
  
  Once these padding values are computed, we pad the sliding window tensor
  of 1s with 0s appropriately, which is the corresponding mask,
  and the result will match the input shape.
docstr_tok: ["This","constructs","the","current","occlusion","mask",",","which","is","the","appropriate","shift","of","the","sliding","window","tensor","based","on","the","ablated","feature","number",".","The","feature","number","ranges","between","0","and","the","product","of","the","shift","counts","(","#","of","times","the","sliding","window","should","be","shifted","in","each","dimension",")",".","First",",","the","ablated","feature","number","is","converted","to","the","number","of","steps","in","each","dimension","from","the","origin",",","based","on","shift","counts",".","This","procedure","is","similar","to","a","base","conversion",",","with","the","position","values","equal","to","shift","counts",".","The","feature","number","is","first","taken","modulo","shift_counts","[","0","]","to","get","the","number","of","shifts","in","the","first","dimension","(","each","shift","by","shift_count","[","0","]",")",",","and","then","divided","by","shift_count","[","0","]",".","The","procedure","is","then","continued","for","each","element","of","shift_count",".","This","computes","the","total","shift","in","each","direction","for","the","sliding","window",".","We","then","need","to","compute","the","padding","required","after","the","window","in","each","dimension",",","which","is","equal","to","the","total","input","dimension","minus","the","sliding","window","dimension","minus","the","(","left",")","shift","amount",".","We","construct","the","array","pad_values","which","contains","the","left","and","right","pad","values","for","each","dimension",",","in","reverse","order","of","dimensions",",","starting","from","the","last","one",".","Once","these","padding","values","are","computed",",","we","pad","the","sliding","window","tensor","of","1s","with","0s","appropriately",",","which","is","the","corresponding","mask",",","and","the","result","will","match","the","input","shape","."]
code: def _occlusion_mask(
      self,
      expanded_input: Tensor,
      ablated_feature_num: int,
      sliding_window_tsr: Tensor,
      strides: Union[int, Tuple[int, ...]],
      shift_counts: Tuple[int, ...],
  ) -> Tensor:
      """
      This constructs the current occlusion mask, which is the appropriate
      shift of the sliding window tensor based on the ablated feature number.
      The feature number ranges between 0 and the product of the shift counts
      (# of times the sliding window should be shifted in each dimension).
  
      First, the ablated feature number is converted to the number of steps in
      each dimension from the origin, based on shift counts. This procedure
      is similar to a base conversion, with the position values equal to shift
      counts. The feature number is first taken modulo shift_counts[0] to
      get the number of shifts in the first dimension (each shift
      by shift_count[0]), and then divided by shift_count[0].
      The procedure is then continued for each element of shift_count. This
      computes the total shift in each direction for the sliding window.
  
      We then need to compute the padding required after the window in each
      dimension, which is equal to the total input dimension minus the sliding
      window dimension minus the (left) shift amount. We construct the
      array pad_values which contains the left and right pad values for each
      dimension, in reverse order of dimensions, starting from the last one.
  
      Once these padding values are computed, we pad the sliding window tensor
      of 1s with 0s appropriately, which is the corresponding mask,
      and the result will match the input shape.
      """
      remaining_total = ablated_feature_num
      current_index = []
      for i, shift_count in enumerate(shift_counts):
          stride = strides[i] if isinstance(strides, tuple) else strides
          current_index.append((remaining_total % shift_count) * stride)
          remaining_total = remaining_total // shift_count
  
      remaining_padding = np.subtract(
          expanded_input.shape[2:],
          np.add(current_index, sliding_window_tsr.shape),
      )
      pad_values = [
          val
          for pair in zip(remaining_padding, current_index)
          for val in pair
      ]
      pad_values.reverse()
      padded_tensor = torch.nn.functional.pad(
          sliding_window_tsr, tuple(pad_values)  # type: ignore
      )
      return padded_tensor.reshape((1,) + padded_tensor.shape)
  
file_path: captum/captum/attr/_core/occlusion.py
imports: from typing import Any, Callable, Tuple, Union
  import numpy
  import torch
  from captum._utils.common import _format_tensor_into_tuples
  from captum._utils.typing import BaselineType, TargetType, TensorOrTupleOfTensorsGeneric
  from captum.attr._core.feature_ablation import FeatureAblation
  from captum.attr._utils.common import _format_and_verify_sliding_window_shapes, _format_and_verify_strides
  from captum.log import log_usage
  from torch import Tensor
label_desc: Use image node_id 4 for calling the Occlusion obj's underlying member method code with example usage: obj._occlusion_mask(expanded_input, ablated_feature_num, sliding_window_tsr, strides, shift_counts) and returns: padded_tensor