class_docstr: The PGMExplainer model from the `"PGMExplainer: Probabilistic
  Graphical Model Explanations  for Graph Neural Networks"
  <https://arxiv.org/abs/1903.03894>`_ paper.
  
  The generated :class:`~torch_geometric.explain.Explanation` provides a
  :obj:`node_mask` and a :obj:`pgm_stats` tensor, which stores the
  :math:`p`-values of each node as calculated by the Chi-squared test.
  
  Args:
      feature_index (List): The indices of the perturbed features. If set
          to :obj:`None`, all features are perturbed. (default: :obj:`None`)
      perturb_mode (str, optional): The method to generate the variations in
          features. One of :obj:`"randint"`, :obj:`"mean"`, :obj:`"zero"`,
          :obj:`"max"` or :obj:`"uniform"`. (default: :obj:`"randint"`)
      perturbations_is_positive_only (bool, optional): If set to :obj:`True`,
          restrict perturbed values to be positive. (default: :obj:`False`)
      is_perturbation_scaled (bool, optional): If set to :obj:`True`, will
          normalize the range of the perturbed features.
          (default: :obj:`False`)
      num_samples (int, optional): The number of samples of perturbations
          used to test the significance of nodes to the prediction.
          (default: :obj:`100`)
      max_subgraph_size (int, optional): The maximum number of neighbors to
          consider for the explanation. (default: :obj:`None`)
      significance_threshold (float, optional): The statistical threshold
          (:math:`p`-value) for which a node is considered to have an effect
          on the prediction. (default: :obj:`0.05`)
      pred_threshold (float, optional): The buffer value (in range
          :obj:`[0, 1]`) to consider the output from a perturbed data to be
          different from the original. (default: :obj:`0.1`)
class_docstr_tok: ["The","PGMExplainer","model","from","the","`","``","PGMExplainer",":","Probabilistic","Graphical","Model","Explanations","for","Graph","Neural","Networks","''","<","https",":","\/\/arxiv.org\/abs\/1903.03894",">","`","_","paper",".","The","generated",":","class",":","`","~torch_geometric.explain.Explanation","`","provides","a",":","obj",":","`","node_mask","`","and","a",":","obj",":","`","pgm_stats","`","tensor",",","which","stores","the",":","math",":","`","p","`","-values","of","each","node","as","calculated","by","the","Chi-squared","test",".","Args",":","feature_index","(","List",")",":","The","indices","of","the","perturbed","features",".","If","set","to",":","obj",":","`","None","`",",","all","features","are","perturbed",".","(","default",":",":","obj",":","`","None","`",")","perturb_mode","(","str",",","optional",")",":","The","method","to","generate","the","variations","in","features",".","One","of",":","obj",":","`","``","randint","''","`",",",":","obj",":","`","``","mean","''","`",",",":","obj",":","`","``","zero","''","`",",",":","obj",":","`","``","max","''","`","or",":","obj",":","`","``","uniform","''","`",".","(","default",":",":","obj",":","`","``","randint","''","`",")","perturbations_is_positive_only","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","True","`",",","restrict","perturbed","values","to","be","positive",".","(","default",":",":","obj",":","`","False","`",")","is_perturbation_scaled","(","bool",",","optional",")",":","If","set","to",":","obj",":","`","True","`",",","will","normalize","the","range","of","the","perturbed","features",".","(","default",":",":","obj",":","`","False","`",")","num_samples","(","int",",","optional",")",":","The","number","of","samples","of","perturbations","used","to","test","the","significance","of","nodes","to","the","prediction",".","(","default",":",":","obj",":","`","100","`",")","max_subgraph_size","(","int",",","optional",")",":","The","maximum","number","of","neighbors","to","consider","for","the","explanation",".","(","default",":",":","obj",":","`","None","`",")","significance_threshold","(","float",",","optional",")",":","The","statistical","threshold","(",":","math",":","`","p","`","-value",")","for","which","a","node","is","considered","to","have","an","effect","on","the","prediction",".","(","default",":",":","obj",":","`","0.05","`",")","pred_threshold","(","float",",","optional",")",":","The","buffer","value","(","in","range",":","obj",":","`","[","0",",","1","]","`",")","to","consider","the","output","from","a","perturbed","data","to","be","different","from","the","original",".","(","default",":",":","obj",":","`","0.1","`",")"]
docstr: Perturbs feature matrix :obj:`x`.
  
  Args:
      x (torch.Tensor): The feature matrix.
      index (torch.Tensor): The indices of nodes to perturb.
docstr_tok: ["Perturbs","feature","matrix",":","obj",":","`","x","`",".","Args",":","x","(","torch.Tensor",")",":","The","feature","matrix",".","index","(","torch.Tensor",")",":","The","indices","of","nodes","to","perturb","."]
code: def _perturb_features_on_nodes(
      self,
      x: Tensor,
      index: Tensor,
  ) -> Tensor:
      r"""Perturbs feature matrix :obj:`x`.
  
      Args:
          x (torch.Tensor): The feature matrix.
          index (torch.Tensor): The indices of nodes to perturb.
      """
      x_perturb = x.detach().clone()
      perturb_array = x_perturb[index]
      epsilon = 0.05 * torch.max(x, dim=0).values
  
      if self.perturbation_mode == "randint":
          perturb_array = torch.randint(
              high=2, size=perturb_array.size(), device=x.device
          )
      elif self.perturbation_mode == "mean":
          perturb_array[:, self.feature_index] = torch.mean(
              x[:, self.feature_index]
          )
      elif self.perturbation_mode == "zero":
          perturb_array[:, self.feature_index] = 0
      elif self.perturbation_mode == "max":
          perturb_array[:, self.feature_index] = torch.max(
              x[:, self.feature_index]
          )
      elif self.perturbation_mode == "uniform":
          random_perturbations = (
              torch.rand(perturb_array.shape) * 2 * epsilon - epsilon
          )
          perturb_array[:, self.feature_index] = (
              perturb_array[self.feature_index] + random_perturbations
          )
          perturb_array.clamp(min=0, max=torch.max(x, dim=0))
  
      if self.is_perturbation_scaled:
          perturb_array = (
              torch.multiply(
                  perturb_array, torch.rand(size=perturb_array.size())
              )
              * 2
          )
  
      x_perturb[index] = perturb_array.type(x_perturb.dtype)
      return x_perturb
  
file_path: pytorch_geometric/torch_geometric/contrib/explain/pgm_explainer.py
imports: import logging
  from typing import List, Optional, Tuple, Union
  import numpy
  import torch
  from torch import Tensor
  from torch_geometric.explain import ExplainerAlgorithm
  from torch_geometric.explain.config import ModelMode, ModelTaskLevel
  from torch_geometric.explain.explanation import Explanation
  from torch_geometric.utils import k_hop_subgraph
  from torch_geometric.utils._subgraph import get_num_hops
label_desc: Use image node_id 2 for calling the PGMExplainer obj's underlying member method code with example usage: obj._perturb_features_on_nodes(x, index) and returns: x_perturb