class_docstr: Runs GenAttack https://arxiv.org/abs/1805.11090
  
  Disclaimers: Note that GenAttack assumes the model outputs
  normalized probabilities.  Moreover, computations are broadcasted,
  so it is advisable to use smaller batch sizes when nb_samples is
  large.
  
  Hyperparams: alpha (mutation range), rho (mutation probability),
  and tau (temperature) all control exploration.
  
  Alpha and rho are adapted using GenAttackScheduler.
  
  :param predict: forward pass function.
  :param eps: maximum distortion.
  :param order: the order of maximum distortion (inf or 2)
  :param loss_fn: loss function (default None, GenAttack uses its own loss)
  :param nb_samples: population size (default 100)
  :param nb_iter: number of iterations (default 40)
  :param tau: sampling temperature (default 0.1)
  :param alpha_init: initial mutation range (default 0.4)
  :param rho_init: initial probability for mutation (default 0.5)
  :param decay: decay param for scheduler (default 0.9)
  :param clip_min: mininum value per input dimension (default 0.)
  :param clip_max: mininum value per input dimension (default 1.)
  :param targeted: if the attack is targeted (default False)
docstr: Given examples (x, y), returns their adversarial counterparts with
  an attack length of eps.
  
  :param x: input tensor.
  :param y: label tensor.
            - if None and self.targeted=False, compute y as predicted
              labels.
            - if self.targeted=True, then y must be the targeted labels.
  :return: tensor containing perturbed inputs.
docstr_tok: ["Given","examples","(","x",",","y",")",",","returns","their","adversarial","counterparts","with","an","attack","length","of","eps",".",":","param","x",":","input","tensor",".",":","param","y",":","label","tensor",".","-","if","None","and","self.targeted=False",",","compute","y","as","predicted","labels",".","-","if","self.targeted=True",",","then","y","must","be","the","targeted","labels",".",":","return",":","tensor","containing","perturbed","inputs","."]
code: def perturb(  # type: ignore
      self, x: torch.FloatTensor, y: Optional[torch.Tensor] = None
  ) -> torch.FloatTensor:
      """
      Given examples (x, y), returns their adversarial counterparts with
      an attack length of eps.
  
      :param x: input tensor.
      :param y: label tensor.
                - if None and self.targeted=False, compute y as predicted
                  labels.
                - if self.targeted=True, then y must be the targeted labels.
      :return: tensor containing perturbed inputs.
      """
      x, y = self._verify_and_process_inputs(x, y)
      shape, flat_x = _flatten(x)
      data_shape = tuple(shape[1:])
  
      # [B]
      eps = _check_param(self.eps, x.new_full((x.shape[0],), 1), "eps")
      # [B, F]
      clip_min = _check_param(self.clip_min, flat_x, "clip_min")
      clip_max = _check_param(self.clip_max, flat_x, "clip_max")
  
      def f(x):
          new_shape = (x.shape[0],) + data_shape
          input = x.reshape(new_shape)
          return self.predict(input)
  
      projector = _make_projector(
          eps, self.order, flat_x, clip_min, clip_max
      )
  
      elite_adv, _, _ = gen_attack(
          predict_fn=f,
          loss_fn=self.loss_fn,
          x=flat_x,
          y=y,
          eps=eps,
          projector=projector,
          nb_samples=self.nb_samples,
          nb_iter=self.nb_iter,
          tau=self.tau,
          alpha_init=self.alpha_init,
          rho_init=self.rho_init,
          decay=self.decay,
          pop_init=None,
          scheduler=None,
          targeted=self.targeted,
      )
  
      elite_adv = elite_adv.reshape(shape)
  
      return elite_adv
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  from typing import Optional
  from math import inf
  import torch
  import torch.nn.functional
  from advertorch.attacks.base import Attack
  from advertorch.attacks.base import LabelMixin
  from .utils import _check_param, _flatten, _make_projector
label_desc: Use image node_id 2 for calling the GenAttack obj's underlying member method code with example usage: obj.perturb(x, y) and returns: elite_adv, self